/** * Defines multiple annotations classes * A very little bit faster than multiple calls to setAnnotation() * * @param $context string Parser::T_CLASS, Parser::T_METHOD, Parser::T_VARIABLE * @param $annotations_classes string[] key is the annotation name, value is the annotation class */ public function setAnnotations($context, $annotations_classes) { // instantiates Parser, in order to call its __destruct() method at the script end if (!isset($GLOBALS['parser'])) { $GLOBALS['parser'] = new Parser(); } // add annotation $namespace = 'SAF\\Framework\\Reflection\\Annotation' . BS . $context; foreach ($annotations_classes as $annotation_name => $annotation_class) { $class_name = Names::propertyToClass($annotation_name) . '_Annotation'; Parser::$additional_annotations[$namespace . BS . $class_name] = $annotation_class; } }
/** * Gets annotation class name (including namespace) for a given annotation name * * @param $reflection_object Has_Doc_Comment * @param $annotation_name string * @return string */ private static function getAnnotationClassName(Has_Doc_Comment $reflection_object, $annotation_name) { $reflection_class = get_class($reflection_object); $pos = strrpos($reflection_class, '_'); $reflection_class = substr($reflection_class, $pos + 1); if ($reflection_class == 'Class') { $reflection_class .= '_'; } elseif ($reflection_class == 'Value') { $reflection_class = 'Property'; } $annotation_class = __NAMESPACE__ . BS . $reflection_class . BS . Names::propertyToClass($annotation_name) . '_Annotation'; /** @noinspection PhpUsageOfSilenceOperatorInspection */ if (!@class_exists($annotation_class)) { if (!isset(self::$default_annotations)) { self::initDefaultAnnotations(); } if (isset(self::$default_annotations[$annotation_class])) { $annotation_class = self::$default_annotations[$annotation_class]; } else { $annotation_class = Annotation::class; } } return $annotation_class; }