{"id":22496988,"url":"https://github.com/morebec/objectgenerator","last_synced_at":"2025-08-12T10:13:08.669Z","repository":{"id":74791534,"uuid":"227470666","full_name":"Morebec/ObjectGenerator","owner":"Morebec","description":"The Object Generator Component, allows to create PHP Objects from Yaml Definition, to save time and reduce typing","archived":false,"fork":false,"pushed_at":"2019-12-14T18:08:28.000Z","size":1603,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-04T01:46:54.923Z","etag":null,"topics":["code-generation","orkestra","php","yaml"],"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/Morebec.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-11T22:15:57.000Z","updated_at":"2019-12-15T14:08:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"ab0160b6-20dc-465e-b24f-ad29977901cc","html_url":"https://github.com/Morebec/ObjectGenerator","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Morebec/ObjectGenerator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FObjectGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FObjectGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FObjectGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FObjectGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morebec","download_url":"https://codeload.github.com/Morebec/ObjectGenerator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morebec%2FObjectGenerator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270041477,"owners_count":24516854,"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-12T02:00:09.011Z","response_time":80,"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":["code-generation","orkestra","php","yaml"],"created_at":"2024-12-06T20:15:12.785Z","updated_at":"2025-08-12T10:13:08.647Z","avatar_url":"https://github.com/Morebec.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Object Generator Component\nThe Object Generator Component, provides functionality to generate PHP objects from Yaml Definitions.\nThis component is used by [Orkestra](https:/github.com/Morebec/Orkestra).\n\n## Rationale\nBecause of its syntax, defining classes in PHP requires a lot of typing: \nfrom namespaces, use declarations, type hints, implements and extends, properties, methods,\nconstructors, getters and setters, to phpDocBlocks, there's a lot to do. \nAfter hundreds of classes, your fingers and your motivation can get pretty tired.\n\nWe figured, wouldn't it be great to be able to define classes with less verbosity?\nWhy not use some sort of DSL that could be translated to working PHP classes?\nHence, the Object Generator Component.\n\n\n## Installation\n```json\n{\n    \"repositories\": [\n        {\n            \"url\": \"https://github.com/Morebec/ObjectGenerator.git\",\n            \"type\": \"git\"\n        }\n    ],\n    \"require\": {\n        \"morebec/object-generator\": \"^1.0\"\n    }\n}\n```\n\n## Usage\n### 1. Create a Yaml Object Definition File\n```yaml\n# Person.yaml\nPerson:\n    namespace: My\\Name\\Space\n    extends: Human\n    desc: This Class represents a Person\n    implements: MortalInterface\n    type: class\n\n    props:\n        fullname:\n            desc: Fullname of the person\n            type: string\n            accessor: true\n            \n        age:\n            desc: Age of the person\n            type: int\n            accessor: true\n\n    methods:\n        __construct:\n            desc: Constructs a Person instance\n            params:\n                fullname:\n                    desc: Fullname of the person\n                    type: string\n                    init: true\n                age:\n                    desc: Age of the person\n                    type: int\n                    init: true\n                    default: 10\n            code: |\n                Assertion::notBlank($fullname, 'A person must have a name!');\n                Assertion::min($age, 0, 'A person must have a positive age!');\n```\n\n### 2. Compile the Object File to PHP\n\n```bash\nbin/console compile:file person.yaml\n```\n\n### 3. Review your newly created PHP file\n```php\n\u003c?php\n\nnamespace My\\Name\\Space;\n\n/**\n * This Class represents a Person\n */\nclass Person extends Human implements MortalInterface\n{\n    /** @var string Fullname of the person */\n    private $fullname;\n\n    /** @var int Age of the person */\n    private $age;\n\n\n    /**\n     * Constructs a Person instance\n     * @param string $fullname Fullname of the person\n     * @param int $age Age of the person\n     */\n    public function __construct(string $fullname, int $age = 10)\n    {\n        $this-\u003eage = $age;\n        $this-\u003efullname = $fullname;\n        Assertion::notBlank($fullname, 'A person must have a name!');\n        Assertion::min($age, 0, 'A person must have a positive age!');\n    }\n\n\n    /**\n     * Returns the value of fullname\n     * @return string Value of fullname\n     */\n    public function getFullname(): string\n    {\n        return $this-\u003efullname;\n    }\n\n\n    /**\n     * Returns the value of age\n     * @return int Value of age\n     */\n    public function getAge(): int\n    {\n        return $this-\u003eage;\n    }\n}\n```\n\n\n### Library Usage\nThe Object Generator Component can also be used in projects as a library.\nFor more information, please read the documentation.\n\n[Documentation](https://github.com/Morebec/ObjectGenerator/tree/docs/user/index.md)\n\n\n## Full object reference\n```yaml\nClassName:\n    namespace:            null\n    final:                false\n    abstract:             false\n    type:                 ~ # One of \"class\"; \"interface\"; \"trait\", Required\n    desc:                 ''\n    extends:              null\n    implements:           []\n    traits:               []\n    annotations:          []\n    use:                  []\n    \n    props:\n\n        # Prototype\n        -\n            type:                 null\n            value:                __undefined__\n            desc:                 ''\n            annotations:          []\n            static:               false\n            constant:             false\n            visibility:           private # One of \"public\"; \"protected\"; \"private\"\n\n            # You can configure how the getter of this property will be generated here.\n            # If you prefer not generating a getter, simply ommit this parameter.\n            accessor:\n\n                # You can specify the name of your setter, here.\n                # If nothing is specified as a name, it will default to getPropertyName.\n                name:                 null\n                desc:                 ''\n                visibility:           public # One of \"public\"; \"protected\"; \"private\"\n\n                # You can specify some PHP code to be injected here.\n                code:                 null\n                annotations:          []\n                abstract:             false\n                static:               false\n                final:                false\n\n            # You can configure how the setter of this property will be generated here.\n            # If you prefer not generating a setter, simply ommit this parameter.\n            mutator:\n\n                # You can specify the name of your setter, here.\n                # If nothing is specified as a name, it will default to setPropertyName.\n                name:                 null\n                desc:                 ''\n                visibility:           public # One of \"public\"; \"protected\"; \"private\"\n\n                # You can specify some PHP code to be injected here.\n                code:                 null\n                annotations:          []\n                abstract:             false\n                static:               false\n                final:                false\n    methods:\n\n        # Prototype\n        -\n            desc:                 ''\n            visibility:           public # One of \"public\"; \"protected\"; \"private\"\n            abstract:             false\n            final:                false\n            static:               false\n            annotations:          []\n\n            # You can specify some PHP code to be injected here.\n            code:                 null\n            params:\n\n                # Prototype\n                name:\n                    type:                 __undefined__\n                    default:              __undefined__\n                    desc:                 ''\n                    annotations:          []\n\n                    # This option is mostly useful for __construct. \n                    # It will initialize the parameter to a property of the same name. (E.g: $this-\u003eproperty = $parameter)\n                    init:                 false\n\n            # Return type definition goes here. If you don't want to provide a return type, simply ommit this parameter\n            return:\n                type:                 __undefined__\n                desc:                 ''\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorebec%2Fobjectgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorebec%2Fobjectgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorebec%2Fobjectgenerator/lists"}