| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 | <?php/** * TEST CASE: Sample Annotations */use mindplay\annotations\Annotation;use mindplay\annotations\IAnnotationParser;use mindplay\annotations\AnnotationException;use mindplay\annotations\standard\TypeAnnotation;/** * @usage('class'=>true, 'property'=>true, 'method'=>true, 'inherited'=>true, 'multiple'=>true) */class NoteAnnotation extends Annotation{    public $note;    public function initAnnotation(array $params)    {        $this->map($params, array('note'));        if (!isset($this->note)) {            throw new AnnotationException("NoteAnnotation requires a note property");        }    }}/** * @usage */class UselessAnnotation extends Annotation{}/** * @usage('class'=>true) */class DocAnnotation extends Annotation implements IAnnotationParser{    public $value;    public static function parseAnnotation($value)    {        return array('value' => intval($value));    }}/** * @usage('property'=>true, 'multiple'=>false) */class SingleAnnotation extends Annotation{    public $test;}/** * @usage('property'=>true, 'multiple'=>false, 'inherited'=>true) */class OverrideAnnotation extends Annotation{    public $test;}/** * @usage('method'=>true) */class SampleAnnotation extends Annotation{    public $test;}/** * @usage('class'=>true, 'inherited'=>false) */class UninheritableAnnotation extends Annotation{    public $test;}class InheritUsageAnnotation extends SampleAnnotation{}/** * @Doc * @usage('class'=>true) */class UsageAndNonUsageAnnotation extends Annotation{}/** * @Doc */class SingleNonUsageAnnotation extends Annotation{}class WrongInterfaceAnnotation{}class TypeAwareAnnotation extends TypeAnnotation{}class NoUsageAnnotation{}/** * TEST CASE: Sample Classes * * @doc 1234 (this is a sample PHP-DOC style annotation) *//** * @note("Applied to the TestBase class") * @uninheritable('test'=>'Test cannot inherit this annotation') */class TestBase{    /**     * @note("Applied to a TestBase member")     */    protected $sample = 'test';    /**     * @single('test'=>'one is okay')     * @single('test'=>'two is one too many')     */    protected $only_one;    /**     * @override('test'=>'This will be overridden')     */    private $override_me;    /**     * @note("First note annotation")     * @override('test'=>'This annotation should get filtered')     */    private $mixed;    /**     * @note("Applied to a hidden TestBase method")     * @sample('test'=>'This should get filtered')     */    public function run()    {    }}/** * A sample class with NoteAttributes applied to the source code: * * @Note( *   "Applied to the Test class (a)" * ) * * @Note("And another one for good measure (b)") */class Test extends TestBase{    /**     * @Note("Applied to a property")     */    public $hello = 'World';    /**     * @Override('test'=>'This annotation overrides the one in TestBase')     */    private $override_me;    /**     * @Note("Second note annotation")     */    private $mixed;    /**     * @Note("First Note Applied to the run() method")     * @Note("And a second Note")     */    public function run()    {    }}/** * @Note('class-first') */class FirstClass{    /**     * @var string     * @Note('prop-first')     */    protected $prop;    /**     * @Note('method-first')     */    protected function someMethod()    {    }}/** * @Note('class-second') * @stop */class SecondClass extends FirstClass{    /**     * @var string     * @Note('prop-second')     */    protected $prop;    /**     * @Note('method-second')     */    protected function someMethod()    {    }}/** * @Note('class-third') */class ThirdClass extends SecondClass{    /**     * @var string     * @Note('prop-third')     */    protected $prop;    /**     * @Note('method-third')     */    protected function someMethod()    {    }}/** * Test that using an core class will not break parsing. * https://github.com/php-annotations/php-annotations/issues/59 * * @Note("An example class annotation.") */class TestClassExtendingCore extends ReflectionClass{}/** * Test that using an extension class will not break parsing. * https://github.com/php-annotations/php-annotations/issues/59 * * @Note("An example class annotation.") */class TestClassExtendingExtension extends SplFileObject{}/** * @Note("Base note.") */class TestClassExtendingUserDefinedBase{}/** * Test that using an user defined class will not break parsing. * https://github.com/php-annotations/php-annotations/issues/59 * * @Note("Note of child.") */class TestClassExtendingUserDefined extends TestClassExtendingUserDefinedBase{}/** * @WrongInterface */class TestClassWrongInterface{}class TestClassFileAwareAnnotation{    /** @TypeAware IAnnotationParser */    public $prop;}interface TestInterface{}class BrokenParamAnnotationClass{    /**     * @param $paramName     */    protected function brokenParamAnnotation($paramName)    {    }}
 |