https://github.com/a5sys/doctrinetraitbundle
Generate the entities stub methods in a trait
https://github.com/a5sys/doctrinetraitbundle
doctrine getters setters symfony-bundle
Last synced: 4 months ago
JSON representation
Generate the entities stub methods in a trait
- Host: GitHub
- URL: https://github.com/a5sys/doctrinetraitbundle
- Owner: A5sys
- License: mit
- Created: 2016-04-15T07:27:33.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-02-27T08:19:46.000Z (over 7 years ago)
- Last Synced: 2024-11-15T22:12:39.042Z (over 1 year ago)
- Topics: doctrine, getters, setters, symfony-bundle
- Language: PHP
- Size: 22.5 KB
- Stars: 6
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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;
}
}