On this page
Caution
The documentation you are viewing is for an older version of this component.
Switch to the latest (v4) version.
Migration from version 2
This document details changes made between version 2 and version 3 that could affect end-users.
Minimum supported versions
PHP
Version 3 bumps the minimum supported PHP version to version 7.2. We chose this
version in particular as it provides the object
typehint, which allows us to
enforce at the engine level what we were previously enforcing only at the
documentation level.
Additionally, we have enabled strict types in all class files shipped with this component.
laminas-eventmanager
The minimum supported version of laminas-eventmanager (used by the
AggregateHydrator
)is now 3.2.1.
laminas-serializer
The minimum supported version of laminas-serializer (used by the
SerializableStrategy
) is now 2.9.0.
laminas-servicemanager
The minimum supported version of laminas-servicemanager (used by the
HydratorPluginManager
) is now 3.3.2.
Renamed interfaces
The following interfaces were renamed:
Laminas\Hydrator\FilterEnabledInterface
becomesLaminas\Hydrator\Filter\FilterEnabledInterface
.Laminas\Hydrator\NamingStrategyEnabledInterface
becomesLaminas\Hydrator\NamingStrategy\NamingStrategyEnabledInterface
.Laminas\Hydrator\StrategyEnabledInterface
becomesLaminas\Hydrator\Strategy\StrategyEnabledInterface
.
Renamed classes
The following classes were renamed:
Laminas\Hydrator\ArraySerializable
becomesLaminas\Hydrator\ArraySerializableHydrator
Laminas\Hydrator\ClassMethods
becomesLaminas\Hydrator\ClassMethodsHydrator
Laminas\Hydrator\ObjectProperty
becomesLaminas\Hydrator\ObjectPropertyHydrator
Laminas\Hydrator\Reflection
becomesLaminas\Hydrator\ReflectionHydrator
In each case, a class named after the original has been created as a deprecated extension of the new class. This means you can continue to use the old class names, but only until version 4, at which point they will be removed.
Additionally, aliases for the old class names have been added to the
HydratorPluginManager
, pointing to services named after the new class names.
Interface changes
Each of the interfaces provided by this package have been updated to add typehints where they were previously omitted (due to engine limitations), both on parameters and return values. These include:
Laminas\Hydrator\ExtractionInterface
:extract($object)
becomesextract(object $object) : array
Laminas\Hydrator\Filter\FilterEnabledInterface
(wasLaminas\Hydrator\FilterEnabledInterface
):addFilter($name, $filter, $condition = Laminas\Hydrator\Filter\FilterComposite::CONDITION_OR)
becomesaddFilter(string $name, $filter, int $condition = Laminas\Hydrator\Filter\FilterComposite::CONDITION_OR) : void
hasFilter($name)
becomeshasFilter(string $name) : bool
removeFilter($name)
becomesremoveFilter(string $name) : void
Laminas\Hydrator\HydrationInterface
:hydrate(array $data, $object)
becomeshydrate(array $data, object $object)
Laminas\Hydrator\HydratorAwareInterface
:setHydrator(Laminas\Hydrator\HydratorInterface $hydrator)
becomessetHydrator(Laminas\Hydrator\HydratorInterface $hydrator) : void
getHydrator()
becomesgetHydrator() : ?Laminas\Hydrator\HydratorInterface
Laminas\Hydrator\HydratorAwareTrait
was updated to follow the interface; if you use the trait to implement the interface, no changes will be necessary.Laminas\Hydrator\HydratorOptionsInterface
:setOptions($options)
becomessetOptions(iterable $options) : void
Laminas\Hydrator\HydratorProviderInterface
:getHydratorConfig()
becomesgetHydratorConfig() : array
Laminas\Hydrator\NamingStrategy\NamingStrategyEnabledInterface
(wasLaminas\Hydrator\NamingStrategyEnabledInterface
):setNamingStrategy(Laminas\Hydrator\NamingStrategy\NamingStrategyInterface $strategy)
becomessetNamingStrategy(Laminas\Hydrator\NamingStrategy\NamingStrategyInterface $strategy) : void
getNamingStrategy()
becomesgetNamingStrategy() : Laminas\Hydrator\NamingStrategy\NamingStrategyInterface
removeNamingStrategy()
becomesremoveNamingStrategy() : void
Laminas\Hydrator\Strategy\StrategyEnabledInterface
(wasLaminas\Hydrator\StrategyEnabledInterface
):addStrategy($name, Laminas\Hydrator\Strategy\StrategyInterface $strategy)
becomesaddStrategy(string $name, Laminas\Hydrator\Strategy\StrategyInterface $strategy) : void
getStrategy($name)
becomesgetStrategy(string $name) : Laminas\Hydrator\Strategy\StrategyInterface
hasStrategy($name)
becomeshasStrategy(string $name) : bool
removeStrategy($name)
becomesremoveStrategy(string $name) : void
Laminas\Hydrator\Filter\FilterInterface
:filter($property)
becomesfilter(string $property) : bool
Laminas\Hydrator\Filter\FilterProviderInterface
:getFilter()
becomesgetFilter() : Laminas\Hydrator\Filter\FilterInterface
Laminas\Hydrator\Iterator\HydratingIteratorInterface
:setPrototype($prototype)
becomessetPrototype($prototype) : void
($prototype
continues to allow either astring
or object)setHydrator(Laminas\Hydrator\HydratorInterface $hydrator)
becomessetHydrator(Laminas\Hydrator\HydratorInterface $hydrator) : void
Laminas\Hydrator\NamingStrategy\NamingStrategyInterface
:extract($name)
becomesextract(string $name, ?object $object = null) : string
hydrate($name)
becomeshydrate(string $name, ?array $data = null) : string
Laminas\Hydrator\Strategy\StrategyInterface
:hydrate($value)
becomeshydrate($value, ?array $data = null)
(the$value
parameter and return value can be any PHP type)extract($value)
becomesextract($value, ?object $object = null)
(the$value
parameter and return value can be any PHP type)
All implementations of these interface shipped in the component have been updated to ensure signatures match.
If you are providing custom implementations, or extending the implementations provided in this package, you may need to update signatures per the above.
Typehints
As noted in the above section, typehints were added to all interfaces. In addition to those changes, the following methods were also updated to add typehints:
Laminas\Hydrator\Aggregate\AggregateHydrator
:-
add(Laminas\Hydrator\HydratorInterface $hydrator, $priority = self::DEFAULT_PRIORITY)
becomesadd(Laminas\Hydrator\HydratorInterface $hydrator, int $priority = self::DEFAULT_PRIORITY) : void
-
Laminas\Hydrator\Aggregate\ExtractEvent
: __construct($target, $extractionObject)
becomes__construct(object $target, object $extractionObject)
getExtractionObject()
becomesgetExtractionObject() : object
setExtractionObject($extractionObject)
becomessetExtractionObject(object $extractionObject) : void
getExtractedData()
becomesgetExtractedData() : array
setExtractedData(array $extractedData)
becomessetExtractedData(array $extractedData) : void
-
mergeExtractedData(array $additionalData)
becomesmergeExtractedData(array $additionalData) : void
-
Laminas\Hydrator\Aggregate\HydrateEvent
: __construct($target, $hydratedObject, array $hydrationData)
becomes__construct(object $target, object $hydratedObject, array $hydrationData)
getHydratedObject()
becomesgetHydratedObject() : object
setHydratedObject($hydratedObject)
becomessetHydratedObject(object $hydratedObject) : void
getHydrationData()
becomesgetHydrationData() : array
-
setHydrationData(array $hydrationData)
becomessetHydrationData(array $hydrationData) : void
-
Laminas\Hydrator\Aggregate\HydratorListener
: onHydrate(HydrateEvent $event)
becomesonHydrate(HydrateEvent $event) : object
-
onExtract(ExtractEvent $event)
becomesonExtract(ExtractEvent $event) : array
-
Laminas\Hydrator\ClassMethodsHydrator
(wasLaminas\Hydrator\ClassMethods
): __construct($underscoreSeparatedKeys = true, $methodExistsCheck = false)
becomes__construct(bool $underscoreSeparatedKeys = true, bool $methodExistsCheck = false)
setUnderscoreSeparatedKeys($underscoreSeparatedKeys)
becomessetUnderscoreSeparatedKeys(bool $underscoreSeparatedKeys) : void
getUnderscoreSeparatedKeys()
becomesgetUnderscoreSeparatedKeys() : bool
setMethodExistsCheck($methodExistsCheck)
becomessetMethodExistsCheck(bool $methodExistsCheck) : void
-
getMethodExistsCheck()
becomesgetMethodExistsCheck() : bool
-
Laminas\Hydrator\ConfigProvider
: __invoke()
becomes__invoke() : array
-
getDependencyConfig()
becomesgetDependencyConfig() : array
-
Laminas\Hydrator\DelegatingHydratorFactory
: - no longer implements
Laminas\ServiceManager\FactoryInterface
-
__invoke(Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
becomes__invoke(Psr\Container\ContainerInterface $container) : Laminas\Hydrator\DelegatingHydrator
-
Laminas\Hydrator\Filter\FilterComposite
: -
__construct($orFilters = [], $andFilters = [])
becomes__construct(array $orFilters = [], array $andFilters = [])
-
Laminas\Hydrator\Filter\MethodMatchFilter
: -
__construct($method, $exclude = true)
becomes__construct(string $method, bool $exclude = true)
-
Laminas\Hydrator\Filter\NumberOfParameterFilter
: -
__construct($numberOfParameters = 0)
becomes__construct(int $numberOfParameters = 0)
-
Laminas\Hydrator\HydratorPluginManagerFactory
: - no longer implements
Laminas\ServiceManager\FactoryInterface
-
__invoke(Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
becomes__invoke(Psr\Container\ContainerInterface $container, string $name, ?array $options = []) : Laminas\Hydrator\HydratorPluginManager
-
Laminas\Hydrator\Module
: getConfig()
becomesgetConfig() : array
-
init($moduleManager)
becomesinit(Laminas\ModuleManager\ModuleManager $moduleManager) : void
-
Laminas\Hydrator\NamingStrategy\CompositeNamingStrategy
: -
__construct(array $strategies, Laminas\Hydrator\NamingStrategy\NamingStrategyInterface $defaultNamingStrategy = null)
becomes__construct(array $strategies, ?Laminas\Hydrator\NamingStrategy\NamingStrategyInterface $defaultNamingStrategy = null)
-
Laminas\Hydrator\NamingStrategy\UnderscoreNamingStrategy\CamelCaseToUnderscoreFilter
: -
filter($value)
becomesfilter(string $value) : string
-
Laminas\Hydrator\NamingStrategy\UnderscoreNamingStrategy\UnderscoreToCamelCaseFilter
: -
filter($value)
becomesfilter(string $value) : string
-
Laminas\Hydrator\Strategy\ClosureStrategy
: -
__construct($extractFunc = null, $hydrateFunc = null)
becomes__construct(?callable $extractFunc = null, ?callable $hydrateFunc = null)
-
Laminas\Hydrator\Strategy\CollectionStrategy
: -
__construct(Laminas\Hydrator\HydratorInterface $objectHydrator, $objectClassName)
becomes__construct(Laminas\Hydrator\HydratorInterface $objectHydrator, string $objectClassName)
-
Laminas\Hydrator\Strategy\DateTimeFormatterStrategy
: -
__construct($format = DateTime::RFC3339, DateTimeZone $timezone = null, $dateTimeFallback = false)
becomes__construct(string $format = DateTime::RFC3339, ?DateTimeZone $timezone = null, bool $dateTimeFallback = false)
-
Laminas\Hydrator\Strategy\ExplodeStrategy
: -
__construct($delimiter = ',', $explodeLimit = null)
becomes__construct(string $delimiter = ',', ?int $explodeLimit = null)
-
Laminas\Hydrator\Strategy\SerializableStrategy
: __construct($serializer, $serializerOptions = null)
becomes__construct($serializer, ?iterable $serializerOptions = null)
setSerializer($serializer)
becomessetSerializer($serializer) : void
getSerializer()
becomesgetSerializer($serializer) : Laminas\Serializer\Adapter\AdapterInterface
setSerializerOptions($serializerOptions)
becomessetSerializerOptions(iterable $serializerOptions) : void
-
getSerializerOptions()
becomesgetSerializerOptions() : array
-
Laminas\Hydrator\Strategy\StrategyChain
: __construct($extractionStrategies)
becomes__construct(iterable $extractionStrategies)
ArrayMapNamingStrategy and MapNamingStrategy merged
ArrayMapNamingStrategy
and MapNamingStrategy
were performing essentially the
same duties, but in reverse. As such, for version 3, we have merged the two into
MapNamingStrategy
. To accommodate the three different use cases, we provide
three "named constructors":
public static function createFromExtractionMap(array $extractionMap) : MapNamingStrategy;
public static function createFromHydrationMap(array $hydrationMap) : MapNamingStrategy;
public static function createFromAsymmetricMap(array $extractionMap, array $hydrationMap) : MapNamingStrategy;
In the first two cases, the constructor will flip the arrays for purposes of the
opposite interaction; e.g., using createFromExtractionMap()
will create a
hydration map based on an array_flip()
of the extraction map provided.
You MUST use one of these methods to create an instance, as the constructor
is now marked private
.
HydratorPluginManager
This version removes support for laminas-servicemanager v2 service names. Under laminas-servicemanager v2, most special characters were removed, and the name normalized to all lowercase. Now, only fully qualified class names are mapped to factories, and short names (names omitting the namespace and/or "Hydrator" suffix) are mapped as aliases.
Additionally, version 3 ships a standalone, PSR-11 compliant version,
Laminas\Hydrator\StandaloneHydratorPluginManager
. By default, the HydratorManager
service alias will point to the StandaloneHydratorPluginManager
if
laminas-servicemanager is not installed, and the HydratorPluginManager
otherwise.
See the plugin managers chapter for more details.