cakephp-annotation-control-list icon indicating copy to clipboard operation
cakephp-annotation-control-list copied to clipboard

Getting ReflectionException errors trying to use this plugin

Open akkaweb opened this issue 9 years ago • 7 comments

@josegonzalez this is a brilliant idea. I am trying to implement it in my application, but I have encountered an issue. To start with, I am trying to load the homepage at PagesController\display, but I encounter the following error:

The parameter class is expected to be either a string or an object

If in AppController I add $this->Auth->allow(['display']) inside beforeFilter(), then the page works, but obviously that is now how this is intended to work.

This is how I have loaded it

    $this->loadComponent('Auth', [
        'authenticate' => [
            'Josegonzalez/AnnotationControlList.AnnotationForm' => [
                'passwordHasher' => 'Blowfish',
                'roleField' => 'role', // `roleField` is `role` by default
            ]
        ],
        'authorize' => [
            'Josegonzalez/AnnotationControlList.Annotation',
            'roleField' => 'role', // `roleField` is `role` by default
        ],
    ]);

and my display annotation looks like this

  /**
   * Displays a view
   *
   * @roles all
   *
   * @return void|\Cake\Network\Response
   * @throws \Cake\Network\Exception\NotFoundException When the view file could not
   *  be found or \Cake\View\Exception\MissingTemplateException in debug mode.
   */
   public function display() {}

I have done several tests, but I am not sure if this is a bug or an error on my part.

akkaweb avatar Mar 05 '16 06:03 akkaweb

Can you gist the entire stacktrace of the error?

josegonzalez avatar Mar 07 '16 01:03 josegonzalez

@josegonzalez thanks for your reply. Please review here: https://gist.github.com/akkaweb/32015f96687ad389f36f

akkaweb avatar Mar 07 '16 01:03 akkaweb

  • Can you gist the entire controller?
  • What happens if you make that @throws a single line?
  • What happens if you remove the non-acl plugin annotations?

josegonzalez avatar Mar 07 '16 01:03 josegonzalez

@josegonzalez this is the gist for my AppController.php and PagesController.php https://gist.github.com/akkaweb/7b3b72b4f70dad41cfca

While debugging, I noticed getController() was not returning anything, so I made the following change which caused the ERROR to go away, but Authentication/Authorization is not working. File src/Lib/AnnotationParserTrait.php, I replaced this:

public function getController() {
    if (!empty($this->ComponentRegistry)) {
      return $this->ComponentRegistry->getController();
    }

    return $this->_Controller;
  }

With this:

public function getController() {
    if (!empty($this->_registry)) {
      return $this->_registry->getController();
    }

    return $this->_Controller;
  }

As you will see in the AppController.php file, I commented out my original Auth code. However, if I comment out your Annotation's Auth and uncomment my original Auth requests to display() is redirected to users/login

Note: @throws in a single line did not make a difference on the result and removing the non-acl plugin annotations did not make a difference either.

akkaweb avatar Mar 07 '16 18:03 akkaweb

I'll take a look. I fixed the registry bit, wonder how I missed that in the first place. Probably was mocking things...

josegonzalez avatar Mar 07 '16 20:03 josegonzalez

Great! Thanks for taking a look

akkaweb avatar Mar 07 '16 22:03 akkaweb

Seems like I have the same issue with the Model version... except there is no getController method...

josegonzalez avatar Mar 07 '16 22:03 josegonzalez