{"id":21467412,"url":"https://github.com/elusivecodes/fyremiddleware","last_synced_at":"2025-07-15T05:31:30.967Z","repository":{"id":62508435,"uuid":"443985931","full_name":"elusivecodes/FyreMiddleware","owner":"elusivecodes","description":"FyreMiddleware is a free, open-source middleware library for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-10T01:14:40.000Z","size":175,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-10T02:19:30.528Z","etag":null,"topics":["middleware","php","queue"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elusivecodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-03T08:13:03.000Z","updated_at":"2024-11-10T01:14:15.000Z","dependencies_parsed_at":"2024-10-19T16:37:01.959Z","dependency_job_id":null,"html_url":"https://github.com/elusivecodes/FyreMiddleware","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreMiddleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreMiddleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreMiddleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreMiddleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreMiddleware/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017473,"owners_count":17560519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["middleware","php","queue"],"created_at":"2024-11-23T08:17:54.615Z","updated_at":"2024-11-23T08:17:55.628Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreMiddleware\r\n\r\n**FyreMiddleware** is a free, open-source middleware library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Middleware Queues](#middleware-queues)\r\n    - [Middleware](#middleware)\r\n- [Request Handlers](#request-handlers)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/middleware\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Middleware\\MiddlewareRegistry;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$middlewareRegistry = new MiddlewareRegistry($container);\r\n```\r\n\r\nIt is recommended to bind the *MiddlewareRegistry* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(MiddlewareRegistry::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$middlewareRegistry = $container-\u003euse(MiddlewareRegistry::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Clear**\r\n\r\nClear all aliases and middleware.\r\n\r\n```php\r\n$middlewareRegistry-\u003eclear();\r\n```\r\n\r\n**Map**\r\n\r\nMap an alias to middleware.\r\n\r\n- `$alias` is a string representing the middleware alias.\r\n- `$middleware` is a string representing the [*Middleware*](#middleware) class name, or a closure that returns an instance of a [*Middleware*](middleware) class.\r\n- `$arguments` is an array containing additional arguments for creating the [*Middleware*](#middleware), and will default to *[]*.\r\n\r\n```php\r\n$middlewareRegistry-\u003emap($alias, $middleware, $arguments);\r\n```\r\n\r\n**Resolve**\r\n\r\nResolve [*Middleware*](#middleware).\r\n\r\n- `$middleware` is a [*Middleware*](#middleware) class instance, class name, alias or *Closure*.\r\n\r\n```php\r\n$resolvedMiddleware = $middlewareRegistry-\u003eresolve($middleware);\r\n```\r\n\r\nYou can pass additional arguments to the `handle` method of the [*Middleware*](#middleware) by appending a colon followed by a comma-separated list of arguments to the string.\r\n\r\n```php\r\n$middlewareRegistry-\u003eresolve('alias:arg1,arg2');\r\n```\r\n\r\n[*Middleware*](#middleware) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n**Use**\r\n\r\nLoad a shared [*Middleware*](#middleware) instance.\r\n\r\n- `$alias` is a string representing the middleware alias.\r\n\r\n```php\r\n$middleware = $middlewareRegistry-\u003euse($alias);\r\n```\r\n\r\n[*Middleware*](#middleware) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n\r\n## Middleware Queues\r\n\r\n```php\r\nuse Fyre\\Middleware\\MiddlewareQueue;\r\n```\r\n\r\n- `$middlewares` is an array containing the [*Middleware*](#middleware).\r\n\r\n```php\r\n$queue = new MiddlewareQueue($middlewares);\r\n```\r\n\r\n**Add**\r\n\r\nAdd [*Middleware*](#middleware).\r\n\r\n- `$middleware` is a [*Middleware*](#middleware) class instance, class name name, alias or [*Closure*](#closures).\r\n\r\n```php\r\n$queue-\u003eadd($middleware);\r\n```\r\n\r\n**Count**\r\n\r\nGet the [*Middleware*](#middleware) count.\r\n\r\n```php\r\n$count = $queue-\u003ecount();\r\n```\r\n\r\n**Current**\r\n\r\nGet the [*Middleware*](#middleware) at the current index.\r\n\r\n```php\r\n$middleware = $queue-\u003ecurrent();\r\n```\r\n\r\n**Insert At**\r\n\r\nInsert [*Middleware*](#middleware) at a specified index.\r\n\r\n- `$index` is a number representing the index.\r\n- `$middleware` is a [*Middleware*](#middleware) class instance, class name name, alias or [*Closure*](#closures).\r\n\r\n```php\r\n$queue-\u003einsertAt($index, $middleware);\r\n```\r\n\r\n**Key**\r\n\r\nGet the current index.\r\n\r\n```php\r\n$key = $queue-\u003ekey();\r\n```\r\n\r\n**Next**\r\n\r\nProgress the index.\r\n\r\n```php\r\n$queue-\u003enext();\r\n```\r\n\r\n**Prepend**\r\n\r\nPrepend [*Middleware*](#middleware).\r\n\r\n- `$middleware` is a [*Middleware*](#middleware) class instance, class name name, alias or [*Closure*](#closures).\r\n\r\n```php\r\n$queue-\u003eprepend($middleware);\r\n```\r\n\r\n**Rewind**\r\n\r\nReset the index.\r\n\r\n```php\r\n$queue-\u003erewind();\r\n```\r\n\r\n**Valid**\r\n\r\nDetermine whether the current index is valid.\r\n\r\n```php\r\n$valid = $queue-\u003evalid();\r\n```\r\n\r\n\r\n### Middleware\r\n\r\nCustom middleware can be created by extending `\\Fyre\\Middleware\\Middleware`, ensuring all below methods are implemented.\r\n\r\n**Handle**\r\n\r\nHandle a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).\r\n\r\n- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).\r\n- `$next` is a *Closure*.\r\n\r\n```php\r\n$response = $middleware-\u003ehandle($request, $next);\r\n```\r\n\r\nThis method should call the `$next` callback with the `$request`, to handle the next middleware in the queue, then return the [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).\r\n\r\n\r\n### Closures\r\n\r\nYou can also provide custom middleware as a simple *Closure*.\r\n\r\n```php\r\n$middleware = function(ServerRequest $request, Closure $next): ClientResponse {\r\n    return $next($request);\r\n};\r\n```\r\n\r\n\r\n## Request Handlers\r\n\r\n```php\r\nuse Fyre\\Middleware\\RequestHandler;\r\n```\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n- `$middlewareRegistry` is a [*MiddlewareRegistry*](#basic-usage).\r\n- `$queue` is a [*MiddlewareQueue*](#middleware-queues).\r\n- `$initialResponse` is a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses) to be used as the initial response, and will default to *null*.\r\n\r\n```php\r\n$handler = new RequestHandler($container, $middlewareRegistry, $queue, $initialResponse);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$handler = $container-\u003euse(RequestHandler::class, 'queue' =\u003e $queue);\r\n```\r\n\r\nIf the `$initialResponse` is set to *null*, a new [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses) will be created.\r\n\r\n**Handle**\r\n\r\nHandle the next middleware in the queue.\r\n\r\n- `$request` is a [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests).\r\n\r\n```php\r\n$response = $handler-\u003ehandle($request);\r\n```\r\n\r\nThis method will return a [*ClientResponse*](https://github.com/elusivecodes/FyreServer#client-responses).\r\n\r\nThe provided `$request` will be automatically set as the [*ServerRequest*](https://github.com/elusivecodes/FyreServer#server-requests) instance in the [*Container*](https://github.com/elusivecodes/FyreContainer).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyremiddleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyremiddleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyremiddleware/lists"}