All Projects → A5sys → Doctrinetraitbundle

A5sys / Doctrinetraitbundle

Licence: mit
Generate the entities stub methods in a trait

Projects that are alternatives of or similar to Doctrinetraitbundle

Doctrinefixturesbundle
Symfony integration for the doctrine/data-fixtures library
Stars: ✭ 2,174 (+36133.33%)
Mutual labels:  doctrine, symfony-bundle
doctrine-json-odm
JSON Object-Document Mapping bundle for Symfony and Doctrine
Stars: ✭ 15 (+150%)
Mutual labels:  symfony-bundle, doctrine
Msgphp
Reusable domain layers. Shipped with industry standard infrastructure.
Stars: ✭ 182 (+2933.33%)
Mutual labels:  doctrine, symfony-bundle
User Bundle
A new Symfony user bundle
Stars: ✭ 116 (+1833.33%)
Mutual labels:  doctrine, symfony-bundle
Sonatadoctrineormadminbundle
Integrate Doctrine ORM into the SonataAdminBundle
Stars: ✭ 400 (+6566.67%)
Mutual labels:  doctrine, symfony-bundle
Stofdoctrineextensionsbundle
Integration bundle for DoctrineExtensions by l3pp4rd in Symfony
Stars: ✭ 1,713 (+28450%)
Mutual labels:  doctrine, symfony-bundle
eav-bundle
A Symfony bundle for basic EAV management
Stars: ✭ 19 (+216.67%)
Mutual labels:  symfony-bundle, doctrine
Doctrinephpcrbundle
This bundle integrates Doctrine PHPCR ODM and PHPCR backends into Symfony
Stars: ✭ 131 (+2083.33%)
Mutual labels:  doctrine, symfony-bundle
Doctrinemigrationsbundle
Symfony integration for the doctrine/migrations library
Stars: ✭ 3,782 (+62933.33%)
Mutual labels:  doctrine, symfony-bundle
Translationformbundle
Ease translations with some dedicated Symfony form types
Stars: ✭ 289 (+4716.67%)
Mutual labels:  doctrine, symfony-bundle
Oneupaclbundle
The missing link between Symfonys Acl implementation and your application.
Stars: ✭ 48 (+700%)
Mutual labels:  doctrine, symfony-bundle
Doctrineenumbundle
📦 Provides support of ENUM type for Doctrine in Symfony applications.
Stars: ✭ 410 (+6733.33%)
Mutual labels:  doctrine, symfony-bundle
symbok-bundle
Symfony annotations bundle
Stars: ✭ 50 (+733.33%)
Mutual labels:  symfony-bundle, doctrine
Doctrinecachebundle
Symfony2 Bundle for Doctrine Cache
Stars: ✭ 2,813 (+46783.33%)
Mutual labels:  doctrine, symfony-bundle
Doctrinebundle
Symfony Bundle for Doctrine ORM and DBAL
Stars: ✭ 4,225 (+70316.67%)
Mutual labels:  doctrine, symfony-bundle
Doctrine Json Odm
An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
Stars: ✭ 420 (+6900%)
Mutual labels:  doctrine, symfony-bundle
Websocketbundle
〽️ Websocket server for Symfony applications (powered by Ratchet), includes a Autobahn.JS based JavaScript client
Stars: ✭ 562 (+9266.67%)
Mutual labels:  symfony-bundle
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+11766.67%)
Mutual labels:  doctrine
Entityauditbundle
Audit for Doctrine Entities
Stars: ✭ 546 (+9000%)
Mutual labels:  symfony-bundle
Sentry Symfony
The official Symfony SDK for Sentry (sentry.io)
Stars: ✭ 515 (+8483.33%)
Mutual labels:  symfony-bundle

DoctrineTraitBundle

Generate the entities stub methods in a trait

The generated traits contains the getters/setters generated by the doctrine generator. The trait should be used in your entity.

Benefits

Your entities contains only the usefull information:

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

All basics getters/setters are in the trait.

Composer

Use composer to get the bundle

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

Activate the bundle

In the AppKernel, activate the bundle for the dev environment

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

Usage

Generate traits

Run the command

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

Or this one if you want to act on a single entity

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

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

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;
        }
    }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].