{"id":21618689,"url":"https://github.com/apioo/psx","last_synced_at":"2025-04-08T15:13:11.497Z","repository":{"id":4955725,"uuid":"6113135","full_name":"apioo/psx","owner":"apioo","description":"PSX is an innovative PHP framework dedicated to build fully typed REST APIs.","archived":false,"fork":false,"pushed_at":"2024-10-10T12:26:01.000Z","size":8634,"stargazers_count":169,"open_issues_count":0,"forks_count":13,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-01T14:09:58.894Z","etag":null,"topics":["api","code-generator","framework","openapi","php","rest"],"latest_commit_sha":null,"homepage":"https://phpsx.org","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"django-guardian/django-guardian","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apioo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"chriskapp","patreon":"fusio","custom":"https://www.paypal.me/fusioapi"}},"created_at":"2012-10-07T14:49:53.000Z","updated_at":"2025-03-18T21:49:02.000Z","dependencies_parsed_at":"2024-06-18T17:11:01.861Z","dependency_job_id":"5b9e504a-aefd-4386-af79-35508b749de6","html_url":"https://github.com/apioo/psx","commit_stats":{"total_commits":1900,"total_committers":2,"mean_commits":950.0,"dds":"0.025789473684210473","last_synced_commit":"b9b61ac6ed5bda32b585e724b9a1a2f97da5d426"},"previous_names":[],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apioo","download_url":"https://codeload.github.com/apioo/psx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247867362,"owners_count":21009240,"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":["api","code-generator","framework","openapi","php","rest"],"created_at":"2024-11-24T23:06:31.420Z","updated_at":"2025-04-08T15:13:11.469Z","avatar_url":"https://github.com/apioo.png","language":"PHP","readme":"\n## About\n\n__PSX is an innovative PHP framework dedicated to build fully typed REST APIs.__\n\nIt helps to improve the API development process by providing the following features:\n\n* Fully typed controller classes\n* Client SDK generator\n* [OpenAPI](https://www.openapis.org/) generator\n* Generate model classes based on a [TypeSchema](https://typeschema.org/) specification\n* Uses the Symfony [DI container](https://github.com/symfony/dependency-injection) component\n* Works with Doctrine [DBAL](https://github.com/doctrine/dbal) and [migrations](https://github.com/doctrine/migrations)\n* Type-safe database interaction\n* Endpoint integration testing\n\nMore information about PSX at [phpsx.org](https://phpsx.org/).\n\n## Installation\n\nTo install the framework you can simply install this demo API project.\n\n```\ncomposer create-project psx/psx .\n```\n\n## Getting started\n\nThis repository contains already a fully working demo API build with PSX which you can use as a starting point and to\nbetter understand how PSX works. In the following we go based on the demo files through the important concepts of PSX.\n\n## Controller\n\nA controller is the entrypoint of your app which gets invoked by the framework. A controller is a simple PHP class which\ncontains attributes to make specific methods invokable. In the following example we have a simple controller with a\n`getAll` and `create` method which gets invoked if a `GET` or `POST` request arrives at the `/population` endpoint s.\n\n```php\nclass Population extends ControllerAbstract\n{\n    #[Get]\n    #[Path('/population')]\n    public function getAll(#[Query] ?int $startIndex = null, #[Query] ?int $count = null): Model\\PopulationCollection\n    {\n        return $this-\u003epopulationTable-\u003egetCollection($startIndex, $count);\n    }\n\n    #[Post]\n    #[Path('/population')]\n    public function create(#[Body] Model\\Population $payload): Model\\Message\n    {\n        $id = $this-\u003epopulationService-\u003ecreate($payload);\n\n        $message = new Model\\Message();\n        $message-\u003esetSuccess(true);\n        $message-\u003esetMessage('Population record successfully created');\n        $message-\u003esetId($id);\n        return $message;\n    }\n}\n```\n\nOne key concept of PSX is that the arguments of your exposed controller methods are mapped to values of the incoming\nHTTP request, at the `getAll` method the `$startIndex` and `$count` parameter are mapped to a query parameter from the\nHTTP request, at the `create` method the `$payload` parameter is mapped to the request body. If you are familiar with\n[Spring](https://spring.io/) or [NestJS](https://nestjs.com/) you already know this approach.\n\nPSX uses the symfony DI container, all controller classes are automatically loaded through auto-wiring. This means\nyou can simply define at the constructor all dependencies which are needed for your controller. Please take a look at\nthe [container.php](https://github.com/apioo/psx/blob/master/resources/container.php) if you want to customize which classes are loaded.\n\n## SDK\n\nOne of the greatest feature of PSX is that it can automatically generate a client SDK for the API which you have build.\nTo generate the client SDK simply run the following command.\n\n```\nphp bin/psx generate:sdk\n```\n\nThis writes the SDK to the `output/` folder. By default, the command generates the TypeScript SDK. Based on the\ncontroller defined above PSX would generate the following client SDK.\n\n```\nconst client = new Client(...);\n\nclient.population().getAll(startIndex?: number, count?: number);\nclient.population().create(payload: Population);\n```\n\nThe client then contains the same schemas which are also defined at the backend but converted to TypeScript. This means\nyou are using exactly the same schema at the backend and frontend. If you change your schema at the backend you can then\nregenerate the SDK and you will directly see all problems with your new schema. In this sense PSX provides similar\nfeatures like [tRPC](https://trpc.io/) but in a language neutral way.\n\nThe `generate:sdk` command accepts as argument a format which defines the type of SDK which is generated. The following\nlist shows some supported formats.\n\n* `client-php`\n* `client-typescript`\n* `spec-openapi`\n\n## Model\n\nTo enable this SDK generation PSX needs to understand the structure of the incoming or outgoing JSON payload. This is\ndone by using DTO models for every argument and return type. PSX contains a model generator which allows you to generate\nthose models based on a [TypeSchema](https://typeschema.org/) specification. Please take a look at the\n[typeschema.json](https://github.com/apioo/psx/blob/master/resources/typeschema.json) file which contains the models for\nour demo API. You can generate all models using the following command s.\n\n```\nphp bin/psx generate:model\n```\n\nThe command writes all models to the `src/Model` folder. You can then use those models at the controller classes.\n\n## Service\n\nPSX recommends to move your actual business logic into a separate service class. The controller then simply invokes\nmethods from your service. While this is not mandatory it improves your code quality since you can easily use this\nservice also in another context. All classes under the `service/` folder are automatically loaded thus you can specify\nall dependencies through simple constructor injection.\n\n## Migrations\n\nPSX uses doctrine [migrations](https://github.com/doctrine/migrations/) which helps to manage your database schema. To\ngenerate a new migration you can simply run s.\n\n```\nphp bin/psx migrations:generate\n```\n\nThis would create a new migration file at `src/Migrations`. You can then model your table schema at this migration file.\nAfter this you can run the `migrate` command to execute all needed database changes s.\n\n```\nphp bin/psx migrations:migrate\n```\n\nPlease take a look at the doctrine [migrations](https://github.com/doctrine/migrations/) project for more information\nhow the migration system works.\n\n## Table\n\nPSX provides a command which generates table and row classes to interact with your database in a type-safe way. This\ncommand should be executed after you have executed all your migrations.\n\n```\nphp bin/psx generate:table\n```\n\nThis command then writes all files to the `src/Table` folder.\n\nNote in general we think that for API development an ORM is not needed, but it would be easy possible to integrate any\nexisting ORM into PSX.\n\n## Tests\n\nPSX provides a way to easily build an integration test for every controller endpoint. The following extract shows the\ntest which requests the `/population` endpoint and simply compares the JSON payload with an existing JSON structure.\n\n```php\npublic function testGetAll(): void\n{\n    $response = $this-\u003esendRequest('/population', 'GET');\n\n    $actual = (string) $response-\u003egetBody();\n    $expect = file_get_contents(__DIR__ . '/resources/collection.json');\n\n    $this-\u003eassertEquals(200, $response-\u003egetStatusCode(), $actual);\n    $this-\u003eassertJsonStringEqualsJsonString($expect, $actual, $actual);\n}\n```\n\nThrough this you can easily build integration tests for every endpoint. Please take a look at the\n`tests/Controller/PopulationTest.php` file to see the complete test case.\n\n## Components\n\nBesides the framework PSX is build on various PHP components. These components are independent of the framework and can\nalso be used in another context. The following list contains the most notable packages:\n\n- [psx/api](https://github.com/apioo/psx-api)  \n  Parse and generate API specification formats\n- [psx/schema](https://github.com/apioo/psx-schema)  \n  Parse and generate data schema formats\n- [psx/data](https://github.com/apioo/psx-data)  \n  Data processing library to read and write POPOs in different formats\n- [psx/sql](https://github.com/apioo/psx-sql)  \n  Generate type-safe PHP classes from your database\n","funding_links":["https://github.com/sponsors/chriskapp","https://patreon.com/fusio","https://www.paypal.me/fusioapi"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapioo%2Fpsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapioo%2Fpsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapioo%2Fpsx/lists"}