{"id":23835180,"url":"https://github.com/yeremi/route-mapper","last_synced_at":"2026-02-12T00:35:23.335Z","repository":{"id":270598842,"uuid":"910565554","full_name":"yeremi/route-mapper","owner":"yeremi","description":"RouteMapper is a lightweight PHP library designed to leverage PHP 8 attributes to map and resolve API routes effortlessly.","archived":false,"fork":false,"pushed_at":"2026-01-27T09:04:57.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-27T21:02:57.981Z","etag":null,"topics":["attributes","mappings","php8","route"],"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/yeremi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["yeremi"],"patreon":"YeremiLoli","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2024-12-31T16:46:29.000Z","updated_at":"2026-01-27T09:05:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"5a63a4b2-bc65-49af-b1ee-2a46df072370","html_url":"https://github.com/yeremi/route-mapper","commit_stats":null,"previous_names":["yeremi/route-mapper"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yeremi/route-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeremi%2Froute-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeremi%2Froute-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeremi%2Froute-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeremi%2Froute-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeremi","download_url":"https://codeload.github.com/yeremi/route-mapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeremi%2Froute-mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29351055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T20:11:40.865Z","status":"ssl_error","status_checked_at":"2026-02-11T20:10:41.637Z","response_time":97,"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":["attributes","mappings","php8","route"],"created_at":"2025-01-02T15:27:25.002Z","updated_at":"2026-02-12T00:35:23.330Z","avatar_url":"https://github.com/yeremi.png","language":"PHP","funding_links":["https://github.com/sponsors/yeremi","https://patreon.com/YeremiLoli"],"categories":[],"sub_categories":[],"readme":"# RouteMapper\n\n![CI](https://github.com/yeremi/route-mapper/actions/workflows/php-qa.yml/badge.svg?branch=main)\n![PHP Version](https://img.shields.io/badge/php-%3E%3D8.0-blue)\n![License](https://img.shields.io/github/license/yeremi/route-mapper)\n![Latest Version](https://img.shields.io/packagist/v/yeremi/route-mapper)\n![Downloads](https://img.shields.io/packagist/dt/yeremi/route-mapper)\n\n**RouteMapper** is a lightweight, framework-agnostic PHP library that uses **PHP 8 attributes** to map and resolve API route paths defined via PHP attributes in a simple and explicit way.\n\nIt focuses on one responsibility only: **mapping routes to methods**, without imposing an HTTP framework or execution model.\n\n---\n\n## Design Philosophy\n\n- RouteMapper focuses on **one responsibility only**: mapping routes to methods.\n- It does **not** handle HTTP requests, middleware, controllers, or responses.\n- Integration is explicit by design — no magic containers or hidden behavior.\n- The library favors **clarity over convenience**.\n- If you need a full routing framework, RouteMapper is probably not the right tool.\n\n---\n\n## Key Features\n\n- **Attribute-Based Routing** using PHP 8 attributes\n- **Framework-Agnostic** (works with any HTTP client or framework)\n- **Lightweight \u0026 Focused** — no unnecessary abstractions\n- **Explicit Route Resolution** — no magic, full control\n- **Modern PHP** — strict typing and PHP 8 features\n\n---\n\n## Requirements\n\n- PHP 8.0 or higher\n\n---\n\n## Why Use RouteMapper?\n\nUse RouteMapper when you want to keep routing metadata close to your code (via attributes) and still remain framework-agnostic.\nIt works well for SDKs, API clients, small services, and projects that want explicit, testable route resolution without adopting a full stack.\n\n---\n\n## Installation\n\nInstall RouteMapper via Composer:\n\n```bash\ncomposer require yeremi/route-mapper\n```\n\n---\n\n## Example Usage\n\n\u003e Routes are resolved using the class name and method name.\n\n### Defining routes with attributes\n\n```php\nuse Yeremi\\RouteMapper\\Attribute\\ApiRoute;\nuse Yeremi\\RouteMapper\\Registry\\RouteRegistry;\nuse Yeremi\\RouteMapper\\Resolver\\RouteResolver;\n\n// (for this example): `composer require guzzlehttp/guzzle`\nuse GuzzleHttp\\Client; // Example only\n\nclass UserRepository\n{\n    public function __construct(\n        protected RouteRegistry $routeRegistry,\n        protected RouteResolver $routeResolver,\n        protected Client $httpClient\n    ) {\n        // Registers all #[ApiRoute] attributes in this class\n        $this-\u003erouteRegistry-\u003eregisterRoutes($this);\n    }\n\n    #[ApiRoute('/users')] // Defines only the route path\n    public function fetchAll(): void\n    {\n        $route = $this-\u003eresolveRoute(__FUNCTION__);\n        $response = $this-\u003ehttpClient-\u003eget($route);\n        echo $response-\u003egetBody()-\u003egetContents();\n    }\n    \n    #[ApiRoute('/user/{id}')]\n    public function fetchOne(int $id): void\n    {\n        $route = $this-\u003eresolveRoute(__FUNCTION__, ['id' =\u003e $id]);\n        $response = $this-\u003ehttpClient-\u003eget($route);\n\n        if ($response-\u003egetStatusCode() === 200) {\n            $data = json_decode($response-\u003egetBody()-\u003egetContents(), true);\n            // Process the $data as needed.\n        }\n    }\n\n    #[ApiRoute('/user/create')]\n    public function create(array $data): void\n    {\n        $route = $this-\u003eresolveRoute(__FUNCTION__);\n        $response = $this-\u003ehttpClient-\u003epost($route, [\n            'json' =\u003e $data,\n        ]);\n        echo \"User Created: \" . $response-\u003egetBody()-\u003egetContents() . \"\\n\";\n    }\n\n    #[ApiRoute('/user/{id}/update')]\n    public function update(int $id, array $data): void\n    {\n        $parameters = ['id' =\u003e $id];\n        $route = $this-\u003eresolveRoute(__FUNCTION__, $parameters);\n\n        $response = $this-\u003ehttpClient-\u003eput($route, [\n            'json' =\u003e $data,\n        ]);\n        echo \"User Updated: \" . $response-\u003egetBody()-\u003egetContents() . \"\\n\";\n    }\n\n    #[ApiRoute('/user/{id}/delete')]\n    public function delete(int $id): void\n    {\n        $parameters = ['id' =\u003e $id];\n        $route = $this-\u003eresolveRoute(__FUNCTION__, $parameters);\n\n        $response = $this-\u003ehttpClient-\u003edelete($route);\n        echo \"User Deleted: \" . $response-\u003egetBody()-\u003egetContents() . \"\\n\";\n    }\n\n    private function resolveRoute(string $methodName, array $parameters = []): string\n    {\n        $route = $this-\u003erouteRegistry-\u003egetRoute(static::class, $methodName);\n\n        if (!$route) {\n            throw new \\RuntimeException(\"Route not found for method: $methodName\");\n        }\n\n        return $this-\u003erouteResolver-\u003eresolve($route, $parameters);\n    }\n}\n\n// Usage example:\n$routeRegistry = new RouteRegistry();\n$routeResolver = new RouteResolver();\n$httpClient = new Client([\n    'base_uri' =\u003e 'https://api.example.com',\n    'timeout'  =\u003e 5.0,\n]);\n\n$userRepository = new UserRepository($routeRegistry, $routeResolver, $httpClient);\n// Fetch one user\n$userRepository-\u003efetchOne(123);\n// Fetch all users\n$userRepository-\u003efetchAll();\n// Create a user\n$userRepository-\u003ecreate(['name' =\u003e 'John Doe', 'email' =\u003e 'john@example.com']);\n// Update a user\n$userRepository-\u003eupdate(123, ['name' =\u003e 'John Doe Updated']);\n// Delete a user\n$userRepository-\u003edelete(123);\n```\n\n\u003e Note: RouteMapper does not perform HTTP requests. Any HTTP client (Guzzle, Symfony HttpClient, etc.) can be used.\n\n---\n\n## Comparison with Other Solutions\n\n| Feature                 | RouteMapper | Symfony Routing | Laravel Routing | Slim Framework |\n|-------------------------|-------------|-----------------|-----------------|----------------|\n| **Attribute-based**     | ✅           | ✅               | ❌               | ❌              |\n| **Framework-Agnostic**  | ✅           | ❌               | ❌               | ✅              |\n| **Lightweight**         | ✅           | ⚠️              | ❌               | ✅              |\n| **Explicit resolution** | ✅           | ❌               | ❌               | ⚠️             |\n\n## Acknowledgments\n\nInspired by the flexibility of modern PHP attributes and the simplicity of middleware-based frameworks.\n\n---\n\n## License\n\nRouteMapper is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeremi%2Froute-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeremi%2Froute-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeremi%2Froute-mapper/lists"}