setono/doctrine-orm-trait
最新稳定版本:v1.2.0
Composer 安装命令:
composer require setono/doctrine-orm-trait
包简介
A very simple library that offers a trait to get the object manager and repository for a given class
README 文档
README
If you are like and me and usually don't inject entity managers directly, but inject the manager registry instead then this little library will come in handy.
Installation
composer require setono/doctrine-orm-trait
Usage
<?php 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(); } }
统计信息
- 总下载量: 59.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 19
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-16