{"action":"created","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/1112","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/1112/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/1112/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/1112/events","html_url":"https://github.com/slimphp/Slim/pull/1112","id":62825653,"number":1112,"title":"DIC-aware route middleware","user":{"login":"akrabat","id":33135,"avatar_url":"https://avatars.githubusercontent.com/u/33135?v=3","gravatar_id":"","url":"https://api.github.com/users/akrabat","html_url":"https://github.com/akrabat","followers_url":"https://api.github.com/users/akrabat/followers","following_url":"https://api.github.com/users/akrabat/following{/other_user}","gists_url":"https://api.github.com/users/akrabat/gists{/gist_id}","starred_url":"https://api.github.com/users/akrabat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akrabat/subscriptions","organizations_url":"https://api.github.com/users/akrabat/orgs","repos_url":"https://api.github.com/users/akrabat/repos","events_url":"https://api.github.com/users/akrabat/events{/privacy}","received_events_url":"https://api.github.com/users/akrabat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-03-18T23:17:00Z","updated_at":"2015-03-19T09:39:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/slimphp/Slim/pulls/1112","html_url":"https://github.com/slimphp/Slim/pull/1112","diff_url":"https://github.com/slimphp/Slim/pull/1112.diff","patch_url":"https://github.com/slimphp/Slim/pull/1112.patch"},"body":"This PR resolves #1014: \"Using 'Class:method' as a route middleware\" which means that it supports:\r\n\r\n```php\r\n$app->get(\r\n    '/',\r\n    function($request, $response) {\r\n        echo \"<p>Hello world</p>\";\r\n    }\r\n)\r\n->add('ClassRouteMiddleware:run');\r\n```\r\n\r\nThis is more invasive than I expected as  `$app->map()` now returns a `Route` with which we use `add()` in order to add middleware to the route.\r\n\r\nHowever, the Route object doesn't know about the DI container and its  `add()` method comes from the `MiddlewareAware` trait which has a signature that is type hinted to `callable`. Also, the `Route` object is  directly instantiated by the `Router` object in `Router::map`.\r\n\r\nAs a result, I've created a `ResolveCallable` trait that is used by both `App` and `Route` and modified `Route` to use it. I also decided to make the `Route` object `Container`-aware, but injected the container via a setter so that I didn't need to change the Router class. The `resolveCallable()` method checks that the container has been set if you try to use the 'class:method' string and throws a runtime exception if it doesn't have a valid container.\r\n\r\nI'm mostly concerned about the `testAddMiddlewareAsString` test as it seems more of an integration than unit test, but I couldn't work out how else to test. If there's a better way to do it, then it should be changed!"},"comment":{"url":"https://api.github.com/repos/slimphp/Slim/issues/comments/83446803","html_url":"https://github.com/slimphp/Slim/pull/1112#issuecomment-83446803","issue_url":"https://api.github.com/repos/slimphp/Slim/issues/1112","id":83446803,"user":{"login":"akrabat","id":33135,"avatar_url":"https://avatars.githubusercontent.com/u/33135?v=3","gravatar_id":"","url":"https://api.github.com/users/akrabat","html_url":"https://github.com/akrabat","followers_url":"https://api.github.com/users/akrabat/followers","following_url":"https://api.github.com/users/akrabat/following{/other_user}","gists_url":"https://api.github.com/users/akrabat/gists{/gist_id}","starred_url":"https://api.github.com/users/akrabat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akrabat/subscriptions","organizations_url":"https://api.github.com/users/akrabat/orgs","repos_url":"https://api.github.com/users/akrabat/repos","events_url":"https://api.github.com/users/akrabat/events{/privacy}","received_events_url":"https://api.github.com/users/akrabat/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T09:39:35Z","updated_at":"2015-03-19T09:39:35Z","body":"Yeah, I figured that the MiddlewareAware trait didn't really care how the callable came to be, so I separated it."}}