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

ReflectionException when having AbstractAccept routine #55

Closed
Fusselwurm opened this issue May 31, 2012 · 3 comments
Closed

ReflectionException when having AbstractAccept routine #55

Fusselwurm opened this issue May 31, 2012 · 3 comments

Comments

@Fusselwurm
Copy link
Contributor

When running this piece of code:

<?php

require 'bootstrap.php'; // PSR-0 autoloader in there

class RouteKnowsGet implements \Respect\Rest\Routable {
    public function get($param) {
        return "ok: $param";
    }
}
class RouteKnowsNothing implements \Respect\Rest\Routable {
}

$_SERVER['HTTP_ACCEPT'] = 'application/json';

$router = new \Respect\Rest\Router();
$router->isAutoDispatched = false;

$r1 = $router->any('/meow/*', 'RouteKnowsGet');
$r1->accept(array('application/json' => 'json_encode')); // some routine inheriting from AbstractAccept 

$router->any('/moo/*', 'RouteKnowsNothing');

$out = $router->run(new \Respect\Rest\Request('get', '/meow/blub')); // ReflectionException

echo "I survived! Result is: '$out'\n";

I get the following exception:

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Method RouteKnowsNothing::GET() does not exist' in /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Routes/ClassName.php:43
Stack trace:
#0 /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Routes/ClassName.php(43): ReflectionMethod->__construct('RouteKnowsNothi...', 'GET')
#1 /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Request.php(75): Respect\Rest\Routes\ClassName->getReflection('GET')
#2 /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Routes/AbstractRoute.php(102): Respect\Rest\Request->routineCall('when', 'GET', Object(Respect\Rest\Routines\Accept), Array)
#3 /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Router.php(197): Respect\Rest\Routes\AbstractRoute->matchRoutines(Object(Respect\Rest\Request), Array)
#4 /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Router.php(215): Respect\Rest\Router->dispatchRequest(Object(Respect\Rest\Request))
#5 /home/fusselwurm/dev/src/Rest/tests/moo2.php(24): Respect\Rest\Router->run(Object(Respect\R in /home/fusselwurm/dev/src/Rest/library/Respect/Rest/Routes/ClassName.php on line 43

@alganet
Copy link
Member

alganet commented May 31, 2012

I'll take a look at it! Thanks for reporting =)

@alganet
Copy link
Member

alganet commented Jun 1, 2012

This is being caused by a recent change. This line isn't handling errors properly. This line is actually a line that processes routines (like the Accept one in your sample), so we can't try/catch there, 'cause for a non-existing method routines shoudn't be called at all.

I'm gonna work on this soon. Perhaps @augustohp can do that before me!

@alganet
Copy link
Member

alganet commented Jun 17, 2012

This seems to be fixed on my dev branch. The code in the tests is the same you provided! Should be published soon.

@alganet alganet closed this as completed Jun 17, 2012
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

2 participants