digital-craftsman/self-aware-normalizers
symfony/serializer or nesbot/carbon for Laravel).Normalizable, Denormalizable) can be manually implemented in Laravel’s VOs/DTOs.toArray(), or custom JSON responses, this package may require additional adapters (e.g., wrapping normalizers).VO::normalize() calls instead of direct property access).toArray()/Arrayable implementations.| Laravel Component | Integration Strategy |
|---|---|
| Symfony Serializer | Direct integration via digital-craftsman/self-aware-normalizers. |
| Laravel JSON Responses | Use package’s normalizers as custom JSON encoders (via Illuminate\Contracts\Json). |
| Fractal/Arrayable | Wrap VOs in custom transformers that delegate to Normalizable::normalize(). |
| Eloquent Models | Use VOs for domain logic, serialize via App\ValueObjects\Email::normalize(). |
| API Resources | Extend JsonResource to use VO normalizers (e.g., $resource->mergeWhen($vo->normalize())). |
Email, Money) to test integration.toArray().// app/Normalizers/ValueObjectNormalizer.php
use DigitalCraftsman\SelfAwareNormalizers\Normalizable;
class ValueObjectNormalizer implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface {
public function normalize($object, string $format = null, array $context = []): array {
return $object instanceof Normalizable ? $object->normalize() : (array)$object;
}
}
Arrayable/toArray() with Normalizable for all VOs.Serializer configurations. Audit existing normalizers before integration.composer require digital-craftsman/self-aware-normalizers
use DigitalCraftsman\SelfAwareNormalizers\Normalizable;
use DigitalCraftsman\SelfAwareNormalizers\Denormalizable;
class Email implements Normalizable, Denormalizable {
public function normalize(): array {
return ['address' => $this->address, 'verified' => $this->verified];
}
public static function denormalize(array $data): self {
return new self($data['address'], $data['verified'] ?? false);
}
}
# config/services.yaml (if using Symfony)
framework:
serializer:
mappings:
- namespace: App\ValueObjects
resource: '../src/ValueObjects'
- namespace: DigitalCraftsman\SelfAwareNormalizers
resource: '@digital-craftsman/self-aware-normalizers'
return $vo->toArray() with return $this->serializer->normalize($vo).$resource->additional(['vo_data' => $vo->normalize()]).dd() or dump() won’t show normalized form; may need custom helpers.microtime).framework:
serializer:
cache:
pools:
app.cache.pool
| Failure Scenario | Impact | **
How can I help you explore Laravel packages today?