[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/src/ProxyManager/ProxyGenerator/Util/ -> Properties.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace ProxyManager\ProxyGenerator\Util;
   6  
   7  use ReflectionClass;
   8  use ReflectionProperty;
   9  
  10  /**
  11   * DTO containing the list of all non-static proxy properties and utility methods to access them
  12   * in various formats/collections
  13   *
  14   * @author Marco Pivetta <ocramius@gmail.com>
  15   * @license MIT
  16   */
  17  final class Properties
  18  {
  19      /**
  20       * @var array|\ReflectionProperty[]
  21       */
  22      private $properties;
  23  
  24      /**
  25       * @param ReflectionProperty[] $properties
  26       */
  27      private function __construct(array $properties)
  28      {
  29          $this->properties = $properties;
  30      }
  31  
  32      public static function fromReflectionClass(ReflectionClass $reflection) : self
  33      {
  34          $class      = $reflection;
  35          $properties = [];
  36  
  37          do {
  38              $properties = array_merge(
  39                  $properties,
  40                  array_values(array_filter(
  41                      $class->getProperties(),
  42                      function (ReflectionProperty $property) use ($class) : bool {
  43                          return $class->getName() === $property->getDeclaringClass()->getName()
  44                              && ! $property->isStatic();
  45                      }
  46                  ))
  47              );
  48          } while ($class = $class->getParentClass());
  49  
  50          return new self($properties);
  51      }
  52  
  53      /**
  54       * @param string[] $excludedProperties
  55       */
  56      public function filter(array $excludedProperties) : self
  57      {
  58          $properties = $this->getInstanceProperties();
  59  
  60          foreach ($excludedProperties as $propertyName) {
  61              unset($properties[$propertyName]);
  62          }
  63  
  64          return new self($properties);
  65      }
  66  
  67      /**
  68       * @return ReflectionProperty[] indexed by the property internal visibility-aware name
  69       */
  70      public function getPublicProperties() : array
  71      {
  72          $publicProperties = [];
  73  
  74          foreach ($this->properties as $property) {
  75              if ($property->isPublic()) {
  76                  $publicProperties[$property->getName()] = $property;
  77              }
  78          }
  79  
  80          return $publicProperties;
  81      }
  82  
  83      /**
  84       * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0*\0propertyName)
  85       */
  86      public function getProtectedProperties() : array
  87      {
  88          $protectedProperties = [];
  89  
  90          foreach ($this->properties as $property) {
  91              if ($property->isProtected()) {
  92                  $protectedProperties["\0*\0" . $property->getName()] = $property;
  93              }
  94          }
  95  
  96          return $protectedProperties;
  97      }
  98  
  99      /**
 100       * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0ClassName\0propertyName)
 101       */
 102      public function getPrivateProperties() : array
 103      {
 104          $privateProperties = [];
 105  
 106          foreach ($this->properties as $property) {
 107              if ($property->isPrivate()) {
 108                  $declaringClass = $property->getDeclaringClass()->getName();
 109  
 110                  $privateProperties["\0" . $declaringClass . "\0" . $property->getName()] = $property;
 111              }
 112          }
 113  
 114          return $privateProperties;
 115      }
 116  
 117      /**
 118       * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0*\0propertyName)
 119       */
 120      public function getAccessibleProperties() : array
 121      {
 122          return array_merge($this->getPublicProperties(), $this->getProtectedProperties());
 123      }
 124  
 125      /**
 126       * @return ReflectionProperty[][] indexed by class name and property name
 127       */
 128      public function getGroupedPrivateProperties() : array
 129      {
 130          $propertiesMap = [];
 131  
 132          foreach ($this->getPrivateProperties() as $property) {
 133              $class = & $propertiesMap[$property->getDeclaringClass()->getName()];
 134  
 135              $class[$property->getName()] = $property;
 136          }
 137  
 138          return $propertiesMap;
 139      }
 140  
 141      /**
 142       * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0*\0propertyName)
 143       */
 144      public function getInstanceProperties() : array
 145      {
 146          return array_merge($this->getAccessibleProperties(), $this->getPrivateProperties());
 147      }
 148  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1