| 1 | <?php |
||
| 9 | class GroupManager |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var EntityManagerInterface |
||
| 13 | */ |
||
| 14 | private $em; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | private $class; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var ObjectRepository |
||
| 23 | */ |
||
| 24 | private $repository; |
||
| 25 | |||
| 26 | public function __construct(EntityManagerInterface $em, string $class) |
||
| 27 | { |
||
| 28 | $this->em = $em; |
||
| 29 | $this->repository = $em->getRepository($class); |
||
| 30 | $this->class = $class; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function createGroup($name) |
||
| 34 | { |
||
| 35 | $class = $this->getClass(); |
||
| 36 | |||
| 37 | return new $class($name); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function deleteGroup(GroupInterface $group) |
||
| 41 | { |
||
| 42 | $this->em->remove($group); |
||
| 43 | $this->em->flush(); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function updateGroup(GroupInterface $group, $andFlush = true) |
||
| 47 | { |
||
| 48 | $this->em->persist($group); |
||
| 49 | if ($andFlush) { |
||
| 50 | $this->em->flush(); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | public function getClass() |
||
|
|
|||
| 55 | { |
||
| 56 | $metadata = $this->em->getClassMetadata($this->class); |
||
| 57 | |||
| 58 | return $metadata->getName(); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function findGroups() |
||
| 65 | |||
| 66 | public function findGroupByName($name) |
||
| 70 | |||
| 71 | public function findGroupBy(array $criteria) |
||
| 75 | } |
||
| 76 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.