ReflectionAnnotatedMethod does not work

37 views
Skip to first unread message

Andreas Kraus

unread,
Jul 23, 2013, 5:30:13 PM7/23/13
to addendum...@googlegroups.com
Hi,

I've some problems using the ReflectionAnnotatedMethod class.
  1. I created the class Permission, extending Annotation
  2. I created the class ModuleNews with the method listAction and the Annotation @Permission('ADD')
  3. I tried to get the Permission class, but it does not work

Does anyone have some ideas?



<?php

class ModuleNews extends CoreModule {

    /**
     *
     * @param type $newst_id
     * @param type $page
     * @param type $pageSize
     * @Permission('ADD')
     */
    protected function listAction($newst_id = 1, $page = null, $pageSize = null) {
   
    }
}


class Permission extends Annotation {
   
    private $perm;
   
    public function __construct($options) {
        parent::__construct();
       
        if (!isset($options['value'])) {
            throw new Exception("Permission is not set");
        }
       
        $this->perm = $options['value'];
    }
   
    public function getPermission() {
        return $this->perm;
    }
}


$reflectionMethod = new ReflectionAnnotatedMethod('ModuleNews', 'listAction');        

if ($reflectionMethod->hasAnnotation('Permission')) {
    $permission = $reflectionMethod->getAnnotation('Permission')->getPermission();
    echo $permission;
}

?>

johno

unread,
Aug 2, 2013, 4:04:08 PM8/2/13
to addendum...@googlegroups.com
Hi,

why are you trying to override final constructor? https://code.google.com/p/addendum/source/browse/trunk/annotations.php#29

Jano
Reply all
Reply to author
Forward
0 new messages