PHP code example of setono / doctrine-orm-trait
1. Go to this page and download the library: Download setono/doctrine-orm-trait 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/ */
setono / doctrine-orm-trait example snippets
use Doctrine\Persistence\ManagerRegistry;
use Setono\Doctrine\ORMTrait;
final class YourClass
{
/**
* Include this trait to use the getManager() and getRepository() methods below
*/
use ORMTrait;
public function __construct(ManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}
public function someMethod(): void
{
/**
* $entity<T> is an entity managed by Doctrine or a class-string representing an entity managed by Doctrine
*/
$entity = ;
/** @var \Doctrine\ORM\EntityRepository<T> $repository */
$repository = $this->getRepository($entity);
/** @var \Doctrine\ORM\EntityManagerInterface $manager */
$manager = $this->getManager($entity);
// or do the following to get the default entity manager
/** @var \Doctrine\ORM\EntityManagerInterface $manager */
$manager = $this->getManager();
$manager->persist($entity);
$manager->flush();
}
}