{"action":"closed","issue":{"url":"https://api.github.com/repos/zendframework/zend-expressive/issues/312","repository_url":"https://api.github.com/repos/zendframework/zend-expressive","labels_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/312/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/312/comments","events_url":"https://api.github.com/repos/zendframework/zend-expressive/issues/312/events","html_url":"https://github.com/zendframework/zend-expressive/issues/312","id":131432169,"number":312,"title":"Custom dispatch middleware, default route middleware, and route attributes","user":{"login":"glen-84","id":261509,"avatar_url":"https://avatars.githubusercontent.com/u/261509?v=3","gravatar_id":"","url":"https://api.github.com/users/glen-84","html_url":"https://github.com/glen-84","followers_url":"https://api.github.com/users/glen-84/followers","following_url":"https://api.github.com/users/glen-84/following{/other_user}","gists_url":"https://api.github.com/users/glen-84/gists{/gist_id}","starred_url":"https://api.github.com/users/glen-84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glen-84/subscriptions","organizations_url":"https://api.github.com/users/glen-84/orgs","repos_url":"https://api.github.com/users/glen-84/repos","events_url":"https://api.github.com/users/glen-84/events{/privacy}","received_events_url":"https://api.github.com/users/glen-84/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-02-04T18:23:59Z","updated_at":"2016-12-07T19:10:47Z","closed_at":"2016-12-07T19:10:47Z","body":"I created a [BaseControllerTrait](http://pastie.org/private/hutorg7doqvlicwmwqpw), and I was wondering whether to instead extend a base class, so I went onto `##php` to ask for opinions. The feedback was a bit mixed, but a somewhat-unrelated suggestion was made that I move the `__invoke` code (dispatch & automatic template rendering) to a separate middleware class. This makes sense to me, but I'm a bit unsure as to how to accomplish it.\n\nI was thinking of something along these lines:\n\n``` php\n    'routes' => [\n        [\n            'name' => 'app.site',\n            'path' => '/[{action}]',\n            'middleware' => My\\Dispatch\\Middleware::class,\n            'allowed_methods' => ['GET']\n        ]\n    ]\n```\n\nHowever:\n\n`1.` If the controller is not part of the route, how do I send that information to the dispatch middleware? I thought that maybe an `attributes` key could be added to the route interface, so you'd do:\n\n``` php\n    'routes' => [\n        [\n            'name' => 'app.site',\n            'path' => '/[{action}]',\n            'middleware' => My\\Dispatch\\Middleware::class,\n            'allowed_methods' => ['GET'],\n            'attributes' => [\n                'controller' => My\\Controller\\Class::class,\n                'somethingElseLikeADefaultAction' => '...'\n            ]\n        ]\n```\n\nWhich would then be available via the request.\n\n`2.` Specifying the same middleware over and over could get annoying, so it would be nice if you could specify default middleware to use if the route doesn't specify any.\n\n `3.` I'm not sure how this relates to `ApplicationFactory::DISPATCH_MIDDLEWARE`? Does it replace it, come before/after it, etc.\n\nThis is just an idea – I wanted to get feedback in case I was thinking of doing something silly when there may be better options.\n\nYour thoughts?\n"}}
{"actor":{"display_login":"weierophinney"}}