Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing annotations router #1040

Closed
3axap4eHko opened this issue Aug 8, 2013 · 15 comments
Closed

Error parsing annotations router #1040

3axap4eHko opened this issue Aug 8, 2013 · 15 comments

Comments

@3axap4eHko
Copy link

I'am called my controller:
App\Controller\Test_AdminController
then add resource to loader:
$router->addResource('App\Controller\Test_Admin');
after first load all right, but next time I'am all time getting error:
App\Controller\Test_adminController handler class cannot be loaded
why Test_AdminController is Test_adminController after first reload?
OS: Ubuntu
This occurs when using Phalcon\Annotations\Adapter\Files
When Annotations Adapter is Phalcon\Annotations\Adapter\Memory - all right

@3axap4eHko
Copy link
Author

Phalcon\Mvc\Router\Annotations has addResource method.
Documentation

@3axap4eHko
Copy link
Author

Guy, I'am not looking for resolving this issue, I'am just post Bug for fixing it. Do you understand it?
Also a resource handler Test__Admin will be converted correctly to Test__AdminController.

@ghost
Copy link

ghost commented Aug 9, 2013

@3axap4eHko could you please post the code that reproduces the bug?

@3axap4eHko
Copy link
Author

No, I could not post the code now. Just repoduced by redefining $di = new Phalcon\DI\FactoryDefault();:

    $di->set('annotations', function()
    {
        $annotations = new Phalcon\Annotations\Adapter\Files(['annotationsDir' => __DIR__ . '/tmp/']);
        return $annotations;
    });
    $di->set('router', function()
    {
        $router = new Phalcon\Mvc\Router\Annotations();
        $router->addResource('Test_Admin');

        return $router;
    });

@3axap4eHko
Copy link
Author

Mistake is in the parsing handler of router resource from annotation with Phalcon\Annotations\Adapter\Files. When handler is Test_Admin at first time - all right, and the framework does find controller Test_AdminController, but at the next time the framework looking for Test_adminController where word Admin is not beginning form the capital letter. Does you see difference beetwen: Test_adminController and Test_AdminController?
This occurs when using an adapter Phalcon\Annotations\Adapter\Files, but when using Phalcon\Annotations\Adapter\Memory - all right!!!
Please, read my issue more carefully!

@ghost
Copy link

ghost commented Aug 16, 2013

With the code you gave I am unable to reproduce the issue.

test_admincontroller.php is correctly created, its contents is as follows:

<?php return Phalcon\Annotations\Reflection::__set_state(array(
  '_reflectionData' => 
 array (
   'class' => 
   array (
     0 => 
     array (
       'type' => 300,
       'name' => 'RoutePrefix',
       'arguments' => 
       array (
         0 => 
         array (
           'expr' => 
           array (
             'type' => 303,
             'value' => '/admin',
           ),
         ),
       ),
       'file' => '/path/to/test/AdminController.php',
       'line' => 4,
     ),
   ),
   'methods' => 
   array (
     'indexAction' => 
     array (
       0 => 
       array (
         'type' => 300,
         'name' => 'Get',
         'arguments' => 
         array (
           0 => 
           array (
             'expr' => 
             array (
               'type' => 303,
               'value' => '/',
             ),
           ),
         ),
         'file' => '/path/to/test/AdminController.php',
         'line' => 9,
       ),
     ),
   ),
 ),
  '_classAnnotations' => NULL,
  '_methodAnnotations' => NULL,
  '_propertyAnnotations' => NULL,
));

On subsequent requests the cache is rad and the correct file gets included.

Could you please provide a complete reproducible example of the bug?

@3axap4eHko
Copy link
Author

Are you OS is Linux?

@ghost
Copy link

ghost commented Aug 16, 2013

yes, Ubuntu

@3axap4eHko
Copy link
Author

structure:

/cache
    /annotations
/src
    /App
        /Controller
            /Admin_TestController.php
/public
    /index.php

/public/index.php

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

use Phalcon\DI\FactoryDefault;

if (!defined('APP_DIR'))
{
    define('APP_DIR', dirname(__DIR__));
}


$loader = new Phalcon\Loader();

$loader->registerNamespaces([
    'App' => APP_DIR . '/src/App'
])->register();

$di = new FactoryDefault();

$di->set('annotations', function()
{
    $annotations = new Phalcon\Annotations\Adapter\Files(array(
        'annotationsDir' => APP_DIR . '/cache/annotations/'
    ));

    return $annotations;
});

$di->set('router', function()
{
    $router = new Phalcon\Mvc\Router\Annotations(false);
    $router->setUriSource(Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI);
    $router->addResource('App\Controller\Test_Admin');

    return $router;
});


$di->set('dispatcher', function()
{
    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('App\Controller');

    return $dispatcher;
});

$di->set('view', function()
{
    $view = new Phalcon\Mvc\View();
    $view->setViewsDir(APP_DIR . '/view');

    return $view;
});


$application = new \Phalcon\Mvc\Application($di);

echo $application->handle()->getContent();

/src/App/Controller/Admin_TestController.php

<?php

namespace App\Controller;

use Phalcon\Mvc\Controller,
    Phalcon\Tag;

/**
 * @RoutePrefix("/")
 */

class Test_AdminController extends Controller
{
    /**
     * @Get("/")
     */
    public function testAction()
    {

    }
}

Error on more than one times reload page, when annotations taked from file

Fatal error: Uncaught exception 'Phalcon\Mvc\Dispatcher\Exception' with message 'App\Controller\Test_adminController handler class cannot be loaded' in /home/data/www/localhost/public/index.php:60
Stack trace:
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('App\Controller\...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /home/data/www/localhost/public/index.php(60): Phalcon\Mvc\Application->handle()
#3 {main} thrown in /home/data/www/localhost/public/index.php on line 60

@ghost
Copy link

ghost commented Aug 16, 2013

OK trying

@ghost
Copy link

ghost commented Aug 16, 2013

This one does not work at all:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class App\Controller\Test_AdminController does not exist' in /home/vladimir/workspace/cphalcon/1040/public/index.php:60

This happens on the very first request.

@ghost
Copy link

ghost commented Aug 16, 2013

The file is probably named /src/App/Controller/Test_AdminController.php, not /src/App/Controller/Admin_TestController.php?

@3axap4eHko
Copy link
Author

clone it

@ghost
Copy link

ghost commented Aug 16, 2013

OK, confirmed.

@3axap4eHko
Copy link
Author

Have a nice day)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant