{"id":34013790,"url":"https://github.com/acelot/struct","last_synced_at":"2026-05-26T13:10:30.846Z","repository":{"id":56939969,"uuid":"143245517","full_name":"acelot/struct","owner":"acelot","description":"Declarative structure builder for PHP 7","archived":false,"fork":false,"pushed_at":"2019-03-18T07:34:33.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-15T01:53:01.486Z","etag":null,"topics":["class","dto","model","strongly-typed","struct","structure","validated","value-object"],"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/acelot.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":"2018-08-02T05:14:16.000Z","updated_at":"2019-03-18T07:02:15.000Z","dependencies_parsed_at":"2022-08-21T01:40:20.140Z","dependency_job_id":null,"html_url":"https://github.com/acelot/struct","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/acelot/struct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acelot","download_url":"https://codeload.github.com/acelot/struct/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acelot%2Fstruct/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33521603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T03:12:49.672Z","status":"ssl_error","status_checked_at":"2026-05-26T03:12:47.976Z","response_time":63,"last_error":"SSL_read: 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":["class","dto","model","strongly-typed","struct","structure","validated","value-object"],"created_at":"2025-12-13T13:41:40.120Z","updated_at":"2026-05-26T13:10:30.815Z","avatar_url":"https://github.com/acelot.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Struct\n\n[![Build Status](https://travis-ci.org/acelot/struct.svg?branch=master)](https://travis-ci.org/acelot/struct)\n[![Code Climate](https://img.shields.io/codeclimate/coverage/acelot/struct.svg)](https://codeclimate.com/github/acelot/struct)\n![](https://img.shields.io/badge/dependencies-zero-blue.svg)\n![](https://img.shields.io/badge/license-MIT-green.svg)\n\nDeclarative structure builder for PHP 7.\n\n## Usage\n\nCreate some model:\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace MyNamespace;\n\nuse Acelot\\Struct\\Struct;\nuse Acelot\\Struct\\Schema;\nuse Acelot\\Struct\\Schema\\Prop;\n\nuse function Acelot\\AutoMapper\\from;\n\nuse Respect\\Validation\\Rules\\{\n    AllOf, StringType, Alnum, NoWhitespace, Length, Instance\n};\n\n/**\n * @property-read string             $login\n * @property-read string             $password\n * @property-read string             $name\n * @property-read \\DateTimeInterface $birthday\n */\nclass CreateUserModel extends Struct\n{\n    public static function getSchema() : Schema\n    {\n        return new Schema(\n            Prop::create('login')\n                -\u003ewithValidator(new AllOf(\n                    new StringType(),\n                    new Alnum(),\n                    new NoWhitespace(),\n                    new Length(0, 64)\n                )),   \n            \n            Prop::create('password')\n                -\u003ewithValidator(new AllOf(\n                    new StringType(),\n                    new Length(0, 256)\n                )),\n                \n            Prop::create('name')\n                -\u003ewithValidator(new AllOf(\n                    new StringType(),\n                    new Length(0, 256)\n                ))\n                -\u003ewithMapper(from('name')-\u003etrim()-\u003edefault('John Doe'), 'json')\n                -\u003enotRequired(),\n                \n            Prop::create('birthday')\n                -\u003ewithValidator(new Instance(\\DateTimeInterface::class))\n                -\u003ewithMapper(from('birthday')-\u003econvert(function ($value) {\n                    return new \\DateTimeImmutable($value);\n                }), 'json')\n                -\u003enotRequired()\n        );\n    }\n}\n```\n\nUse model:\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace MyNamespace;\n\n$json = \u003c\u003c\u003cJSON\n{\n    \"login\": \"superhacker\",\n    \"password\": \"correcthorsebatterystaple\",\n    \"birthday\": \"1988-08-08\"\n}\nJSON;\n\n$model = CreateUserModel::mapFrom(json_decode($json), 'json');\n\necho $model-\u003elogin;    // \"superhacker\"\necho $model-\u003epassword; // \"correcthorsebatterystaple\"\necho $model-\u003ename;     // \"John Doe\"\n\nvar_export($model-\u003ebirthday);\n// DateTime::__set_state(array(\n//    'date' =\u003e '1988-08-08 00:00:00.000000',\n//    'timezone_type' =\u003e 3,\n//    'timezone' =\u003e 'UTC',\n// ))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facelot%2Fstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facelot%2Fstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facelot%2Fstruct/lists"}