{"action":"created","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/2785","repository_url":"https://api.github.com/repos/slimphp/Slim","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/2785/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/2785/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/2785/events","html_url":"https://github.com/slimphp/Slim/issues/2785","id":478591747,"node_id":"MDU6SXNzdWU0Nzg1OTE3NDc=","number":2785,"title":"4.x - MiddlewareDispatcherInterface","user":{"login":"l0gicgate","id":6510935,"node_id":"MDQ6VXNlcjY1MTA5MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/6510935?v=4","gravatar_id":"","url":"https://api.github.com/users/l0gicgate","html_url":"https://github.com/l0gicgate","followers_url":"https://api.github.com/users/l0gicgate/followers","following_url":"https://api.github.com/users/l0gicgate/following{/other_user}","gists_url":"https://api.github.com/users/l0gicgate/gists{/gist_id}","starred_url":"https://api.github.com/users/l0gicgate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/l0gicgate/subscriptions","organizations_url":"https://api.github.com/users/l0gicgate/orgs","repos_url":"https://api.github.com/users/l0gicgate/repos","events_url":"https://api.github.com/users/l0gicgate/events{/privacy}","received_events_url":"https://api.github.com/users/l0gicgate/received_events","type":"User","site_admin":false},"labels":[{"id":372378249,"node_id":"MDU6TGFiZWwzNzIzNzgyNDk=","url":"https://api.github.com/repos/slimphp/Slim/labels/Slim%204","name":"Slim 4","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-08-08T17:11:09Z","updated_at":"2019-08-08T17:33:50Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"We will need to introduce a new interface in order to enable users to drop in their own `MiddlewareDispatcher`\r\n\r\nSince we won't be able to rely on the constructor, we need methods to set the following:\r\n- `add()` - Untyped method to add a `MiddlewareInterface`, a `string` for deferred callables or a `callable`\r\n- `addMiddleware()` - Typed method to add only `MiddlewareInterface` for people who enjoy stricter typed approaches\r\n- `setKernel()` Set the kernel or \"tip\" of the middleware stack\r\n- `setCallableResolver()` Set a `CallableResolver`, for resolving all middleware class names / callables. Currently we are injecting `ContainerInterface` inside of `MiddlewareDispatcher` and duplicating some of the logic from within `CallableResolver`. That needs to be changed once we modify `CallableResolver` to handle all that logic.\r\n\r\nHere is the proposed interface:\r\n```php\r\n<?php\r\ndeclare(strict_types=1);\r\n\r\nnamespace Slim\\Interfaces;\r\n\r\nuse Psr\\Container\\ContainerInterface;\r\nuse Psr\\Http\\Server\\MiddlewareInterface;\r\nuse Psr\\Http\\Server\\RequestHandlerInterface;\r\n\r\ninterface MiddlewareDispatcherInterface extends RequestHandlerInterface\r\n{\r\n    /**\r\n     * Add a new middleware to the stack\r\n     *\r\n     * Middleware are organized as a stack. That means middleware\r\n     * that have been added before will be executed after the newly\r\n     * added one (last in, first out).\r\n     *\r\n     * @param MiddlewareInterface|string|callable $middleware\r\n     * @return self\r\n     */\r\n    public function add($middleware): self;\r\n\r\n    /**\r\n     * Add a new middleware to the stack\r\n     *\r\n     * Middleware are organized as a stack. That means middleware\r\n     * that have been added before will be executed after the newly\r\n     * added one (last in, first out).\r\n     *\r\n     * @param MiddlewareInterface $middleware\r\n     * @return self\r\n     */\r\n    public function addMiddleware(MiddlewareInterface $middleware): self;\r\n\r\n    /**\r\n     * @param RequestHandlerInterface $kernel\r\n     * @return MiddlewareDispatcherInterface\r\n     */\r\n    public function setKernel(RequestHandlerInterface $kernel): self;\r\n\r\n    /**\r\n     * @param CallableResolverInterface $callableResolver\r\n     * @return self\r\n     */\r\n    public function setCallableResolver(CallableResolverInterface $callableResolver): self;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/slimphp/Slim/issues/comments/519615837","html_url":"https://github.com/slimphp/Slim/issues/2785#issuecomment-519615837","issue_url":"https://api.github.com/repos/slimphp/Slim/issues/2785","id":519615837,"node_id":"MDEyOklzc3VlQ29tbWVudDUxOTYxNTgzNw==","user":{"login":"shadowhand","id":38203,"node_id":"MDQ6VXNlcjM4MjAz","avatar_url":"https://avatars3.githubusercontent.com/u/38203?v=4","gravatar_id":"","url":"https://api.github.com/users/shadowhand","html_url":"https://github.com/shadowhand","followers_url":"https://api.github.com/users/shadowhand/followers","following_url":"https://api.github.com/users/shadowhand/following{/other_user}","gists_url":"https://api.github.com/users/shadowhand/gists{/gist_id}","starred_url":"https://api.github.com/users/shadowhand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shadowhand/subscriptions","organizations_url":"https://api.github.com/users/shadowhand/orgs","repos_url":"https://api.github.com/users/shadowhand/repos","events_url":"https://api.github.com/users/shadowhand/events{/privacy}","received_events_url":"https://api.github.com/users/shadowhand/received_events","type":"User","site_admin":false},"created_at":"2019-08-08T17:33:50Z","updated_at":"2019-08-08T17:33:50Z","author_association":"CONTRIBUTOR","body":"I can't help but feel like all of this would be easier with two factories for deferred and callable middleware:\r\n\r\n```php\r\n$callableMiddleware = new CallableMiddlewareFactory($callableResolver);\r\n// This creates a CallableMiddleware instance around $callable that will\r\n// be resolved using the $callableResolver when invoked.\r\n$middleware = $callableMiddleware->create($callable);\r\nassert($middleware instanceof MiddlewareInterface);\r\n\r\n$containerMiddleware = new ContainerMiddlewareFactory($container);\r\n// This creates a ContainerMiddleware instance around $identifier that will\r\n// be resolved using the $container when invoked.\r\n$middleware = $containerFactory->create($identifier);\r\nassert($middleware instanceof MiddlewareInterface);\r\n```"}}
{"actor":{"display_login":"shadowhand"}}