We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Strange Annotation Behavior

Can't get annotations to work as expected. My BaseController implements a "beforeExecuteRoute" method which tries to get an annotation called "Permission". But the parser only recognize the "Route" annotation.

object(Phalcon\Annotations\Collection)[48] protected '_position' => int 0 protected '_annotations' => array (size=1) 0 => object(Phalcon\Annotations\Annotation)[62] protected '_name' => string 'Route' (length=5) protected '_arguments' => array (size=2) ... protected '_exprArguments' => array (size=2) ...

Why does this happens? What can I do that the annotation Parser also recognizes the other Annotations?



98.9k

It would be fine to post the related docblock

edited Sep '14

It would be fine to post the related docblock

Sure (sorry)

/**
* @Permission("deny")
* @Route("/login", name="users-login")
*/

And here is the generated annotation file:

<?php return Phalcon\Annotations\Reflection::__set_state(array(
  '_reflectionData' => 
 array (
   'class' => 
   array (
     0 => 
     array (
       'type' => 300,
       'name' => 'package',
       'file' => '/var/www/clients/client1/web2/web/app/controllers/UsersController.php',
       'line' => 8,
     ),
     1 => 
     array (
       'type' => 300,
       'name' => 'RoutePrefix',
       'arguments' => 
       array (
         0 => 
         array (
           'expr' => 
           array (
             'type' => 303,
             'value' => '/users',
           ),
         ),
       ),
       'file' => '/var/www/clients/client1/web2/web/app/controllers/UsersController.php',
       'line' => 8,
     ),
   ),
   'methods' => 
   array (
     'loginAction' => 
     array (
       0 => 
       array (
         'type' => 300,
         'name' => 'Permission',
         'arguments' => 
         array (
           0 => 
           array (
             'expr' => 
             array (
               'type' => 303,
               'value' => 'deny',
             ),
           ),
         ),
         'file' => '/var/www/clients/client1/web2/web/app/controllers/UsersController.php',
         'line' => 16,
       ),
       1 => 
       array (
         'type' => 300,
         'name' => 'Route',
         'arguments' => 
         array (
           0 => 
           array (
             'expr' => 
             array (
               'type' => 303,
               'value' => '/login',
             ),
           ),
           1 => 
           array (
             'expr' => 
             array (
               'type' => 303,
               'value' => 'users-login',
             ),
             'name' => 'name',
           ),
         ),
         'file' => '/var/www/clients/client1/web2/web/app/controllers/UsersController.php',
         'line' => 16,
       ),
     ),
     'registerAction' => 
     array (
       0 => 
       array (
         'type' => 300,
         'name' => 'Route',
         'arguments' => 
         array (
           0 => 
           array (
             'expr' => 
             array (
               'type' => 303,
               'value' => '/register',
             ),
           ),
         ),
         'file' => '/var/www/clients/client1/web2/web/app/controllers/UsersController.php',
         'line' => 54,
       ),
     ),
     'indexAction' => 
     array (
       0 => 
       array (
         'type' => 300,
         'name' => 'Permission',
         'arguments' => 
         array (
           0 => 
           array (
             'expr' => 
             array (
               'type' => 303,
               'value' => 'users-index',
             ),
           ),
         ),
         'file' => '/var/www/clients/client1/web2/web/app/controllers/UsersController.php',
         'line' => 63,
       ),
     ),
   ),
 ),
  '_classAnnotations' => NULL,
  '_methodAnnotations' => NULL,
  '_propertyAnnotations' => NULL,
));


98.9k
Accepted
answer

I've made the following test:


class Example
{
        /**
         * @Permission("deny")
         * @Route("/login", name="users-login")
         */
        public function some()
        {

        }
}

$reader = new Phalcon\Annotations\Reader();
$parsing = $reader->parse('Example');

print_r($parsing['methods']['some'])

The output:

Array
(
    [0] => Array
        (
            [type] => 300
            [name] => Permission
            [arguments] => Array
                (
                    [0] => Array
                        (
                            [expr] => Array
                                (
                                    [type] => 303
                                    [value] => deny
                                )

                        )

                )

            [file] => /opt/local/apache2/htdocs/a.php
            [line] => 6
        )

    [1] => Array
        (
            [type] => 300
            [name] => Route
            [arguments] => Array
                (
                    [0] => Array
                        (
                            [expr] => Array
                                (
                                    [type] => 303
                                    [value] => /login
                                )

                        )

                    [1] => Array
                        (
                            [expr] => Array
                                (
                                    [type] => 303
                                    [value] => users-login
                                )

                            [name] => name
                        )

                )

            [file] => /opt/local/apache2/htdocs/a.php
            [line] => 6
        )

)