PK qI'Pڤ
LICENSE.mdnu W+A Copyright (c) 2019, Laminas Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Laminas Foundation nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PK qI'PKW W COPYRIGHT.mdnu W+A Copyright (c) 2019, Laminas Foundation.
All rights reserved. (https://getlaminas.org/)
PK qI'P
K( README.mdnu W+A # laminas-hydrator
[![Build Status](https://travis-ci.org/laminas/laminas-hydrator.svg?branch=master)](https://travis-ci.org/laminas/laminas-hydrator)
[![Coverage Status](https://coveralls.io/repos/laminas/laminas-hydrator/badge.svg?branch=master)](https://coveralls.io/r/laminas/laminas-hydrator?branch=master)
`Laminas\Hydrator` provides utilities for mapping arrays to objects, and vice
versa, including facilities for filtering which data is mapped as well as
providing mechanisms for mapping nested structures.
- File issues at https://github.com/laminas/laminas-hydrator/issues
- Documentation is at https://docs.laminas.dev/laminas-stdlib
PK qI'PK src/AbstractHydrator.phpnu W+A strategies = new ArrayObject();
$this->filterComposite = new Filter\FilterComposite();
}
/**
* Gets the strategy with the given name.
*
* @param string $name The name of the strategy to get.
*
* @throws Exception\InvalidArgumentException
* @return Strategy\StrategyInterface
*/
public function getStrategy($name)
{
if (isset($this->strategies[$name])) {
return $this->strategies[$name];
}
if (!isset($this->strategies['*'])) {
throw new Exception\InvalidArgumentException(sprintf(
'%s: no strategy by name of "%s", and no wildcard strategy present',
__METHOD__,
$name
));
}
return $this->strategies['*'];
}
/**
* Checks if the strategy with the given name exists.
*
* @param string $name The name of the strategy to check for.
* @return bool
*/
public function hasStrategy($name)
{
return array_key_exists($name, $this->strategies)
|| array_key_exists('*', $this->strategies);
}
/**
* Adds the given strategy under the given name.
*
* @param string $name The name of the strategy to register.
* @param Strategy\StrategyInterface $strategy The strategy to register.
* @return HydratorInterface
*/
public function addStrategy($name, Strategy\StrategyInterface $strategy)
{
$this->strategies[$name] = $strategy;
return $this;
}
/**
* Removes the strategy with the given name.
*
* @param string $name The name of the strategy to remove.
* @return HydratorInterface
*/
public function removeStrategy($name)
{
unset($this->strategies[$name]);
return $this;
}
/**
* Converts a value for extraction. If no strategy exists the plain value is returned.
*
* @param string $name The name of the strategy to use.
* @param mixed $value The value that should be converted.
* @param mixed $object The object is optionally provided as context.
* @return mixed
*/
public function extractValue($name, $value, $object = null)
{
if ($this->hasStrategy($name)) {
$strategy = $this->getStrategy($name);
$value = $strategy->extract($value, $object);
}
return $value;
}
/**
* Converts a value for hydration. If no strategy exists the plain value is returned.
*
* @param string $name The name of the strategy to use.
* @param mixed $value The value that should be converted.
* @param array $data The whole data is optionally provided as context.
* @return mixed
*/
public function hydrateValue($name, $value, $data = null)
{
if ($this->hasStrategy($name)) {
$strategy = $this->getStrategy($name);
$value = $strategy->hydrate($value, $data);
}
return $value;
}
/**
* Convert a name for extraction. If no naming strategy exists, the plain value is returned.
*
* @param string $name The name to convert.
* @param null $object The object is optionally provided as context.
* @return mixed
*/
public function extractName($name, $object = null)
{
if ($this->hasNamingStrategy()) {
$name = $this->getNamingStrategy()->extract($name, $object);
}
return $name;
}
/**
* Converts a value for hydration. If no naming strategy exists, the plain value is returned.
*
* @param string $name The name to convert.
* @param array $data The whole data is optionally provided as context.
* @return mixed
*/
public function hydrateName($name, $data = null)
{
if ($this->hasNamingStrategy()) {
$name = $this->getNamingStrategy()->hydrate($name, $data);
}
return $name;
}
/**
* Get the filter instance
*
* @return Filter\FilterComposite
*/
public function getFilter()
{
return $this->filterComposite;
}
/**
* Add a new filter to take care of what needs to be hydrated.
* To exclude e.g. the method getServiceLocator:
*
*
* $composite->addFilter("servicelocator",
* function ($property) {
* list($class, $method) = explode('::', $property);
* if ($method === 'getServiceLocator') {
* return false;
* }
* return true;
* }, FilterComposite::CONDITION_AND
* );
*
*
* @param string $name Index in the composite
* @param callable|Filter\FilterInterface $filter
* @param int $condition
* @return Filter\FilterComposite
*/
public function addFilter($name, $filter, $condition = Filter\FilterComposite::CONDITION_OR)
{
return $this->filterComposite->addFilter($name, $filter, $condition);
}
/**
* Check whether a specific filter exists at key $name or not
*
* @param string $name Index in the composite
* @return bool
*/
public function hasFilter($name)
{
return $this->filterComposite->hasFilter($name);
}
/**
* Remove a filter from the composition.
* To not extract "has" methods, you simply need to unregister it
*
*
* $filterComposite->removeFilter('has');
*
*
* @param $name
* @return Filter\FilterComposite
*/
public function removeFilter($name)
{
return $this->filterComposite->removeFilter($name);
}
/**
* Adds the given naming strategy
*
* @param NamingStrategy\NamingStrategyInterface $strategy The naming to register.
* @return self
*/
public function setNamingStrategy(NamingStrategy\NamingStrategyInterface $strategy)
{
$this->namingStrategy = $strategy;
return $this;
}
/**
* Gets the naming strategy.
*
* @return NamingStrategy\NamingStrategyInterface
*/
public function getNamingStrategy()
{
return $this->namingStrategy;
}
/**
* Checks if a naming strategy exists.
*
* @return bool
*/
public function hasNamingStrategy()
{
return isset($this->namingStrategy);
}
/**
* Removes the naming strategy
*
* @return self
*/
public function removeNamingStrategy()
{
$this->namingStrategy = null;
return $this;
}
}
PK qI'PP src/HydratorAwareTrait.phpnu W+A hydrator = $hydrator;
return $this;
}
/**
* Retrieve hydrator
*
* @param void
* @return null|HydratorInterface
* @access public
*/
public function getHydrator()
{
return $this->hydrator;
}
}
PK qI'P &