{"id":18382907,"url":"https://github.com/e-commit/doctrine-entities-generator-bundle","last_synced_at":"2025-04-06T23:32:01.402Z","repository":{"id":56974782,"uuid":"244191483","full_name":"e-commit/doctrine-entities-generator-bundle","owner":"e-commit","description":"The EcommitDoctrineEntitiesGeneratorBundle bundle (for Symfony) allows the user to re(generate) getters-setters methods for Doctrine ORM entities.","archived":false,"fork":false,"pushed_at":"2024-02-27T09:55:54.000Z","size":188,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-14T19:33:32.777Z","etag":null,"topics":["doctrine","doctrine-orm-entities","entity","getters","php","setters","symfony"],"latest_commit_sha":null,"homepage":"","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/e-commit.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":"2020-03-01T17:19:37.000Z","updated_at":"2024-03-14T19:33:32.778Z","dependencies_parsed_at":"2023-02-16T05:31:24.727Z","dependency_job_id":"5bd8caaf-d500-4550-b77f-5ead32cafae9","html_url":"https://github.com/e-commit/doctrine-entities-generator-bundle","commit_stats":{"total_commits":63,"total_committers":1,"mean_commits":63.0,"dds":0.0,"last_synced_commit":"4139b60838930a8d4f7bced49be7cd2af105511c"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-commit%2Fdoctrine-entities-generator-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-commit%2Fdoctrine-entities-generator-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-commit%2Fdoctrine-entities-generator-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-commit%2Fdoctrine-entities-generator-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e-commit","download_url":"https://codeload.github.com/e-commit/doctrine-entities-generator-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247569124,"owners_count":20959758,"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":["doctrine","doctrine-orm-entities","entity","getters","php","setters","symfony"],"created_at":"2024-11-06T01:09:06.572Z","updated_at":"2025-04-06T23:32:01.395Z","avatar_url":"https://github.com/e-commit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EcommitDoctrineEntitiesGeneratorBundle\n\nThe EcommitDoctrineEntitiesGeneratorBundle bundle (for Symfony) allows the user to re(generate) getters-setters \nmethods for Doctrine ORM entities.\n\n\n![Tests](https://github.com/e-commit/doctrine-entities-generator-bundle/workflows/Tests/badge.svg)\n\n\n| Bundle version | Compatible with Doctrine ORM |\n|----------------|------------------------------|\n| 3.*            | ≥ 3.2 ; \u003c 4.0                |\n| 2.*            | ≥ 2.7 ; \u003c 3.0                |\n\n\n\n## Installation ##\n\nInstall the bundle with Composer : In your project directory, execute the following command :\n\n```bash\n$ composer require ecommit/doctrine-entities-generator-bundle\n```\n\nEnable the bundle in the `config/bundles.php` file for your project :\n\n```php\nreturn [\n    //...\n    Ecommit\\DoctrineEntitiesGeneratorBundle\\EcommitDoctrineEntitiesGeneratorBundle::class =\u003e ['dev' =\u003e true],\n    //...\n];\n```\n\n## Usage ##\n\nAdd the start tag to your entity :\n\n```php\n    /*\n     * Getters / Setters (auto-generated)\n     */\n```\n\n**WARNING** : The content between this start tag and the end of the PHP class will be deleted\nwhen the bundle generates the getters-setters methods. The getters-setters methods will be generated\nbetween these two tags.\n\n\nFor example:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\n\n#[ORM\\Entity]\n#[ORM\\Table(name: 'category')]\nclass Category\n{\n    #[ORM\\Id]\n    #[ORM\\Column(type: 'integer', name: 'category_id')]\n    protected $categoryId;\n\n    #[ORM\\Column(type: 'string', length: 255)]\n    protected $name;\n\n    /*\n     * Getters / Setters (auto-generated)\n     */\n\n    //Content after this block will be deleted when\n    //the bundle generates the getters-setters methods.\n    //Getters-setters methods will be generated here.\n}\n```\n\nYou can change the start tag and the end tag (the end of the PHP class by default) : See the \"FAQ\" section.\n\n\nIn your project directory, execute the following command :\n\n```bash\n$ php bin/console ecommit:doctrine:generate-entities {Classename}\n```\n\nFor example:\n\n```bash\n$ php bin/console ecommit:doctrine:generate-entities App/Entity/MyEntity\n```\n\nEach slash is replaced by an anti-slash.\n\nYou can use the `*` joker (which generates multiple entities). For example:\n\n```bash\n$ php bin/console ecommit:doctrine:generate-entities App/Entity/*\n```\n\nThe bundle generates getters-setters methods for an entity only if :\n* The PHP class is a Doctrine ORM entity; and\n* The entity is not an interface; and\n* The entity is not a trait; and\n* The entity doesn't use the `Ecommit\\DoctrineEntitiesGeneratorBundle\\Attribute\\IgnoreGenerateEntity` attribute.\n\nThe bundle generates getters-setters methods for an entity property only if :\n* The property is defined directly in the entity (and is not defined in an inherited class or a trait); and\n* The property is not public; and\n* The methods (getters-setters) do not exist (except if the method is defined between the start and end tags).\n\n## FAQ ##\n\n### How can I change the generated code ? ###\n\nWhen the code is generated, the `@EcommitDoctrineEntitiesGenerator/Theme/base.php.twig` Twig template is used.\n\nYou can create a custom template (that extends the base template). \n\n\n**Solution 1 - Override the bundle**\n\nSee https://symfony.com/doc/current/bundles/override.html\n\n**Solution 2 - Configure the template**\n\nIn your project configuration, you can configure the theme used by the bundle. For example, you can create \nthe `config/packages/dev/ecommit_doctrine_entities_generator.yaml` file:\n\n```yaml\necommit_doctrine_entities_generator:\n    template: \"your_template.php.twig\"\n```\n\n**Solution 3 - Create a custom template in entity**\n\nYou can override the theme to be used by the bundle only for an entity. To do this, use\nthe `Ecommit\\DoctrineEntitiesGeneratorBundle\\Attribute\\GenerateEntityTemplate` attribute:\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Ecommit\\DoctrineEntitiesGeneratorBundle\\Attribute\\GenerateEntityTemplate;\n\n#[ORM\\Entity]\n#[ORM\\Table(name: 'category')]\n#[GenerateEntityTemplate(\"your_template.php.twig\")]\nclass Category\n{\n    #[ORM\\Id]\n    #[ORM\\Column(type: 'integer', name: 'category_id')]\n    protected $categoryId;\n    //...\n}\n```\n\n### How can I change the start-end tags ? ###\n\nYou can change the template (see previous question).\n\nThe start tag is defined in the `start_tag` Twig block.\n\nThe end tag is defined in the `end_tag` Twig block.\n\nFor example, you can create this theme:\n\n```twig\n{% extends '@EcommitDoctrineEntitiesGenerator/Theme/base.php.twig' %}\n\n{% block end_tag %}\n\n\n    /*\n     * End Getters / Setters (auto-generated)\n     */\n{% endblock %}\n```\n\nand use as follows: \n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Ecommit\\DoctrineEntitiesGeneratorBundle\\Attribute\\GenerateEntityTemplate;\n\n#[ORM\\Entity]\n#[ORM\\Table(name: 'category')]\n#[GenerateEntityTemplate('your_template.php.twig')]\nclass Category\n{\n    #[ORM\\Id]\n    #[ORM\\Column(type: 'integer', name: 'category_id')]\n    protected $categoryId;\n    //...\n\n    /*\n     * Getters / Setters (auto-generated)\n     */\n\n\n    /*\n     * End Getters / Setters (auto-generated)\n     */\n}\n```\n\n### How can I create a constructor in my entity ? ###\n\nIf your entity has a `TOMANY` association, the bundle will create a constructor in your entity.\nFor this reason, manually defining a constructor in your entity is not allowed.\n\nInstead, you can use the `Ecommit\\DoctrineEntitiesGeneratorBundle\\Entity\\EntityInitializerInterface` interface\nand its `initializeEntity` method.\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Ecommit\\DoctrineEntitiesGeneratorBundle\\Entity\\EntityInitializerInterface;\n\n#[ORM\\Entity]\n#[ORM\\Table(name: 'category')]\nclass Category implements EntityInitializerInterface\n{\n    #[ORM\\Id]\n    #[ORM\\Column(type: 'integer', name: 'category_id')]\n    protected $categoryId;\n\n    #[ORM\\OneToMany(targetEntity: 'Ecommit\\DoctrineEntitiesGeneratorBundle\\Tests\\App\\Entity\\Book', mappedBy: 'category')]\n    protected $books;\n\n    #[ORM\\Column(type: 'datetime')]\n    protected $createdAt;\n\n    public function initializeEntity(): void\n    {\n        $this-\u003ecreatedAt = new \\DateTime('now');\n    }\n\n    //...\n}\n```\n\nThe `initializeEntity` method will be automatically called in the constructor generated in this way.\n\n\n### An EntityInitializerInterfaceNotUsedException exception is thrown ###\n\nAn `Ecommit\\DoctrineEntitiesGeneratorBundle\\Exception\\EntityInitializerInterfaceNotUsedException`\nexception is thrown if you define manually a constructor in your entity when a `TOMANY` association is used.\n\nSee the previous question.\n\n\n### A TagNotFoundException exception is thrown ###\n\nThe start and/or end tag was not found in your entity.\n\n\n### How can I ignore the generation of getters-setters methods for an entity ? ###\n\nNot all entities are processed (see the \"Usage\" section to find out which classes can be generated).\n\nYou can ignore the generation of getters-setters methods for an entity by using the\n`Ecommit\\DoctrineEntitiesGeneratorBundle\\Attribute\\IgnoreGenerateEntity` attribute :\n\n```php\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Ecommit\\DoctrineEntitiesGeneratorBundle\\Attribute\\IgnoreGenerateEntity;\n\n#[ORM\\Entity]\n#[ORM\\Table(name: 'category')]\n#[IgnoreGenerateEntity]\nclass Category\n{\n    #[ORM\\Id]\n    #[ORM\\Column(type: 'integer', name: 'category_id')]\n    protected $categoryId;\n    //...\n}\n```\n\n### How can I ignore the generation of getters-setters methods for a property ? ###\n\nNot all properties are processed (see the \"Usage\" section to find out which properties can be generated).\n\n### Why was no method generated ? ###\n\nSee the last two questions.\n\n\n\n## Limitations ##\n\nThe bundle only works under the following conditions :\n\n* The Doctrine attributes are used (Doctrine annotations are not compatible).\n* Only one entity (PHP class) per PHP file\n* Inside each entity (PHP class) :\n    * Only one property per line\n    * Only one method per line (but a method can be defined through over lines)\n* EOL (End Of Line) = LF\n\n\n## License ##\n\nThis bundle is available under the MIT license. See the complete license in the *LICENSE* file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-commit%2Fdoctrine-entities-generator-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe-commit%2Fdoctrine-entities-generator-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-commit%2Fdoctrine-entities-generator-bundle/lists"}