1 | <?php |
||
14 | class ProductExportManager |
||
15 | { |
||
16 | /** |
||
17 | * @var boolean |
||
18 | */ |
||
19 | protected $productValueDelta; |
||
20 | |||
21 | /** |
||
22 | * @var EntityManager |
||
23 | */ |
||
24 | protected $entityManager; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $productExportClass; |
||
30 | |||
31 | /** |
||
32 | * @var EntityRepository |
||
33 | */ |
||
34 | protected $productExportRepository; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * @var EntityRepository |
||
39 | */ |
||
40 | protected $productRepository; |
||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | * |
||
45 | * @param EntityManager $entityManager Entity manager for other entitites |
||
46 | * @param string $productExportClass ProductExport class |
||
47 | * @param string $productClass Product class |
||
48 | * @param boolean $productValueDelta Should we do a delta on product values |
||
49 | */ |
||
50 | public function __construct( |
||
62 | /** |
||
63 | * Update product export dates for the given products |
||
64 | * @param array $products |
||
65 | * @param JobInstance $jobInstance |
||
66 | */ |
||
67 | public function updateProductExports($products, JobInstance $jobInstance) |
||
73 | |||
74 | /** |
||
75 | * Update product export date for the given product |
||
76 | * @param string $identifier |
||
77 | * @param JobInstance $jobInstance |
||
78 | */ |
||
79 | public function updateProductExport($identifier, JobInstance $jobInstance) |
||
130 | |||
131 | /** |
||
132 | * Filter products to export |
||
133 | * @param array $products |
||
134 | * @param JobInstance $jobInstance |
||
135 | * |
||
136 | * @return AbstractProduct |
||
137 | */ |
||
138 | public function filterProducts($products, JobInstance $jobInstance) |
||
152 | |||
153 | /** |
||
154 | * Filter a product (return null if the product got exported after his last edit) |
||
155 | * @param AbstractProduct $product |
||
156 | * @param JobInstance $jobInstance |
||
157 | * |
||
158 | * @return AbstractProduct|null |
||
159 | */ |
||
160 | public function filterProduct(AbstractProduct $product, JobInstance $jobInstance) |
||
181 | |||
182 | /** |
||
183 | * Filter on product values |
||
184 | * |
||
185 | * @param AbstractProduct $product |
||
186 | * |
||
187 | * @return AbstractProduct |
||
188 | */ |
||
189 | public function filterProductValues(AbstractProduct $product) |
||
210 | } |
||
211 |
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.