chriso/klein.php — pull request #126 by Rican7 (2013-07-31 23:28:40+00:00)
Title: Feature - "Matched" as Route Collection

While discussing and researching a bug realized in #124, I noticed that the old [`$matched`][matched] variable in the [`dispatch()`][dispatch] process was still just a basic integer. While working as expected, I thought it would be much more convenient to instead have the `$matched` variable be an instance of a [`RouteCollection`][route-collection], so that a developer could later on check what [`Route`][route] objects were in the collection of matched routes and even get the matched routes meta.

Does this make sense as a feature?

Also, for dependency injection's sake, I made the `$matched` [an empty **clone**][matched-clone] of the injected `RouteCollection` class, in case a developer wanted to extend and inject their own version. This way, instead of using the `new` keyword to create a `RouteCollection`, the developer gets to inject their own extension and they get it in both places. I think that's the best way of going about it. Otherwise, we'd have to make ANOTHER argument on the `dispatch()` method, and the signature would get even more ugly.

[matched]: https://github.com/chriso/klein.php/blob/fc22fdbad9225ede913ed343b98f4469f21fc869/src/Klein/Klein.php#L392
[dispatch]: https://github.com/chriso/klein.php/blob/fc22fdbad9225ede913ed343b98f4469f21fc869/src/Klein/Klein.php#L369
[route-collection]: https://github.com/chriso/klein.php/blob/fc22fdbad9225ede913ed343b98f4469f21fc869/src/Klein/DataCollection/RouteCollection.php
[route]: https://github.com/chriso/klein.php/blob/fc22fdbad9225ede913ed343b98f4469f21fc869/src/Klein/Route.php
[matched-clone]: https://github.com/Rican7/klein.php/blob/2165f94643988ea1e968d17b889bd5b243abc523/src/Klein/Klein.php#L392