chriso/klein.php — pull request #92 by Rican7 (2013-05-13 15:19:23+00:00)
Title: Klein v2

## Klein - Version 2

Here we go, @chriso...

Here it is, the **Version 2** rewrite of Klein.php.

Its been a long time coming: many commits, thousands of lines, and a lot of unit tests. :P

The biggest differences are:
- The modern OOP pattern to the code
- The [PSR-2 compliance][1]
- The [PSR-0 autoloader][2] compatibility
- The more modular codebase
- The heavily documented code (with [PHPdoc][3] style documentation)
- The dependency injection approach to the different Request, Response, and Service handling classes
- The more testable approach to also injecting the request data that is normally contained in the super-globals (your idea!)
- The namespaced, contained code that keeps the global scope clean and relies less on static variables
- The use of custom exceptions that extend the SPL (standard library) for a more consistent exception handling pattern
- The unit tested and "integration tested" code
- The Symfony inspired classes that have no external dependencies

The routing algorithm itself has not been changed. Klein 2's efficiency therefore hasn't been reduced thanks to PHP's handling of objects (they're inexpensive), and the easily APC-cacheable classes (that depend less on the super-globals).

The code was designed to satisfy more of the "Laws of Demeter" and the "Single Responsibility Principle", in that each class handles its own objects and simply interfaces with its related classes without ever directly operating on each other's properties (most of the properties are behind getters/setters).

The use of Klein has also not changed much, other than the lack of the ability to call Klein's methods from anywhere (since the scope isn't global). This is its strength, though, as it allows multiple instances of Klein (great for testing) and a less dirty global scope with less of a chance to accidentally change Klein's intended behavior at runtime.

### Anyway

**Let me know what you think!** You won't hurt my feelings if you don't like something. :tongue: Merging this code into master isn't nearly as scary of an idea now that we have [well tagged versions][4]. And after a merge, the code can be tagged as a major version (2.0.0), so that [dependency managers][5] won't automatically update!

[1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
[3]: http://www.phpdoc.org/
[4]: https://github.com/chriso/klein.php/tags
[5]: http://getcomposer.org/