seasar\util\Annotation reads the comment and constant annotation which were described in the class.
The annotation string is processed with the eval function as PHP Array Expression.
Let's create an annotated service class as an example.
/** * @Sample('name' => 'seasar') */ class Service { const SAMPLE = '"name" => "seasar.php"'; }
The execution script which reads Annotation is as follows.
<?php require_once('S2Container/S2Container.php'); use seasar\container\S2ApplicationContext as s2app; s2app::import(dirname(__FILE__) . '/classes'); $service = new \ReflectionClass('Service'); $annotation = \seasar\util\Annotation::get($service, '@Sample'); print_r($annotation); $annotation = \seasar\util\Annotation::get($service, 'SAMPLE'); print_r($annotation);
If the above-mentioned script is performed, the value described by commnet annotation and constant annotation is acquirable as an array value.
% php example.php Array ( [name] => seasar ) Array ( [name] => seasar.php ) %
NOTE | |
---|---|
This Example is located in examples/misc/annotation. |
COMMENT Setup.
A setup which reads comment annotation.
seasar\util\Annotation::$COMMENT = true;CONSTANT Setup.
A setup which reads constant annotation.
seasar\util\Annotation::$CONSTANT = true;Annotation::get method.
Annotation is read. ReflectionClass, ReflectionMethod, and ReflectionProperty can be specified as the 1st argument. ReflectionClass is passed when reading class annotation or constant annotation. ReflectionMethod is passed when reading method annotation. ReflectionProperty is passed when reading property annotation.
/** * @param ReflectionClass|ReflectionMethod|ReflectionProperty $reflection * @param string $annotation * @return array * @throw seasar\exception\AnnotationNotFoundException */ publi static function get($reflection, $annotation)Annotation::has method.
It returns whether annotation is described or not. ReflectionClass, ReflectionMethod, and ReflectionProperty can be specified as the 1st argument. ReflectionClass is passed when investigating class annotation or constant annotation. ReflectionMethod is passed when investigating method annotation. ReflectionProperty is passed when investigating property annotation.
/** * @param ReflectionClass|ReflectionMethod|ReflectionProperty $reflection * @param string $annotation * @return boolean */ publi static function has($reflection, $annotation)
© Copyright The Seasar Foundation and the others 2005-2010, all rights reserved. |