|
@@ 56-91 (lines=36) @@
|
| 53 |
|
* @return AnnotationSet |
| 54 |
|
* @throws \InvalidArgumentException If the type does not exist |
| 55 |
|
*/ |
| 56 |
|
public function createPropertyAnnotations(string $className, string $propertyName): AnnotationSet |
| 57 |
|
{ |
| 58 |
|
$key = $className.':'.$propertyName; |
| 59 |
|
if ($this->cache->contains($key)) { |
| 60 |
|
return $this->cache->fetch($key); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
$reflectionProperty = new ReflectionProperty($className, $propertyName); |
| 64 |
|
|
| 65 |
|
$annotations = new AnnotationSet(); |
| 66 |
|
|
| 67 |
|
// start with with all property annotations |
| 68 |
|
foreach ($this->reader->getPropertyAnnotations($reflectionProperty) as $defaultAnnotation) { |
| 69 |
|
$annotations->addAnnotation($defaultAnnotation, AnnotationSet::TYPE_PROPERTY); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
$reflectionClass = $reflectionProperty->getDeclaringClass(); |
| 73 |
|
$parentClass = $reflectionClass->getParentClass(); |
| 74 |
|
|
| 75 |
|
while (false !== $parentClass) { |
| 76 |
|
// add parent property annotations if they exist |
| 77 |
|
if ($parentClass->hasProperty($reflectionProperty->getName())) { |
| 78 |
|
$parentProperty = $parentClass->getProperty($reflectionProperty->getName()); |
| 79 |
|
foreach ($this->reader->getPropertyAnnotations($parentProperty) as $parentPropertyAnnotation) { |
| 80 |
|
$annotations->addAnnotation($parentPropertyAnnotation, AnnotationSet::TYPE_PROPERTY); |
| 81 |
|
} |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
// reset $parentClass |
| 85 |
|
$parentClass = $parentClass->getParentClass(); |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
$this->cache->save($key, $annotations); |
| 89 |
|
|
| 90 |
|
return $annotations; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
/** |
| 94 |
|
* Create a set of class annotations |
|
@@ 134-165 (lines=32) @@
|
| 131 |
|
* @return AnnotationSet |
| 132 |
|
* @throws \InvalidArgumentException If the type does not exist |
| 133 |
|
*/ |
| 134 |
|
public function createMethodAnnotations(string $className, string $methodName): AnnotationSet |
| 135 |
|
{ |
| 136 |
|
$key = $className.':'.$methodName; |
| 137 |
|
if ($this->cache->contains($key)) { |
| 138 |
|
return $this->cache->fetch($key); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
$annotations = new AnnotationSet(); |
| 142 |
|
|
| 143 |
|
$reflectionMethod = new ReflectionMethod($className, $methodName); |
| 144 |
|
foreach ($this->reader->getMethodAnnotations($reflectionMethod) as $annotation) { |
| 145 |
|
$annotations->addAnnotation($annotation, AnnotationSet::TYPE_METHOD); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
$parentClass = $reflectionMethod->getDeclaringClass()->getParentClass(); |
| 149 |
|
while (false !== $parentClass) { |
| 150 |
|
// add parent property annotations if they exist |
| 151 |
|
if ($parentClass->hasMethod($reflectionMethod->getName())) { |
| 152 |
|
$parentMethod = $parentClass->getMethod($reflectionMethod->getName()); |
| 153 |
|
foreach ($this->reader->getMethodAnnotations($parentMethod) as $parentMethodAnnotation) { |
| 154 |
|
$annotations->addAnnotation($parentMethodAnnotation, AnnotationSet::TYPE_METHOD); |
| 155 |
|
} |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
// reset $parentClass |
| 159 |
|
$parentClass = $parentClass->getParentClass(); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
$this->cache->save($key, $annotations); |
| 163 |
|
|
| 164 |
|
return $annotations; |
| 165 |
|
} |
| 166 |
|
} |
| 167 |
|
|