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

Dispatcher getActiveMethod breaks method name letter case #2313

Closed
baryshev opened this issue Apr 8, 2014 · 11 comments
Closed

Dispatcher getActiveMethod breaks method name letter case #2313

baryshev opened this issue Apr 8, 2014 · 11 comments

Comments

@baryshev
Copy link
Contributor

baryshev commented Apr 8, 2014

If method name have one word in prefix like indexAction or addAction everything works fine. But if method have a more complex name like addPostAction or showMeSomethingAction $dispatcher->getActiveMethod() returns unexpected results: addpostAction and showmesomethindAction. Method name before Action keyword unexpectedly lowercased.

It makes impossible to use this methods in annotations reader.

        $annotations = $this->annotations->getMethod(
            $dispatcher->getActiveController(),
            $dispatcher->getActiveMethod()
        );

This code not working, because $dispatcher->getActiveMethod() returns wrong method name (partially lowercased).

OS: Mac OS X 10.9.2
PHP version: 5.5.11
Phalcon version: 1.3.1

@baryshev
Copy link
Contributor Author

baryshev commented Apr 9, 2014

$dispatcher->getActionName() also returns lowercased method name, but without Action postfix.

@dreamsxin
Copy link
Contributor

Case can't control the user to enter the url, so only unified converted to lowercase.

@baryshev
Copy link
Contributor Author

baryshev commented Apr 9, 2014

This naming restrictions makes difficult to develop more complex applications. One word method naming and REST-like routing that strict representing method and class not the only way to make routing.

@baryshev
Copy link
Contributor Author

baryshev commented Apr 9, 2014

Also, $router->addGet('/', 'Posts::addPost'); works fine. I see this problem only with annotations based router.

@dreamsxin
Copy link
Contributor

Understand your meaning this time, I check.

@phalcon
Copy link
Collaborator

phalcon commented Apr 9, 2014

Try using Phalcon\Mvc\Dispatcher::getActiveMethod instead of getActionName

@baryshev
Copy link
Contributor Author

baryshev commented Apr 9, 2014

There is only one difference between this methods.Phalcon\Mvc\Dispatcher::getActiveMethod returns full method name with Action postfix, Phalcon\Mvc\Dispatcher::getActionName returns only base name of method (without Action postfix). But both returns base method name in lowercase.

Problem not in Phalcon\Mvc\Dispatcher. It's only returns value.
There is some difference between \Phalcon\Mvc\Router\Annotations and \Phalcon\Mvc\Router

$router = new \Phalcon\Mvc\Router();
$router->add(
    "/admin/users/change-password",
    array(
        "controller" => "users",
        "action"     => "changePassword",
    )
);

// Trying to get method name from $dispatcher
$dispatcher->getActiveMethod(); // Returns "changePasswordAction" - everything is fine
$router = new \Phalcon\Mvc\Router\Annotations(false);
$router->addResource('Users', '/');

// Users Controller
class UsersController extends Controller
{
    /**
     * @Route('/admin/users/change-password')
     */
    public function changePasswordAction() {
    }
}

// Trying to get method name from $dispatcher
$dispatcher->getActiveMethod(); // Returns "changepasswordAction" - lowercased method name with 'Action' postfix

In the last example we get unexpected method name. In other words, now we can't get current active method with \Phalcon\Mvc\Router\Annotations router.

phalcon pushed a commit that referenced this issue Apr 12, 2014
Fix #2313 about Phalcon\Annotations\Annotation
@baryshev
Copy link
Contributor Author

I checked 1.3.2 with @dreamsxin fix. Error was fixed. Thanks!

@niden niden closed this as completed in d59c83d Jun 4, 2014
@clowestab
Copy link

This bug is back in 2.0..

@VincentMolinie
Copy link

Bug is back in 3.0.1. Could we fix it please ?

@sergeyklay
Copy link
Contributor

@VincentMolinie Could you please open a new issue with minimal code to reproduce

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

6 participants