These are chat archives for ppi/framework

27th
Nov 2015
Paul Dragoonis
@dragoonis
Nov 27 2015 17:21
@KorvinSzanto @AndrewCarterUK - here’s the PR from the work we were going over - thoughts? https://github.com/ppi/framework/pull/137/files?diff=split
Paul Dragoonis
@dragoonis
Nov 27 2015 22:58
I completed Fast Route integration, but I’m stuck on something.

My controller is:

public function fastRouteAction($request, $response)

The Fast Route definition is:

$r->addRoute('GET', '/fastroute/{name}', ['Application\Controller\Index', 'fastRouteAction']);

The dispatcher is doing this, against the array (controller, action):

$result = call_user_func_array(
     $routeParams['_controller'],
     array($request, $response)
);

This is my error:

Runtime Notice: call_user_func_array() expects parameter 1 to be a valid callback, 
non-static method Application\Controller\Index::fastRouteAction() should not be called statically
Roman Tsiupa
@dracony
Nov 27 2015 23:09
$routeParams['_controller'] s probably a class name
not an instance
thats why you get the error
Paul Dragoonis
@dragoonis
Nov 27 2015 23:11
_controller is ['Application\Controller\Index', 'fastRouteAction']
I’d like to call it non-statically.
Roman Tsiupa
@dracony
Nov 27 2015 23:11
well
how
?
i mean you need a controller instance to call it non statically
I think
you might need a callback there:
Paul Dragoonis
@dragoonis
Nov 27 2015 23:13
Yea, I could try __invoke() or make a callback on my route definition.
Roman Tsiupa
@dracony
Nov 27 2015 23:14
$r->addRoute('GET', '/fastroute/{name}', function() {
     $controller = new Application\Controller\Index();
     return $controller->fastRouteAction();
});
Paul Dragoonis
@dragoonis
Nov 27 2015 23:19
Refactoring the ControllerResolver class here, to cope better with __invoke()
Seems okay though
        if (is_object($controller)) {
            if (method_exists($controller, '__invoke')) {
                return $controller;
            }
        }
I noticed Slim3 is using FastRoute, and they have controllers with __invoke() definitions, specified like this.
$app->any('/user', 'MyRestfulController’);

This works fine in PPI

$r->addRoute('GET', '/fastroute/{name}', new Application\Controller\Index());

It has __invoke ^

Roman Tsiupa
@dracony
Nov 27 2015 23:29
but then you are instantiating every controller all the time