[ Index ] |
PHP Cross Reference of phpBB-3.3.9-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 * 15 * This software consists of voluntary contributions made by many individuals 16 * and is licensed under the MIT license. 17 */ 18 19 declare(strict_types=1); 20 21 namespace ProxyManager\ProxyGenerator\Util; 22 23 use ReflectionClass; 24 use ReflectionProperty; 25 26 /** 27 * DTO containing the list of all non-static proxy properties and utility methods to access them 28 * in various formats/collections 29 * 30 * @author Marco Pivetta <ocramius@gmail.com> 31 * @license MIT 32 */ 33 final class Properties 34 { 35 /** 36 * @var array|\ReflectionProperty[] 37 */ 38 private $properties; 39 40 /** 41 * @param ReflectionProperty[] $properties 42 */ 43 private function __construct(array $properties) 44 { 45 $this->properties = $properties; 46 } 47 48 public static function fromReflectionClass(ReflectionClass $reflection) : self 49 { 50 $class = $reflection; 51 $properties = []; 52 53 do { 54 $properties = array_merge( 55 $properties, 56 array_values(array_filter( 57 $class->getProperties(), 58 function (ReflectionProperty $property) use ($class) : bool { 59 return $class->getName() === $property->getDeclaringClass()->getName() 60 && ! $property->isStatic(); 61 } 62 )) 63 ); 64 } while ($class = $class->getParentClass()); 65 66 return new self($properties); 67 } 68 69 /** 70 * @param string[] $excludedProperties 71 * 72 * @return self 73 */ 74 public function filter(array $excludedProperties) : self 75 { 76 $properties = $this->getInstanceProperties(); 77 78 foreach ($excludedProperties as $propertyName) { 79 unset($properties[$propertyName]); 80 } 81 82 return new self($properties); 83 } 84 85 /** 86 * @return ReflectionProperty[] indexed by the property internal visibility-aware name 87 */ 88 public function getPublicProperties() : array 89 { 90 $publicProperties = []; 91 92 foreach ($this->properties as $property) { 93 if ($property->isPublic()) { 94 $publicProperties[$property->getName()] = $property; 95 } 96 } 97 98 return $publicProperties; 99 } 100 101 /** 102 * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0*\0propertyName) 103 */ 104 public function getProtectedProperties() : array 105 { 106 $protectedProperties = []; 107 108 foreach ($this->properties as $property) { 109 if ($property->isProtected()) { 110 $protectedProperties["\0*\0" . $property->getName()] = $property; 111 } 112 } 113 114 return $protectedProperties; 115 } 116 117 /** 118 * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0ClassName\0propertyName) 119 */ 120 public function getPrivateProperties() : array 121 { 122 $privateProperties = []; 123 124 foreach ($this->properties as $property) { 125 if ($property->isPrivate()) { 126 $declaringClass = $property->getDeclaringClass()->getName(); 127 128 $privateProperties["\0" . $declaringClass . "\0" . $property->getName()] = $property; 129 } 130 } 131 132 return $privateProperties; 133 } 134 135 /** 136 * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0*\0propertyName) 137 */ 138 public function getAccessibleProperties() : array 139 { 140 return array_merge($this->getPublicProperties(), $this->getProtectedProperties()); 141 } 142 143 /** 144 * @return ReflectionProperty[][] indexed by class name and property name 145 */ 146 public function getGroupedPrivateProperties() : array 147 { 148 $propertiesMap = []; 149 150 foreach ($this->getPrivateProperties() as $property) { 151 $class = & $propertiesMap[$property->getDeclaringClass()->getName()]; 152 153 $class[$property->getName()] = $property; 154 } 155 156 return $propertiesMap; 157 } 158 159 /** 160 * @return ReflectionProperty[] indexed by the property internal visibility-aware name (\0*\0propertyName) 161 */ 162 public function getInstanceProperties() : array 163 { 164 return array_merge($this->getAccessibleProperties(), $this->getPrivateProperties()); 165 } 166 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 7 15:09:22 2022 | Cross-referenced by PHPXref 0.7.1 |