setono / doctrine-object-manager-trait
v1.3.0
2024-04-16 08:25 UTC
Requires
- php: >=8.1
- doctrine/orm: ^2.8
- doctrine/persistence: ^1.3 || ^2.5 || ^3.1
- webmozart/assert: ^1.11
Requires (Dev)
- infection/infection: ^0.27
- phpspec/prophecy-phpunit: ^2.2
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.18
- setono/code-quality-pack: ^2.7
This package is auto-updated.
Last update: 2024-04-16 09:33:09 UTC
README
如果你和我一样,通常 不直接注入实体管理器,而是注入管理器注册表,那么这个小库将非常有用。
安装
$ composer require setono/doctrine-object-manager-trait
使用
<?php use Doctrine\Persistence\ManagerRegistry; use Setono\DoctrineObjectManagerTrait\ORM\ORMManagerTrait; final class YourClass { use ORMManagerTrait; public function __construct(ManagerRegistry $managerRegistry) { $this->managerRegistry = $managerRegistry; } public function someMethod(): void { /** * $entity is an entity managed by Doctrine or a class-string representing an entity managed by Doctrine */ $entity = ; /** * Because we used the ORMManagerTrait above the getManager method will return an EntityManagerInterface * * @var \Doctrine\ORM\EntityManagerInterface $manager */ $manager = $this->getManager($entity); $manager->persist($entity); $manager->flush(); } }