Respect / Rest

Thin controller for RESTful applications
http://respect.github.io/Rest
Other
605 stars 102 forks source link

Update ClassName.php #108

Closed migolo closed 10 years ago

migolo commented 10 years ago

Error when calling an HTTP method that doesn't exists in the instance of the class. It is called a 'nonimplemented' method of the class.

nickl- commented 10 years ago

@migolo I am not following. You called my notfollowing method which caused a What the!?! exception on PR 108# at comment 1. =)

Is there documentation for this 'notimplemented' method you are referring to or do we have it implemented somewhere that I don't know of? If not and you want an error on notimplemented method doesn't exist then why is this better than excepting out on the actual "not implemented" method supplied?

Please advise and in advance excuse my ignorance...

migolo commented 10 years ago

Sorry @nickl- , I got an error when I called an HTTP method without defining it in the class, for example:

class MyArticle implements Routable { public function get($id) { echo "GET:".$id; } public function delete($id) { echo "DELETE:".$id; } } $r3->any('/article/*', 'MyArticle');

If I call this with an HTTP Method POST i get an not catchable Exception, with this patch I was able to redirect the response to a method called 'notimplemented'.

First I tried to throw a InvalidArgumentException but the 'runTarget' method expected a String not an Exception, so I defined the 'nonimplemented' method as an alternative, but I think there should be something else that handles that exception.

nickl- commented 10 years ago

@migolo but why doesn't the method exist? Are you dynamically generating the callback or something.

We can't handle the exception as there is nowhere we can go from there if it doesn't exist. For the same reason it is best that we report back which method doesn't exist because this is an implementation fault and needs to be rectified so we should provide as much information as possible for you to identify the issue not try and avoid it.

I don't agree that this is a good idea, as mentioned previously it obfuscates the reason for the error and since I don't have a 'notimplemented' method I'll be cursing from here till tomorrow if it happened to me. Did you try a register error handler? Have a look at this post on SO It covers even deliberate program aborts and I am sure you will be able to catch this too.

Let us know...

Closed as won't implement...

migolo commented 10 years ago

Oh, Sorry I didn't catch the message, the original class was modified and It depends on the user to implement this method:

class MyArticle implements Routable { public function get($id) { echo "GET:".$id; } public function delete($id) { echo "DELETE:".$id; }

public function notimplemented($id) { echo "Sorry, this method is not implemented."; } }

But as you said it is not a good idea, the error should be catcheable in other way.

Thanks for the information @nickl-

Its a nice project!