{"id":15524199,"url":"https://github.com/leocavalcante/ippo","last_synced_at":"2025-04-23T07:29:28.738Z","repository":{"id":57013895,"uuid":"168981888","full_name":"leocavalcante/ippo","owner":"leocavalcante","description":"Immutable, Statically-typed, Cloneable and Serializable Auto-generated Plain-old PHP Objects","archived":false,"fork":false,"pushed_at":"2019-02-27T21:00:51.000Z","size":51,"stargazers_count":29,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T22:41:20.702Z","etag":null,"topics":["auto-generated","cloneable","immutable","objects","php","serializable"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leocavalcante.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":"2019-02-03T19:04:17.000Z","updated_at":"2022-01-25T17:16:11.000Z","dependencies_parsed_at":"2022-08-21T13:30:08.440Z","dependency_job_id":null,"html_url":"https://github.com/leocavalcante/ippo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fippo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fippo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fippo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocavalcante%2Fippo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leocavalcante","download_url":"https://codeload.github.com/leocavalcante/ippo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250390433,"owners_count":21422702,"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":["auto-generated","cloneable","immutable","objects","php","serializable"],"created_at":"2024-10-02T10:49:41.773Z","updated_at":"2025-04-23T07:29:28.698Z","avatar_url":"https://github.com/leocavalcante.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# I.P.P.O [![CircleCI](https://circleci.com/gh/leocavalcante/ippo.svg?style=svg)](https://circleci.com/gh/leocavalcante/ippo)\n\n- Immutable - *Uses `with`s instead of setters*\n- Statically-typed - *Your tooling loves it*\n- Cloneable - *No reference sharing*\n- Serializable - *To JSON, to Array and to String*\n\n― Auto-generated Plain-old PHP Objects.\n\n#### 🛡️ Both lib's source code and it's generated code are verifiable by [Phan](https://github.com/phan/phan) on its strictest level. \n\n## Usage\n\nA definition file looks like:\n```yaml\nnamespace: App\n\ndefinitions:\n  - User:\n    id: int\n    name: string\n    email: string\n    isAdmin: [bool, 'false']\n    birthDate: [?\\DateTime, 'null']\n```\nIt's self explanatory, it declares an `User` class on the `App` namespace with `member: type` or `member: [type, default]`.\nSimple like that.\n\nYou're encoraged to install it as a development dependency in your project:\n```bash\n$ composer install --dev leocavalcante/ippo dev-master\n```\n\nIt will place a binary file at `vendor/bin` that requires only two arguments: the definition file and the output directory.\n```bash\n$ vendor/bin/ippo definitions.yml src/generated/\n```\n\n## Output examples\nFrom the definitions above, you get an `User` class:\n```php\nclass User implements \\JsonSerializable\n```\n\nWith a construtor like:\n```php\npublic function __construct(\n    int $id,\n    string $name,\n    string $email,\n    bool $isAdmin = false,\n    ?\\DateTime $birthDate = null\n) {\n    $this-\u003eid = $id;\n    $this-\u003ename = $name;\n    $this-\u003eemail = $email;\n    $this-\u003eisAdmin = $isAdmin;\n    $this-\u003ebirthDate = $birthDate;\n}\n```\n\nGetters and withs for each declared attribute, like:\n```php\npublic function getName(): string\n{\n    return $this-\u003ename;\n}\n\npublic function withName(string $name): User\n{\n    return new User(\n        $this-\u003eid,\n        $name,\n        $this-\u003eemail,\n        $this-\u003eisAdmin,\n        $this-\u003ebirthDate\n    );\n}\n```\n\nAnd serialization methods like `toArray`:\n```php\npublic function toArray(): array\n{\n    return [\n        'id' =\u003e $this-\u003eid,\n        'name' =\u003e $this-\u003ename,\n        'email' =\u003e $this-\u003eemail,\n        'is_admin' =\u003e $this-\u003eisAdmin,\n        'birth_date' =\u003e $this-\u003ebirthDate,\n    ];\n}\n```\n\nOr `toString()`:\n```php\npublic function toString()\n{\n    $id = json_encode($this-\u003eid);\n    $name = json_encode($this-\u003ename);\n    $email = json_encode($this-\u003eemail);\n    $isAdmin = json_encode($this-\u003eisAdmin);\n    $birthDate = json_encode($this-\u003ebirthDate);\n\n    return \"User(\\n\\tid =\u003e {$id};\\n\\tname =\u003e {$name};\\n\\temail =\u003e {$email};\\n\\tisAdmin =\u003e {$isAdmin};\\n\\tbirthDate =\u003e {$birthDate};\\n)\";\n}\n```\n\nCon·ven·ient factory methods like `fromArray` and `fromJson`:\n```php\nstatic public function fromArray(array $source): User\n{\n    return new User(\n        $source['id'] ?? null,\n        $source['name'] ?? null,\n        $source['email'] ?? null,\n        $source['is_admin'] ?? false,\n        $source['birth_date'] ?? null,\n    );\n}\n\nstatic public function fromJson(string $json): User\n{\n    $source = json_decode($json, true);\n\n    if (false === $source) {\n        throw new \\InvalidArgumentException('JSON decode error: '.json_last_error_msg());\n    }\n\n    if (!is_array($source)) {\n        throw new \\InvalidArgumentException('Your JSON didnt decoded to an array');\n    }\n\n    return User::fromArray($source);\n}\n```\n\n#### [Check out the complete output here](https://github.com/leocavalcante/ippo/blob/master/example/User.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocavalcante%2Fippo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocavalcante%2Fippo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocavalcante%2Fippo/lists"}