[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10 namespace Zend\Stdlib\Hydrator; 11 12 use ReflectionClass; 13 use Zend\Stdlib\Exception; 14 15 class Reflection extends AbstractHydrator 16 { 17 /** 18 * Simple in-memory array cache of ReflectionProperties used. 19 * @var \ReflectionProperty[] 20 */ 21 protected static $reflProperties = array(); 22 23 /** 24 * Extract values from an object 25 * 26 * @param object $object 27 * @return array 28 */ 29 public function extract($object) 30 { 31 $result = array(); 32 foreach (self::getReflProperties($object) as $property) { 33 $propertyName = $this->extractName($property->getName(), $object); 34 if (!$this->filterComposite->filter($propertyName)) { 35 continue; 36 } 37 38 $value = $property->getValue($object); 39 $result[$propertyName] = $this->extractValue($propertyName, $value, $object); 40 } 41 42 return $result; 43 } 44 45 /** 46 * Hydrate $object with the provided $data. 47 * 48 * @param array $data 49 * @param object $object 50 * @return object 51 */ 52 public function hydrate(array $data, $object) 53 { 54 $reflProperties = self::getReflProperties($object); 55 foreach ($data as $key => $value) { 56 $name = $this->hydrateName($key, $data); 57 if (isset($reflProperties[$name])) { 58 $reflProperties[$name]->setValue($object, $this->hydrateValue($name, $value, $data)); 59 } 60 } 61 return $object; 62 } 63 64 /** 65 * Get a reflection properties from in-memory cache and lazy-load if 66 * class has not been loaded. 67 * 68 * @param string|object $input 69 * @throws Exception\InvalidArgumentException 70 * @return \ReflectionProperty[] 71 */ 72 protected static function getReflProperties($input) 73 { 74 if (is_object($input)) { 75 $input = get_class($input); 76 } elseif (!is_string($input)) { 77 throw new Exception\InvalidArgumentException('Input must be a string or an object.'); 78 } 79 80 if (isset(static::$reflProperties[$input])) { 81 return static::$reflProperties[$input]; 82 } 83 84 static::$reflProperties[$input] = array(); 85 $reflClass = new ReflectionClass($input); 86 $reflProperties = $reflClass->getProperties(); 87 88 foreach ($reflProperties as $property) { 89 $property->setAccessible(true); 90 static::$reflProperties[$input][$property->getName()] = $property; 91 } 92 93 return static::$reflProperties[$input]; 94 } 95 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |