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 |
ArraySerializable.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 Zend\Stdlib\Exception;
13
14 class ArraySerializable extends AbstractHydrator
15 {
16 /**
17 * Extract values from the provided object
18 *
19 * Extracts values via the object's getArrayCopy() method.
20 *
21 * @param object $object
22 * @return array
23 * @throws Exception\BadMethodCallException for an $object not implementing getArrayCopy()
24 */
25 public function extract($object)
26 {
27 if (!is_callable(array($object, 'getArrayCopy'))) {
28 throw new Exception\BadMethodCallException(
29 sprintf('%s expects the provided object to implement getArrayCopy()', __METHOD__)
30 );
31 }
32
33 $data = $object->getArrayCopy();
34 $filter = $this->getFilter();
35
36 foreach ($data as $name => $value) {
37 if (!$filter->filter($name)) {
38 unset($data[$name]);
39 continue;
40 }
41 $extractedName = $this->extractName($name, $object);
42 // replace the original key with extracted, if differ
43 if ($extractedName !== $name) {
44 unset($data[$name]);
45 $name = $extractedName;
46 }
47 $data[$name] = $this->extractValue($name, $value, $object);
48 }
49
50 return $data;
51 }
52
53 /**
54 * Hydrate an object
55 *
56 * Hydrates an object by passing $data to either its exchangeArray() or
57 * populate() method.
58 *
59 * @param array $data
60 * @param object $object
61 * @return object
62 * @throws Exception\BadMethodCallException for an $object not implementing exchangeArray() or populate()
63 */
64 public function hydrate(array $data, $object)
65 {
66 $replacement = array();
67 foreach ($data as $key => $value) {
68 $name = $this->hydrateName($key, $data);
69 $replacement[$name] = $this->hydrateValue($name, $value, $data);
70 }
71
72 if (is_callable(array($object, 'exchangeArray'))) {
73 $object->exchangeArray($replacement);
74 } elseif (is_callable(array($object, 'populate'))) {
75 $object->populate($replacement);
76 } else {
77 throw new Exception\BadMethodCallException(
78 sprintf('%s expects the provided object to implement exchangeArray() or populate()', __METHOD__)
79 );
80 }
81 return $object;
82 }
83 }
84