{"id":43845503,"url":"https://github.com/xtompie/middleware","last_synced_at":"2026-02-06T05:37:05.395Z","repository":{"id":57085200,"uuid":"438726579","full_name":"xtompie/middleware","owner":"xtompie","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-15T19:40:57.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-15T22:16:11.817Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtompie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-15T18:05:36.000Z","updated_at":"2021-12-15T19:40:59.000Z","dependencies_parsed_at":"2022-08-25T00:50:24.279Z","dependency_job_id":null,"html_url":"https://github.com/xtompie/middleware","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xtompie/middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fmiddleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fmiddleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fmiddleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fmiddleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtompie","download_url":"https://codeload.github.com/xtompie/middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fmiddleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29152427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T02:39:25.012Z","status":"ssl_error","status_checked_at":"2026-02-06T02:37:22.784Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-06T05:37:03.644Z","updated_at":"2026-02-06T05:37:05.389Z","avatar_url":"https://github.com/xtompie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Middleware\n\nMiddleware component\n\n## Requiments\n\nPHP \u003e= 8.0\n\n## Installation\n\nUsing [composer](https://getcomposer.org/)\n\n```\ncomposer require xtompie/middleware\n```\n\n## Docs\n\nOne middleware is a callble `fn(mixed $input, $next): mixed`\n\n### Private service middleware\n\nService without middleware:\n\n```php\n\u003c?php\n\nuse Xtompie\\Middleware\\Middleware;\n\nclass TopArticlesService\n{\n    public function __construct(\n        protected DAO $dao,\n    ) {}\n\n    public function __invoke(int $limit, int $offset): ArticleCollection\n    {\n        return $this-\u003edao-\u003equery([\n            \"select\" =\u003e \"*\", \"from\" =\u003e \"article\", \"order\" =\u003e \"top DESC\"\n            \"offset\" =\u003e $offset, \"limit\" =\u003e $limit\n        ])\n            -\u003emapInto(Article::class)\n            -\u003epipeInto(ArticleCollection::class);\n        }\n    }\n}\n```\n\nService with middleware\n```php\n\u003c?php\n\nuse Xtompie\\Middleware\\Middleware;\n\nclass TopArticlesService\n{\n    public function __construct(\n        protected DAO $dao,\n        protected InMemoryCacheMiddleware $cache,\n        protected LoggerMiddleware $logger,\n    ) {}\n\n    public function __invoke(int $limit, int $offset): ArticleCollection\n    {\n        return Middleware::dispatch(\n            [\n                $this-\u003ecache,\n                $this-\u003elogger,\n                fn ($args) =\u003e return $this-\u003einvoke(...$args)\n            ],\n            func_get_args()\n        )\n    }\n\n    protected function invoke(int $limit, int $offset): ArticleCollection\n    {\n        return $this-\u003edao-\u003equery([\n            \"select\" =\u003e \"*\", \"from\" =\u003e \"article\", \"order\" =\u003e \"top DESC\"\n            \"offset\" =\u003e $offset, \"limit\" =\u003e $limit\n        ])\n            -\u003emapInto(Article::class)\n            -\u003epipeInto(ArticleCollection::class);\n        }\n    }\n}\n\n```\n\nor with cached middleware chain\n```php\n\u003c?php\n\nuse Xtompie\\Middleware\\Middleware;\n\nclass TopArticlesService\n{\n    public function __construct(\n        protected DAO $dao,\n        protected InMemoryCacheMiddleware $cache,\n        protected LoggerMiddleware $logger,\n        protected Middleware $middleware,\n    ) {\n        $this-\u003emiddleware = $middleware-\u003ewithMiddlewares([\n            $this-\u003ecache,\n            $this-\u003elogger,\n            fn ($args) =\u003e return $this-\u003einvoke(...$args)\n        ])\n    }\n\n    public function __invoke(int $limit, int $offset): ArticleCollection\n    {\n        return ($this-\u003emiddleware)(func_get_args());\n    }\n\n    protected function invoke(int $limit, int $offset): ArticleCollection\n    {\n        return $this-\u003edao-\u003equery([\n            \"select\" =\u003e \"*\", \"from\" =\u003e \"article\", \"order\" =\u003e \"top DESC\"\n            \"offset\" =\u003e $offset, \"limit\" =\u003e $limit\n        ])\n            -\u003emapInto(Article::class)\n            -\u003epipeInto(ArticleCollection::class);\n        }\n    }\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtompie%2Fmiddleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtompie%2Fmiddleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtompie%2Fmiddleware/lists"}