Reflection.php in Zircon Profile 8.0
File
vendor/zendframework/zend-hydrator/src/Reflection.php
View source
<?php
namespace Zend\Hydrator;
use ReflectionClass;
use ReflectionProperty;
class Reflection extends AbstractHydrator {
protected static $reflProperties = [];
public function extract($object) {
$result = [];
foreach (self::getReflProperties($object) as $property) {
$propertyName = $this
->extractName($property
->getName(), $object);
if (!$this->filterComposite
->filter($propertyName)) {
continue;
}
$value = $property
->getValue($object);
$result[$propertyName] = $this
->extractValue($propertyName, $value, $object);
}
return $result;
}
public function hydrate(array $data, $object) {
$reflProperties = self::getReflProperties($object);
foreach ($data as $key => $value) {
$name = $this
->hydrateName($key, $data);
if (isset($reflProperties[$name])) {
$reflProperties[$name]
->setValue($object, $this
->hydrateValue($name, $value, $data));
}
}
return $object;
}
protected static function getReflProperties($input) {
if (is_object($input)) {
$input = get_class($input);
}
elseif (!is_string($input)) {
throw new Exception\InvalidArgumentException('Input must be a string or an object.');
}
if (isset(static::$reflProperties[$input])) {
return static::$reflProperties[$input];
}
static::$reflProperties[$input] = [];
$reflClass = new ReflectionClass($input);
$reflProperties = $reflClass
->getProperties();
foreach ($reflProperties as $property) {
$property
->setAccessible(true);
static::$reflProperties[$input][$property
->getName()] = $property;
}
return static::$reflProperties[$input];
}
}