PHP code example of ecommit / doctrine-entities-generator-bundle

1. Go to this page and download the library: Download ecommit/doctrine-entities-generator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ecommit / doctrine-entities-generator-bundle example snippets


return [
    //...
    Ecommit\DoctrineEntitiesGeneratorBundle\EcommitDoctrineEntitiesGeneratorBundle::class => ['dev' => true],
    //...
];

    /*
     * Getters / Setters (auto-generated)
     */

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected $categoryId;

    #[ORM\Column(type: 'string', length: 255)]
    protected $name;

    /*
     * Getters / Setters (auto-generated)
     */

    //Content after this block will be deleted when
    //the bundle generates the getters-setters methods.
    //Getters-setters methods will be generated here.
}

use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\GenerateEntityTemplate;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
#[GenerateEntityTemplate("your_template.php.twig")]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected $categoryId;
    //...
}

use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\GenerateEntityTemplate;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
#[GenerateEntityTemplate('your_template.php.twig')]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected $categoryId;
    //...

    /*
     * Getters / Setters (auto-generated)
     */


    /*
     * End Getters / Setters (auto-generated)
     */
}

use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Entity\EntityInitializerInterface;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
class Category implements EntityInitializerInterface
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected $categoryId;

    #[ORM\OneToMany(targetEntity: 'Ecommit\DoctrineEntitiesGeneratorBundle\Tests\App\Entity\Book', mappedBy: 'category')]
    protected $books;

    #[ORM\Column(type: 'datetime')]
    protected $createdAt;

    public function initializeEntity(): void
    {
        $this->createdAt = new \DateTime('now');
    }

    //...
}

use Doctrine\ORM\Mapping as ORM;
use Ecommit\DoctrineEntitiesGeneratorBundle\Attribute\IgnoreGenerateEntity;

#[ORM\Entity]
#[ORM\Table(name: 'category')]
#[IgnoreGenerateEntity]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer', name: 'category_id')]
    protected $categoryId;
    //...
}
yaml
ecommit_doctrine_entities_generator:
    template: "your_template.php.twig"