-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Klein v2 #92
Klein v2 #92
Conversation
This was done quickly, naively, and dangerously. (lots of copy-pasta)
In fact, removed the old klein library from our tests to make sure everything's running well! And it works!!!!!!
Conflicts: tests/ResponsesTest.php tests/RoutesTest.php
…at the start of each test. That should make for less copy-pasta/boilerplate for tests.
passing of a flag that will allow/disallow duplicate error callbacks
"auto-instance" of Klein for quick and easy testing. :)
- Now using a phpunit.xml.dist - Now PHPDoc'ing the test classes - Namespacing the test classes
The new Klein classes effectively replace it now. :)
Using the phpunit installed with "composer install --dev" is now suggested. After installation, simply run "./vendor/bin/phpunit"
(most tests are designed so that they don't expect any Header output, hence the NoOp)
It does feel a little dirty
where they really do belong
ServiceProvider class method moving
that a response is unlocked before modifying it
exceptions on a locked response object Updated tests to reflect changes
a response that's already been sent Also, a new method for checking if a response has already been sent or not
"get()", "post()", "put()", and "delete()"
Very nice looking. Just a few thoughts: instead of nested try catch blocks you can do: try {
// do something
} catch(LockedResponseException $e) {
// do nothing
} catch(Exception $e) {
$this->error($e);
} or possibly try {
// do something
} catch(Exception $e) {
switch(gettype($e)) {
case 'LockedResponseException': break;
default: $this->error($e);
}
} or even in Add support for PHP 5.4 function http_response_code and let the engine intelligently handle sending the response code, and then fall back to I had some notion about abstracting the concept of a locked response out of the response class itself, and using some kind of read-only variable class that threw exceptions on The prepend method can be shortened to:
Though that's only really stylistic. Also not certain about And also an early bird feature request, in the validators, add a Last thing I can see right now: Since it can only be got once per request, maybe make the variable static, so even if there are multiple instances of Thanks for your work It is quite well formatted and easy to understand code. |
@kafene Thanks for the suggestions!
Thanks for your comments and compliments! They're greatly appreciated! Thank you so much! |
So, what do you think @chriso? |
Hey Trevor, All good. I still think that the Request / Response instances should be injected in the constructor but we can talk about that post-merge. Again, thanks for all the work you've done. Merging now.. |
Woot! Thanks! This has been a long time coming! :) Yea, we can definitely hash out the details through separate issues/pull-requests, instead of having this giant thread. Thank you SO much! I'm honored to have been able to contribute to this project! 👍 |
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 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. 👅 Merging this code into master isn't nearly as scary of an idea now that we have well tagged versions. And after a merge, the code can be tagged as a major version (2.0.0), so that dependency managers won't automatically update!