peej/tonic — pull request #111 by lushchick (2012-09-07 10:51:24+00:00)
Title: Application factory method

Hey Paul,

When working with Tonic, i found it difficult to extend some classes with my application-specific functionality (e.g. Response). So I decided to write a "smart" factory method for class instantiation. It accepts $className as first parameter, and all other passed parameters are forwarded to $className constructor (or factory method of $className, if it exists).

If $className does not include leading backslash, this method prepends current Application namespace to it, for instance:

```php
// let's say $app is instance of Project\Application, which extends Tonic\Application
// here if Project\Response class exists, it will be loaded. Otherwise Tonic\Response is loaded
// $code and $body are passed to Response::factory method
$res = $app->factory('Response', $code, $body);
```

It makes every class loaded via Tonic\Application::factory easily substitutable, which is great if developer wants to add some methods to base Tonic classes.