/** * @param array $annotationClassesByName */ public function registerCustomAnnotations($annotationClassesByName) { $manager = Annotations::getManager(); foreach (array_keys($annotationClassesByName) as $name) { $manager->registry[$name] = $annotationClassesByName[$name]; } }
public static function register() { $manager = Annotations::getManager(); $manager->registry['get'] = Get::class; $manager->registry['post'] = Post::class; $manager->registry['delete'] = Delete::class; $manager->registry['controller'] = Controller::class; }
public function __construct() { Annotations::$config['cache'] = false; $annotationManager = Annotations::getManager(); $annotationManager->registry['assert'] = 'Phprtest\\Annotations\\AssertAnnotation'; $annotationManager->registry['provider'] = 'Phprtest\\Annotations\\ProviderAnnotation'; $annotationManager->registry['repeat'] = 'Phprtest\\Annotations\\RepeatAnnotation'; $this->setAnnotations($annotationManager); $this->setPrinter(new ConsolePrinter()); $this->setProfiler(new Profiler(true)); }
protected function assertApplyConstrains(array &$annotations, $memberType) { $manager = Annotations::getManager(); $methodReflection = new ReflectionMethod(get_class($manager), 'applyConstraints'); $methodReflection->setAccessible(true); $methodReflection->invokeArgs($manager, array(&$annotations, $memberType)); $this->check(count($annotations) > 0); }
$vendor_path = dirname(__DIR__) . '/vendor'; if (!is_dir($vendor_path)) { echo 'Install dependencies first' . PHP_EOL; exit(1); } require_once $vendor_path . '/autoload.php'; $auto_loader = new ClassLoader(); $auto_loader->addPsr4("mindplay\\demo\\", __DIR__); $auto_loader->register(); ## Configure the cache-path. The static `Annotations` class will configure any public ## properties of `AnnotationManager` when it creates it. The `AnnotationManager::$cachePath` ## property is a path to a writable folder, where the `AnnotationManager` caches parsed ## annotations from individual source code files. Annotations::$config['cache'] = new AnnotationCache(__DIR__ . '/runtime'); ## Register demo annotations. Package::register(Annotations::getManager()); ## For this example, we're going to generate a simple form that allows us to edit a `Person` ## object. We'll define a few public properties and annotate them with some useful metadata, ## which will enable us to make decisions (at run-time) about how to display each field, ## how to parse the values posted back from the form, and how to validate the input. ## ## Note the use of standard PHP-DOC annotations, such as `@var string` - this metadata is ## traditionally useful both as documentation to developers, and as hints for an IDE. In ## this example, we're going to use that same information as advice to our components, at ## run-time, to help them establish defaults and make sensible decisions about how to ## handle the value of each property. class Person { /** * @var string * @required