Final Class Yiisoft\Hydrator\AttributeHandling\DataAttributesHandler
| Inheritance | Yiisoft\ |
|---|
Handles data attributes that implement {@see DataAttributeInterface}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| handle() | Handle data attributes. | Yiisoft\ |
Method Details
| public mixed __construct ( Yiisoft\ | ||
| $attributeResolverFactory | Yiisoft\ |
|
public function __construct(
private AttributeResolverFactoryInterface $attributeResolverFactory,
) {}
Handle data attributes.
| public Yiisoft\ | ||
| $reflectionClass | ReflectionClass |
Reflection of class to attributes handle. |
| $data | Yiisoft\ |
Current data object ({@see \ |
public function handle(ReflectionClass $reflectionClass, DataInterface $data): DataInterface
{
$reflectionAttributes = $reflectionClass->getAttributes(
DataAttributeInterface::class,
ReflectionAttribute::IS_INSTANCEOF,
);
foreach ($reflectionAttributes as $reflectionAttribute) {
$attribute = $reflectionAttribute->newInstance();
$resolver = $this->attributeResolverFactory->create($attribute);
if (!$resolver instanceof DataAttributeResolverInterface) {
throw new RuntimeException(
sprintf(
'Data attribute resolver "%s" must implement "%s".',
get_debug_type($resolver),
DataAttributeResolverInterface::class,
),
);
}
$data = $resolver->prepareData($attribute, $data);
}
return $data;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.