PHP Trait WoohooLabs\Yin\JsonApi\Hydrator\HydratorTrait

Mostra file Open project: woohoolabs/yin

Protected Methods

Method Description
doHydrateRelationship ( mixed $domainObject, string $relationshipName, callable $hydrator, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory, array | null $relationshipData, array | null $data ) : mixed
getAcceptedType ( ) : string | array Determines which resource type or types can be accepted by the hydrator.
getArgumentTypeHintFromCallable ( callable $callable ) : string | null
getAttributeHydrator ( mixed $domainObject ) : callable[] Provides the attribute hydrators.
getRelationshipHydrator ( mixed $domainObject ) : callable[] Provides the relationship hydrators.
getRelationshipHydratorResult ( string $relationshipName, callable $hydrator, mixed $domainObject, ToOneRelationship | ToManyRelationship $relationshipObject, array | null $data, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory ) : mixed
getRelationshipType ( object | string | null $object ) : string | null
hydrateAttributes ( mixed $domainObject, array $data ) : mixed
hydrateRelationships ( mixed $domainObject, array $data, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory ) : mixed
validateType ( array $data, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory )

Private Methods

Method Description
createRelationship ( array | null $relationship, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory ) : ToOneRelationship
isAssociativeArray ( array $array ) : boolean

Method Details

doHydrateRelationship() protected method

protected doHydrateRelationship ( mixed $domainObject, string $relationshipName, callable $hydrator, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory, array | null $relationshipData, array | null $data ) : mixed
$domainObject mixed
$relationshipName string
$hydrator callable
$exceptionFactory WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface
$relationshipData array | null
$data array | null
return mixed

getAcceptedType() abstract protected method

If the hydrator can only accept one type of resources, the method should return a string. If it accepts more types, then it should return an array of strings. When such a resource is received for hydration which can't be accepted (its type doesn't match the acceptable type or types of the hydrator), a ResourceTypeUnacceptable exception will be raised.
abstract protected getAcceptedType ( ) : string | array
return string | array

getArgumentTypeHintFromCallable() protected method

protected getArgumentTypeHintFromCallable ( callable $callable ) : string | null
$callable callable
return string | null

getAttributeHydrator() abstract protected method

The method returns an array of attribute hydrators, where a hydrator is a key-value pair: the key is the specific attribute name which comes from the request and the value is a callable which hydrates the given attribute. These callables receive the domain object (which will be hydrated), the value of the currently processed attribute, the "data" part of the request and the name of the attribute to be hydrated as their arguments, and they should mutate the state of the domain object. If it is an immutable object or an array (and passing by reference isn't used), the callable should return the domain object.
abstract protected getAttributeHydrator ( mixed $domainObject ) : callable[]
$domainObject mixed
return callable[]

getRelationshipHydrator() abstract protected method

The method returns an array of relationship hydrators, where a hydrator is a key-value pair: the key is the specific relationship name which comes from the request and the value is an callable which hydrate the previous relationship. These callables receive the domain object (which will be hydrated), an object representing the currently processed relationship (it can be a ToOneRelationship or a ToManyRelationship object), the "data" part of the request and the relationship name as their arguments, and they should mutate the state of the domain object. If it is an immutable object or an array (and passing by reference isn't used), the callable should return the domain object.
abstract protected getRelationshipHydrator ( mixed $domainObject ) : callable[]
$domainObject mixed
return callable[]

getRelationshipHydratorResult() protected method

protected getRelationshipHydratorResult ( string $relationshipName, callable $hydrator, mixed $domainObject, ToOneRelationship | ToManyRelationship $relationshipObject, array | null $data, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory ) : mixed
$relationshipName string
$hydrator callable
$domainObject mixed
$relationshipObject WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToOneRelationship | WoohooLabs\Yin\JsonApi\Hydrator\Relationship\ToManyRelationship
$data array | null
$exceptionFactory WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface
return mixed

getRelationshipType() protected method

protected getRelationshipType ( object | string | null $object ) : string | null
$object object | string | null
return string | null

hydrateAttributes() protected method

protected hydrateAttributes ( mixed $domainObject, array $data ) : mixed
$domainObject mixed
$data array
return mixed

hydrateRelationships() protected method

protected hydrateRelationships ( mixed $domainObject, array $data, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory ) : mixed
$domainObject mixed
$data array
$exceptionFactory WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface
return mixed

validateType() protected method

protected validateType ( array $data, WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory )
$data array
$exceptionFactory WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface