1 | <?php |
||
15 | class ProjectManager { |
||
16 | /** @var Doctrine\ORM\EntityManager **/ |
||
17 | protected $em; |
||
18 | /** @var Developtech\AgilityBundle\Utils\Slugger **/ |
||
19 | protected $slugger; |
||
20 | |||
21 | /** |
||
22 | * @param Doctrine\ORM\EntityManager $em |
||
23 | * @param Slugger $slugger |
||
24 | */ |
||
25 | 5 | public function __construct(EntityManager $em, Slugger $slugger) { |
|
29 | |||
30 | /** |
||
31 | * @return array |
||
32 | */ |
||
33 | 1 | public function getProjects() { |
|
36 | |||
37 | /** |
||
38 | * @param string $slug |
||
39 | * @throws NotFoundHttpException |
||
40 | * @return ProjectModel |
||
41 | */ |
||
42 | 1 | public function getProject($slug) { |
|
49 | |||
50 | /** |
||
51 | * @param string $name |
||
52 | * @param UserInterface $productOwner |
||
53 | * @return \DevelopTech\AgilityBundle\ProjectModel |
||
54 | */ |
||
55 | 1 | public function createProject($name, UserInterface $productOwner) { |
|
68 | |||
69 | /** |
||
70 | * @param integer $id |
||
71 | * @param string $name |
||
72 | * @param integer $betaTestStatus |
||
73 | * @param integer $nbBetaTesters |
||
74 | * @param UserInterface $productOwner |
||
75 | * @throws NotFoundHttpException |
||
76 | * @return ProjectModel |
||
77 | */ |
||
78 | 2 | public function editProject($id, $name, $betaTestStatus, $nbBetaTesters, UserInterface $productOwner = null) { |
|
94 | } |
||
95 |
The
EntityManager
might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during this request will fail.On the other hand, if you instead inject the
ManagerRegistry
, thegetManager()
method guarantees that you will always get a usable manager instance.