{"action":"created","issue":{"url":"https://api.github.com/repos/bcosca/fatfree-core/issues/257","repository_url":"https://api.github.com/repos/bcosca/fatfree-core","labels_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/257/labels{/name}","comments_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/257/comments","events_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/257/events","html_url":"https://github.com/bcosca/fatfree-core/pull/257","id":360538575,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE1NzY4Mzcx","number":257,"title":"Fix OPTIONS method for REST requests, now returning only callable methods on handler","user":{"login":"nanawel","id":4866761,"node_id":"MDQ6VXNlcjQ4NjY3NjE=","avatar_url":"https://avatars3.githubusercontent.com/u/4866761?v=4","gravatar_id":"","url":"https://api.github.com/users/nanawel","html_url":"https://github.com/nanawel","followers_url":"https://api.github.com/users/nanawel/followers","following_url":"https://api.github.com/users/nanawel/following{/other_user}","gists_url":"https://api.github.com/users/nanawel/gists{/gist_id}","starred_url":"https://api.github.com/users/nanawel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nanawel/subscriptions","organizations_url":"https://api.github.com/users/nanawel/orgs","repos_url":"https://api.github.com/users/nanawel/repos","events_url":"https://api.github.com/users/nanawel/events{/privacy}","received_events_url":"https://api.github.com/users/nanawel/received_events","type":"User","site_admin":false},"labels":[{"id":145574248,"node_id":"MDU6TGFiZWwxNDU1NzQyNDg=","url":"https://api.github.com/repos/bcosca/fatfree-core/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":{"login":"bcosca","id":199570,"node_id":"MDQ6VXNlcjE5OTU3MA==","avatar_url":"https://avatars2.githubusercontent.com/u/199570?v=4","gravatar_id":"","url":"https://api.github.com/users/bcosca","html_url":"https://github.com/bcosca","followers_url":"https://api.github.com/users/bcosca/followers","following_url":"https://api.github.com/users/bcosca/following{/other_user}","gists_url":"https://api.github.com/users/bcosca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcosca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcosca/subscriptions","organizations_url":"https://api.github.com/users/bcosca/orgs","repos_url":"https://api.github.com/users/bcosca/repos","events_url":"https://api.github.com/users/bcosca/events{/privacy}","received_events_url":"https://api.github.com/users/bcosca/received_events","type":"User","site_admin":false},"assignees":[{"login":"bcosca","id":199570,"node_id":"MDQ6VXNlcjE5OTU3MA==","avatar_url":"https://avatars2.githubusercontent.com/u/199570?v=4","gravatar_id":"","url":"https://api.github.com/users/bcosca","html_url":"https://github.com/bcosca","followers_url":"https://api.github.com/users/bcosca/followers","following_url":"https://api.github.com/users/bcosca/following{/other_user}","gists_url":"https://api.github.com/users/bcosca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcosca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcosca/subscriptions","organizations_url":"https://api.github.com/users/bcosca/orgs","repos_url":"https://api.github.com/users/bcosca/repos","events_url":"https://api.github.com/users/bcosca/events{/privacy}","received_events_url":"https://api.github.com/users/bcosca/received_events","type":"User","site_admin":false}],"milestone":null,"comments":10,"created_at":"2018-09-15T13:06:55Z","updated_at":"2018-09-20T15:33:09Z","closed_at":"2018-09-20T12:01:20Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/bcosca/fatfree-core/pulls/257","html_url":"https://github.com/bcosca/fatfree-core/pull/257","diff_url":"https://github.com/bcosca/fatfree-core/pull/257.diff","patch_url":"https://github.com/bcosca/fatfree-core/pull/257.patch"},"body":"I'm proposing this PR to fix what seems to be a bug in the REST method mapping process.\r\n\r\nWith the given example in the [documentation](https://fatfreeframework.com/3.6/routing-engine#ReST:RepresentationalStateTransfer):\r\n```php\r\nclass Item {\r\n    function get() {}\r\n    function post() {}\r\n    function put() {}\r\n    function delete() {}\r\n}\r\n\r\n$f3=require('lib/base.php');\r\n$f3->map('/cart/@item','Item');\r\n$f3->run();\r\n```\r\n\r\nwe have the following behavior:\r\n\r\n- calling GET on `/cart` will result in HTTP status 200 with empty body :heavy_check_mark: \r\n- calling PATCH on `/cart` will result in HTTP status 405 with empty body and the `Allow` header set to `POST,PUT,DELETE,OPTIONS` :heavy_check_mark: \r\n- calling OPTIONS `/cart` will result in HTTP status 200 with empty body and the `Allow` header set to `GET,HEAD,POST,PUT,PATCH,DELETE,CONNECT,OPTIONS` while obviously not all these methods are supported by the handler here :x:\r\n\r\nThat's because the `\\Base::map()` method creates routes for all `\\Base::VERBS` when called, while it should only do for methods that are _callable_ on the handler.\r\n\r\nWith my PR, calling OPTIONS `/cart` will result in HTTP status 200 with empty body and the `Allow` header set to `POST,PUT,DELETE,OPTIONS` as it should.\r\n\r\nBe aware that I prefered using `is_callable()` instead of `method_exists()` because one may want to define a `__call()` method on the handler. In that case, the PR is useless as all methods will be detected as callable because of the catch-all `__call` method."},"comment":{"url":"https://api.github.com/repos/bcosca/fatfree-core/issues/comments/423228685","html_url":"https://github.com/bcosca/fatfree-core/pull/257#issuecomment-423228685","issue_url":"https://api.github.com/repos/bcosca/fatfree-core/issues/257","id":423228685,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzIyODY4NQ==","user":{"login":"bcosca","id":199570,"node_id":"MDQ6VXNlcjE5OTU3MA==","avatar_url":"https://avatars2.githubusercontent.com/u/199570?v=4","gravatar_id":"","url":"https://api.github.com/users/bcosca","html_url":"https://github.com/bcosca","followers_url":"https://api.github.com/users/bcosca/followers","following_url":"https://api.github.com/users/bcosca/following{/other_user}","gists_url":"https://api.github.com/users/bcosca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcosca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcosca/subscriptions","organizations_url":"https://api.github.com/users/bcosca/orgs","repos_url":"https://api.github.com/users/bcosca/repos","events_url":"https://api.github.com/users/bcosca/events{/privacy}","received_events_url":"https://api.github.com/users/bcosca/received_events","type":"User","site_admin":false},"created_at":"2018-09-20T15:33:09Z","updated_at":"2018-09-20T15:33:09Z","author_association":"OWNER","body":"There now. Sorry about that."}}
{"actor":{"display_login":"bcosca"}}