View helpers and Controller plugin helpers in closures
The ZeffMu\App class should expose methods to allow accessing view and controller helpers in closures. Ideally something like following I suppose:
$app = \ZeffMu\App::init();
$app
->route('/', function() use ($app) {
$form = new Form(/* yaddayadda */);
return $app->viewHelper()->form($someForm);
})
->route('/login', function() use ($app) {
return $app->controllerHelper()->redirect('/');
})
Is it ok to limit this functionality to PHP 5.4? if so then we just need to run some more tests on various accesses.
Currently, due to the upgrade/change to the ClosureController and the bindTo, $this inside the closure under PHP 5.4 is the instance of the ClosureController. This should give access to the controller methods (need another test for that to be certain)
Thoughts?
Well, this can work with both:
5.3:
->route('/', function (/* ... */, $controller) {
$controller->doStuff();
});
5.4:
->route('/', function () {
$this->doStuff();
});
hmm,
maybe something like an update to app to store the event rather than pushing more into the args?
so App::getDispatchedEvent()
which would return the event, from which the controller could be got
5.3
->route('/', function () use ($app) {
$event = $app->getDispatchedEvent();
$controller = $event->getTarget();
$controller->doStuff();
});
5.4 would remain the same
->route('/', function () use ($app) {
$event = $app->getDispatchedEvent();
$controller = $this;
$controller->doStuff();
});
Hmm... A bit too verbose, no? :) But anyway, I think there's no problem if the feature is left out for 5.3 for now. Ralph's method would allow us to add an arbitrary amount of parameters to the closures though
is being "too verbose" a problem?
On Tue, Feb 5, 2013 at 12:47 PM, Marco Pivetta [email protected]:
Hmm... A bit too verbose, no? :) But anyway, I think there's no problem if the feature is left out for 5.3 for now. Ralph's method would allow us to add an arbitrary amount of parameters to the closures though
— Reply to this email directly or view it on GitHubhttps://github.com/BinaryKitten/ZeffMu/issues/7#issuecomment-13127660.
@BinaryKitten well, it's a micro-framework ;)