{"id":18273232,"url":"https://github.com/spacetab-io/amphp-support-php","last_synced_at":"2025-09-09T18:04:01.833Z","repository":{"id":57056370,"uuid":"257043016","full_name":"spacetab-io/amphp-support-php","owner":"spacetab-io","description":"Package to reduce code duplication across services.","archived":false,"fork":false,"pushed_at":"2020-06-20T09:43:58.000Z","size":215,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-12T05:23:07.619Z","etag":null,"topics":["amphp","async","php","php74"],"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/spacetab-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-19T16:06:59.000Z","updated_at":"2025-03-05T20:13:53.000Z","dependencies_parsed_at":"2022-08-24T06:01:01.634Z","dependency_job_id":null,"html_url":"https://github.com/spacetab-io/amphp-support-php","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/spacetab-io/amphp-support-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Famphp-support-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Famphp-support-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Famphp-support-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Famphp-support-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spacetab-io","download_url":"https://codeload.github.com/spacetab-io/amphp-support-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Famphp-support-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270899515,"owners_count":24664715,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["amphp","async","php","php74"],"created_at":"2024-11-05T12:05:43.164Z","updated_at":"2025-08-17T19:45:39.425Z","avatar_url":"https://github.com/spacetab-io.png","language":"PHP","funding_links":[],"categories":["Unsorted yet"],"sub_categories":["Tunnel"],"readme":"Amphp support\n=============\n\n[![CircleCI](https://circleci.com/gh/spacetab-io/amphp-support-php/tree/master.svg?style=svg)](https://circleci.com/gh/spacetab-io/amphp-support-php/tree/master)\n[![codecov](https://codecov.io/gh/spacetab-io/amphp-support-php/branch/master/graph/badge.svg)](https://codecov.io/gh/spacetab-io/amphp-support-php)\n\n## Installation\n\n```bash\ncomposer require spacetab-io/amphp-support\n```\n\n## Usage\n\n```php\nuse Amp\\Http\\{Server\\HttpServer, Server\\Request, Server\\Response, Server\\Router, Status};\nuse Amp\\{Loop, Promise, Socket};\nuse HarmonyIO\\Validation\\Rule\\{Combinator\\All, Text\\AlphaNumeric, Text\\LengthRange};\nuse Spacetab\\AmphpSupport\\Handler\\AbstractTrustedRequest;\nuse Spacetab\\AmphpSupport\\Server\\ErrorHandler;\nuse Spacetab\\AmphpSupport\\Middleware\\{AcceptJsonBody, ExceptionMiddleware};\nuse function Amp\\call;\n\nLoop::run(function () {\n    $sockets = [\n        Socket\\Server::listen('0.0.0.0:8081'),\n    ];\n\n    $router = new Router();\n\n    $handler = new class extends AbstractTrustedRequest {\n        public function handleRequest(Request $request): Promise {\n            var_dump($this-\u003egetTrustedBody());\n            return call(fn() =\u003e new Response(Status::OK, [], '{\"message\": \"hey!\"}'));\n        }\n    };\n\n    $router-\u003estack(new ExceptionMiddleware());\n    $router-\u003eaddRoute('POST', '/', $handler, new class extends AcceptJsonBody {\n        public function validate(): iterable {\n            yield 'username' =\u003e new All(new LengthRange(3, 15), new AlphaNumeric());\n        }\n    });\n\n    $server = new HttpServer($sockets, $router, new \\Psr\\Log\\NullLogger());\n    $server-\u003esetErrorHandler(new ErrorHandler());\n\n    yield $server-\u003estart();\n\n    // Stop the server gracefully when SIGINT is received.\n    Loop::onSignal(SIGINT, function (string $watcherId) use ($server) {\n        Loop::cancel($watcherId);\n        yield $server-\u003estop();\n    });\n});\n```\n\n```bash\ncurl -X POST -d '{\"username\": \"roquie\"}' -H 'Content-Type: application/json' http://0.0.0.0:8081/ | jq .\n```\n\n## Depends\n\n* \\\u003e= PHP 7.4\n* Composer for install package\n\n## License\n\nThe MIT License\n\nCopyright © 2020 spacetab.io, Inc. https://spacetab.io\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacetab-io%2Famphp-support-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspacetab-io%2Famphp-support-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacetab-io%2Famphp-support-php/lists"}