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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ObjectProperty.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 3.15 KiB


001  <?php
002  /**
003   * Zend Framework (http://framework.zend.com/)
004   *
005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007   * @license   http://framework.zend.com/license/new-bsd New BSD License
008   */
009   
010  namespace Zend\Stdlib\Hydrator;
011   
012  use Zend\Stdlib\Exception;
013  use ReflectionClass;
014  use ReflectionProperty;
015   
016  class ObjectProperty extends AbstractHydrator
017  {
018      /**
019       * @var array[] indexed by class name and then property name
020       */
021      private static $skippedPropertiesCache = array();
022   
023      /**
024       * {@inheritDoc}
025       *
026       * Extracts the accessible non-static properties of the given $object.
027       *
028       * @throws Exception\BadMethodCallException for a non-object $object
029       */
030      public function extract($object)
031      {
032          if (!is_object($object)) {
033              throw new Exception\BadMethodCallException(
034                  sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)
035              );
036          }
037   
038          $data   = get_object_vars($object);
039          $filter = $this->getFilter();
040   
041          foreach ($data as $name => $value) {
042              // Filter keys, removing any we don't want
043              if (! $filter->filter($name)) {
044                  unset($data[$name]);
045                  continue;
046              }
047   
048              // Replace name if extracted differ
049              $extracted = $this->extractName($name, $object);
050   
051              if ($extracted !== $name) {
052                  unset($data[$name]);
053                  $name = $extracted;
054              }
055   
056              $data[$name] = $this->extractValue($name, $value, $object);
057          }
058   
059          return $data;
060      }
061   
062      /**
063       * {@inheritDoc}
064       *
065       * Hydrate an object by populating public properties
066       *
067       * Hydrates an object by setting public properties of the object.
068       *
069       * @throws Exception\BadMethodCallException for a non-object $object
070       */
071      public function hydrate(array $data, $object)
072      {
073          if (!is_object($object)) {
074              throw new Exception\BadMethodCallException(
075                  sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)
076              );
077          }
078   
079          $properties = & self::$skippedPropertiesCache[get_class($object)];
080   
081          if (! isset($properties)) {
082              $reflection = new ReflectionClass($object);
083              $properties = array_fill_keys(
084                  array_map(
085                      function (ReflectionProperty $property) {
086                          return $property->getName();
087                      },
088                      $reflection->getProperties(
089                          ReflectionProperty::IS_PRIVATE
090                          + ReflectionProperty::IS_PROTECTED
091                          + ReflectionProperty::IS_STATIC
092                      )
093                  ),
094                  true
095              );
096          }
097   
098          foreach ($data as $name => $value) {
099              $property = $this->hydrateName($name, $data);
100   
101              if (isset($properties[$property])) {
102                  continue;
103              }
104   
105              $object->$property = $this->hydrateValue($property, $value, $data);
106          }
107   
108          return $object;
109      }
110  }
111