class ArraySerializable in Zircon Profile 8.0
Same name in this branch
- 8.0 vendor/zendframework/zend-hydrator/src/ArraySerializable.php \Zend\Hydrator\ArraySerializable
- 8.0 vendor/zendframework/zend-stdlib/src/Hydrator/ArraySerializable.php \Zend\Stdlib\Hydrator\ArraySerializable
Same name and namespace in other branches
- 8 vendor/zendframework/zend-hydrator/src/ArraySerializable.php \Zend\Hydrator\ArraySerializable
Hierarchy
- class \Zend\Hydrator\AbstractHydrator implements FilterEnabledInterface, HydratorInterface, NamingStrategyEnabledInterface, StrategyEnabledInterface
- class \Zend\Hydrator\ArraySerializable
Expanded class hierarchy of ArraySerializable
1 file declares its use of ArraySerializable
- ArraySerializable.php in vendor/
zendframework/ zend-stdlib/ src/ Hydrator/ ArraySerializable.php
File
- vendor/
zendframework/ zend-hydrator/ src/ ArraySerializable.php, line 12
Namespace
Zend\HydratorView source
class ArraySerializable extends AbstractHydrator {
/**
* Extract values from the provided object
*
* Extracts values via the object's getArrayCopy() method.
*
* @param object $object
* @return array
* @throws Exception\BadMethodCallException for an $object not implementing getArrayCopy()
*/
public function extract($object) {
if (!is_callable([
$object,
'getArrayCopy',
])) {
throw new Exception\BadMethodCallException(sprintf('%s expects the provided object to implement getArrayCopy()', __METHOD__));
}
$data = $object
->getArrayCopy();
$filter = $this
->getFilter();
foreach ($data as $name => $value) {
if (!$filter
->filter($name)) {
unset($data[$name]);
continue;
}
$extractedName = $this
->extractName($name, $object);
// replace the original key with extracted, if differ
if ($extractedName !== $name) {
unset($data[$name]);
$name = $extractedName;
}
$data[$name] = $this
->extractValue($name, $value, $object);
}
return $data;
}
/**
* Hydrate an object
*
* Hydrates an object by passing $data to either its exchangeArray() or
* populate() method.
*
* @param array $data
* @param object $object
* @return object
* @throws Exception\BadMethodCallException for an $object not implementing exchangeArray() or populate()
*/
public function hydrate(array $data, $object) {
$replacement = [];
foreach ($data as $key => $value) {
$name = $this
->hydrateName($key, $data);
$replacement[$name] = $this
->hydrateValue($name, $value, $data);
}
if (is_callable([
$object,
'exchangeArray',
])) {
$object
->exchangeArray($replacement);
}
elseif (is_callable([
$object,
'populate',
])) {
$object
->populate($replacement);
}
else {
throw new Exception\BadMethodCallException(sprintf('%s expects the provided object to implement exchangeArray() or populate()', __METHOD__));
}
return $object;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractHydrator:: |
protected | property | Composite to filter the methods, that need to be hydrated | |
AbstractHydrator:: |
protected | property | An instance of NamingStrategy\NamingStrategyInterface | |
AbstractHydrator:: |
protected | property | The list with strategies that this hydrator has. | |
AbstractHydrator:: |
public | function |
Add a new filter to take care of what needs to be hydrated.
To exclude e.g. the method getServiceLocator: Overrides FilterEnabledInterface:: |
1 |
AbstractHydrator:: |
public | function |
Adds the given strategy under the given name. Overrides StrategyEnabledInterface:: |
|
AbstractHydrator:: |
public | function | Convert a name for extraction. If no naming strategy exists, the plain value is returned. | |
AbstractHydrator:: |
public | function | Converts a value for extraction. If no strategy exists the plain value is returned. | |
AbstractHydrator:: |
public | function | Get the filter instance | |
AbstractHydrator:: |
public | function |
Gets the naming strategy. Overrides NamingStrategyEnabledInterface:: |
|
AbstractHydrator:: |
public | function |
Gets the strategy with the given name. Overrides StrategyEnabledInterface:: |
|
AbstractHydrator:: |
public | function |
Check whether a specific filter exists at key $name or not Overrides FilterEnabledInterface:: |
|
AbstractHydrator:: |
public | function |
Checks if a naming strategy exists. Overrides NamingStrategyEnabledInterface:: |
|
AbstractHydrator:: |
public | function |
Checks if the strategy with the given name exists. Overrides StrategyEnabledInterface:: |
|
AbstractHydrator:: |
public | function | Converts a value for hydration. If no naming strategy exists, the plain value is returned. | |
AbstractHydrator:: |
public | function | Converts a value for hydration. If no strategy exists the plain value is returned. | |
AbstractHydrator:: |
public | function |
Remove a filter from the composition.
To not extract "has" methods, you simply need to unregister it Overrides FilterEnabledInterface:: |
1 |
AbstractHydrator:: |
public | function |
Removes the naming strategy Overrides NamingStrategyEnabledInterface:: |
1 |
AbstractHydrator:: |
public | function |
Removes the strategy with the given name. Overrides StrategyEnabledInterface:: |
|
AbstractHydrator:: |
public | function |
Adds the given naming strategy Overrides NamingStrategyEnabledInterface:: |
1 |
AbstractHydrator:: |
public | function | Initializes a new instance of this class. | 1 |
ArraySerializable:: |
public | function |
Extract values from the provided object Overrides ExtractionInterface:: |
|
ArraySerializable:: |
public | function |
Hydrate an object Overrides HydrationInterface:: |