| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\DebugInfo; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class AnnotationReader { |
| 11 |
|
| 12 |
private static $cache = []; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public static function propertyHasAnnotation( |
| 22 |
\ReflectionProperty $property, |
| 23 |
string $annotationName |
| 24 |
) { |
| 25 |
$cacheKey = "$annotationName@{$property->class}::{$property->name}"; |
| 26 |
if ( !isset( self::$cache[$cacheKey] ) ) { |
| 27 |
$comment = $property->getDocComment(); |
| 28 |
if ( $comment === false ) { |
| 29 |
self::$cache[$cacheKey] = false; |
| 30 |
} else { |
| 31 |
$encAnnotation = preg_quote( $annotationName, '!' ); |
| 32 |
self::$cache[$cacheKey] = |
| 33 |
(bool)preg_match( "!^[ \t]*(/\*\*|\*)[ \t]*@$encAnnotation\b!im", $comment ); |
| 34 |
} |
| 35 |
} |
| 36 |
return self::$cache[$cacheKey]; |
| 37 |
} |
| 38 |
} |