{"id":20887626,"url":"https://github.com/opsway/slim-attribute-router","last_synced_at":"2026-04-20T23:32:04.248Z","repository":{"id":62549862,"uuid":"486214439","full_name":"opsway/slim-attribute-router","owner":"opsway","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-05T09:27:34.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-30T07:31:09.685Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opsway.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}},"created_at":"2022-04-27T13:57:01.000Z","updated_at":"2023-09-22T23:21:33.000Z","dependencies_parsed_at":"2022-11-03T01:15:50.737Z","dependency_job_id":null,"html_url":"https://github.com/opsway/slim-attribute-router","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/opsway/slim-attribute-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fslim-attribute-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fslim-attribute-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fslim-attribute-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fslim-attribute-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opsway","download_url":"https://codeload.github.com/opsway/slim-attribute-router/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fslim-attribute-router/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32070628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T21:26:33.338Z","status":"ssl_error","status_checked_at":"2026-04-20T21:26:22.081Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":"2024-11-18T08:21:27.966Z","updated_at":"2026-04-20T23:32:04.228Z","avatar_url":"https://github.com/opsway.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slim-attribute-router\nSlim attribute router\n\nThis package allows you to add routes to your slim4 (https://www.slimframework.com) application using attributes.\n\n### Features\n* Route methods support\n* Route name support\n* Route group support\n* Middlewares support\n\n## Installation\nThis package can be installed using Composer  \nNavigate into your project's root directory and execute the bash command shown below\n```bash\ncomposer require opsway/slim-attribute-router\n```\n\n## Enabling the Attribute Router\nAttribute router extends slims default RouteCollector, all you need to do is instantiate attribute router and pass\nit on to AppFactory. First parameter is array of namespace parts of app. It will be used for filtering classes in which \nsearch of parameters will go on.\n\n```php\n\u003c?php\nuse OpsWay\\Slim\\AttributeRouter\\Router;\nuse Slim\\Factory\\AppFactory;\n$route = new Router([\n    ['NameSpace'], // array of namespaces parts of app \n\tAppFactory::determineResponseFactory(),\n\tnew CallableResolver($container) // optional DI container\n);\nAppFactory::setRouteCollector($attributeRouteCollector);\n$app = AppFactory::create();\n$app-\u003erun();\n```\n\n## Attribute signature\n**#[Route({methods}, {path}[[, {group}][, {name}][, {isDeprecated}]])]**\n\n| Parameter      | Example              | Description                               |\n|----------------|----------------------|-------------------------------------------|\n| {methods}      | ['GET', 'POST']      | (array)  The allowed HTTP request methods |\n| {path}         | '/hello/{parameter}' | (string) The route pattern                |\n| {group}        | 'group'              | (string) The group name                   |\n| {name}         | 'route.Name'         | (string) The name of the route            |\n| {isDeprecated} | 'false'              | (bool) Flag if route is deprecated        |\n\n* The \"methods\" parameter is required and must be not empty\n* The \"path\" parameter is required and must be not empty\n* Rest of parameters are optional\n\n**#[Group({name} [[, {classes}]])]**\n\n| Parameter | Example               | Description                     |\n|-----------|-----------------------|---------------------------------|\n| {name}    | '/api'                | (string) The group name         |\n| {classes} | ['Middleware::class'] | (array) Middlewares class names |\n\n* The \"name\" parameter is required and must be compatible with URI string requirements\n* The \"classes\" parameter is optional. List of classes implementing Psr\\Http\\Server\\MiddlewareInterface\n\n**#[Middlewares({firstClass} [, {secondClass}])]**\n\n| Parameter    | Example               | Description                    |\n|--------------|-----------------------|--------------------------------|\n| {firstClass} | ['Middleware::class'] | (string) Middleware class name |\n\n* The \"firstClass\" parameter is required and must class name of class that implements Psr\\Http\\Server\\MiddlewareInterface\n* The \"secondClass\" and all other parameters is optional.\n* All arguments of constructor are converted to an array of middleware classes. It should be at least one middleware class\n\n## Specifying attributes examples\n\nExample specifying route with name and group parameters at class level\n```php\n\u003c?php\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\n\n#[Route([Route::METHOD_GET], '/api/hello-world', '/hello-world-group', 'api.hello-world.route-name')]\nclass HelloWorld\n{\n    public function __invoke(Request $request, Response $response): Response\n    {\n        // some php code\n        return $response;\n    }\n}\n```\n\nExample specifying route without additional parameters at method level\n```php\n\u003c?php\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\n\nclass HelloWorld\n{\n    #[Route([Route::METHOD_GET], '/api/hello-world')]\n    public function __invoke(Request $request, Response $response): Response\n    {\n        // some php code\n        return $response;\n    }\n}\n```\n\nExample specifying group with middlewares at class level\n```php\n\u003c?php\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\n\n#[Group('/api', [FirstMidleware::class, SecondMidleware::class])]\nclass HelloWorld\n{\n    public function __invoke(Request $request, Response $response): Response\n    {\n        // some php code\n        return $response;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopsway%2Fslim-attribute-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopsway%2Fslim-attribute-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopsway%2Fslim-attribute-router/lists"}