codeguy/Slim — pull request #502 by janeklb (2013-04-11 09:52:06+00:00)
Title: adding dispatchContext support (for PHP 5.4+)

*I'm not sure if this implementation is ideal, however I think the idea itself is quite powerful and I figured it would be best illustrated via a pull request.*

When building Slim apps I've often found it desirable to have access to the \Slim\Slim object inside my route callables. Of course, you can always use PHP's `use` keyword:
```PHP
$slim = new \Slim\Slim();
$slim->map('/foo', function() use($slim) {
$slim->forward('/bar');
});
```

However, this can be a bit tedious after declaring a lot of routes.
As a shortcut, I propose a *"dispatchContext"* that will be accessible via `$this` inside the callables.

The pull request implements this in a way that would be used as follows:
```PHP
$slim = new \Slim\Slim();
$slim->setDispatchContext($slim);
$slim->map('/foo', function() {
$this->forward('/bar');
});
```

Of course, the dispatch context can be set to anything, which could make it a very powerful controller delegate.