Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Reflection.php
01 <?php
02 /**
03 * Zend Framework (http://framework.zend.com/)
04 *
05 * @link http://github.com/zendframework/zf2 for the canonical source repository
06 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
07 * @license http://framework.zend.com/license/new-bsd New BSD License
08 */
09
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 }
96