comparison vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
101 // PlantUML 101 // PlantUML
102 'startuml' => true, 'enduml' => true, 102 'startuml' => true, 'enduml' => true,
103 ); 103 );
104 104
105 /** 105 /**
106 * A list with annotations that are not causing exceptions when not resolved to an annotation class.
107 *
108 * The names are case sensitive.
109 *
110 * @var array
111 */
112 private static $globalIgnoredNamespaces = array();
113
114 /**
106 * Add a new annotation to the globally ignored annotation names with regard to exception handling. 115 * Add a new annotation to the globally ignored annotation names with regard to exception handling.
107 * 116 *
108 * @param string $name 117 * @param string $name
109 */ 118 */
110 static public function addGlobalIgnoredName($name) 119 static public function addGlobalIgnoredName($name)
111 { 120 {
112 self::$globalIgnoredNames[$name] = true; 121 self::$globalIgnoredNames[$name] = true;
113 } 122 }
114 123
115 /** 124 /**
125 * Add a new annotation to the globally ignored annotation namespaces with regard to exception handling.
126 *
127 * @param string $namespace
128 */
129 static public function addGlobalIgnoredNamespace($namespace)
130 {
131 self::$globalIgnoredNamespaces[$namespace] = true;
132 }
133
134 /**
116 * Annotations parser. 135 * Annotations parser.
117 * 136 *
118 * @var \Doctrine\Common\Annotations\DocParser 137 * @var \Doctrine\Common\Annotations\DocParser
119 */ 138 */
120 private $parser; 139 private $parser;
149 168
150 /** 169 /**
151 * Constructor. 170 * Constructor.
152 * 171 *
153 * Initializes a new AnnotationReader. 172 * Initializes a new AnnotationReader.
154 */ 173 *
155 public function __construct() 174 * @param DocParser $parser
175 */
176 public function __construct(DocParser $parser = null)
156 { 177 {
157 if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0")) { 178 if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0")) {
158 throw AnnotationException::optimizerPlusSaveComments(); 179 throw AnnotationException::optimizerPlusSaveComments();
159 } 180 }
160 181
172 } 193 }
173 } 194 }
174 195
175 AnnotationRegistry::registerFile(__DIR__ . '/Annotation/IgnoreAnnotation.php'); 196 AnnotationRegistry::registerFile(__DIR__ . '/Annotation/IgnoreAnnotation.php');
176 197
177 $this->parser = new DocParser; 198 $this->parser = $parser ?: new DocParser();
199
178 $this->preParser = new DocParser; 200 $this->preParser = new DocParser;
179 201
180 $this->preParser->setImports(self::$globalImports); 202 $this->preParser->setImports(self::$globalImports);
181 $this->preParser->setIgnoreNotImportedAnnotations(true); 203 $this->preParser->setIgnoreNotImportedAnnotations(true);
182 204
189 public function getClassAnnotations(ReflectionClass $class) 211 public function getClassAnnotations(ReflectionClass $class)
190 { 212 {
191 $this->parser->setTarget(Target::TARGET_CLASS); 213 $this->parser->setTarget(Target::TARGET_CLASS);
192 $this->parser->setImports($this->getClassImports($class)); 214 $this->parser->setImports($this->getClassImports($class));
193 $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class)); 215 $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
216 $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
194 217
195 return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName()); 218 return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
196 } 219 }
197 220
198 /** 221 /**
220 $context = 'property ' . $class->getName() . "::\$" . $property->getName(); 243 $context = 'property ' . $class->getName() . "::\$" . $property->getName();
221 244
222 $this->parser->setTarget(Target::TARGET_PROPERTY); 245 $this->parser->setTarget(Target::TARGET_PROPERTY);
223 $this->parser->setImports($this->getPropertyImports($property)); 246 $this->parser->setImports($this->getPropertyImports($property));
224 $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class)); 247 $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
248 $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
225 249
226 return $this->parser->parse($property->getDocComment(), $context); 250 return $this->parser->parse($property->getDocComment(), $context);
227 } 251 }
228 252
229 /** 253 /**
251 $context = 'method ' . $class->getName() . '::' . $method->getName() . '()'; 275 $context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
252 276
253 $this->parser->setTarget(Target::TARGET_METHOD); 277 $this->parser->setTarget(Target::TARGET_METHOD);
254 $this->parser->setImports($this->getMethodImports($method)); 278 $this->parser->setImports($this->getMethodImports($method));
255 $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class)); 279 $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
280 $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
256 281
257 return $this->parser->parse($method->getDocComment(), $context); 282 return $this->parser->parse($method->getDocComment(), $context);
258 } 283 }
259 284
260 /** 285 /**
280 * 305 *
281 * @return array 306 * @return array
282 */ 307 */
283 private function getIgnoredAnnotationNames(ReflectionClass $class) 308 private function getIgnoredAnnotationNames(ReflectionClass $class)
284 { 309 {
285 if (isset($this->ignoredAnnotationNames[$name = $class->getName()])) { 310 $name = $class->getName();
311 if (isset($this->ignoredAnnotationNames[$name])) {
286 return $this->ignoredAnnotationNames[$name]; 312 return $this->ignoredAnnotationNames[$name];
287 } 313 }
288 314
289 $this->collectParsingMetadata($class); 315 $this->collectParsingMetadata($class);
290 316
298 * 324 *
299 * @return array 325 * @return array
300 */ 326 */
301 private function getClassImports(ReflectionClass $class) 327 private function getClassImports(ReflectionClass $class)
302 { 328 {
303 if (isset($this->imports[$name = $class->getName()])) { 329 $name = $class->getName();
330 if (isset($this->imports[$name])) {
304 return $this->imports[$name]; 331 return $this->imports[$name];
305 } 332 }
306 333
307 $this->collectParsingMetadata($class); 334 $this->collectParsingMetadata($class);
308 335