2017 © Pedro Peláez
 

symfony-bundle doctrine-trait-bundle

image

a5sys/doctrine-trait-bundle

  • Monday, July 23, 2018
  • by thomasbeaujean
  • Repository
  • 3 Watchers
  • 6 Stars
  • 2,219 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 10 Versions
  • 8 % Grown

The README.md

DoctrineTraitBundle

Generate the entities stub methods in a trait, (*1)

The generated traits contains the getters/setters generated by the doctrine generator. The trait should be used in your entity., (*2)

Benefits

Your entities contains only the usefull information:, (*3)

  • The doctrine columns and relationships
  • The getters/setters that have been modified
  • The custom methods

All basics getters/setters are in the trait., (*4)

Composer

Use composer to get the bundle, (*5)

composer require --dev "a5sys/doctrine-trait-bundle"

Activate the bundle

In the AppKernel, activate the bundle for the dev environment, (*6)

    if (in_array($this->getEnvironment(), array('dev'))) {
        ...
        $bundles[] = new A5sys\DoctrineTraitBundle\DoctrineTraitBundle();
    }

Usage

Generate traits

Run the command, (*7)

    php app/console generate:doctrine:traits AppBundle\\Entity

Or this one if you want to act on a single entity, (*8)

    php app/console generate:doctrine:traits "AppBundle:MyEntity"

Those commands will generate the trait(s) in the /src/AppBundle/Entity/Traits directory, (*9)

Use custom method

  • Go in the trait related to your entity
  • Cut the method
  • Go in your entity
  • Paste the method
  • Update the method
  • The command will not re-generate this method because it is already defined in entity

Exemple

  • Create your entity (User) without the getters/setters
  • Run the command
  • Add the trait to your entity
  • You are done

The entity

    namespace AppBundle/Entity;

    class User
    {
        use AppBundle/Entity/Traits/UserTrait;

        /**
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer", nullable=false)
         */
        protected $id;

        /**
         * @ORM\Column(type="string", length=50, nullable=false)
         */
        protected $name;
    }

The trait

    namespace AppBundle/Entity/Traits;

    /**
     * User
     */
    trait UserTrait
    {

        /**
         *
         * @param integer $id
         */
        public function setId($id)
        {
            $this->id = $id;
        }

        /**
         *
         * @return integer
         */
        public function getId()
        {
            return $this->id;
        }

        /**
         *
         * @param string $name
         */
        public function setName($name)
        {
            $this->name = $name;
        }

        /**
         * Get the name
         *
         * @return string
         */
        public function getName()
        {
            return $this->name;
        }
    }

The Versions

23/07 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

23/07 2018

V2.0.0

2.0.0.0

  Sources   Download

MIT

The Requires

 

23/07 2018

dev-doctrine-2.6-compatibility

dev-doctrine-2.6-compatibility

  Sources   Download

MIT

The Requires

 

12/05 2017

V1.0.5

1.0.5.0

  Sources   Download

MIT

The Requires

 

21/04 2017

V1.0.4

1.0.4.0

  Sources   Download

MIT

The Requires

 

31/01 2017

V1.0.3

1.0.3.0

  Sources   Download

MIT

The Requires

 

16/12 2016

dev-readme-update

dev-readme-update

  Sources   Download

MIT

The Requires

 

19/09 2016

V1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

25/04 2016

V1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

15/04 2016

V1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires