1 | <?php |
||
18 | class CustomerAddressManager implements LoggerAwareInterface |
||
19 | { |
||
20 | use LoggerAwareTrait; |
||
21 | |||
22 | /** @var EntityManager */ |
||
23 | protected $em; |
||
24 | |||
25 | /** @var PropertyAccessor */ |
||
26 | protected $accessor; |
||
27 | |||
28 | /** @var ConvertAddressToContactAdress */ |
||
29 | protected $convertAddressToContactAddress; |
||
30 | |||
31 | /** @var array */ |
||
32 | protected $baseAddressProperties = [ |
||
33 | 'label', |
||
34 | 'street', |
||
35 | 'street2', |
||
36 | 'city', |
||
37 | 'postalCode', |
||
38 | 'country', |
||
39 | 'organization', |
||
40 | 'region', |
||
41 | 'regionText', |
||
42 | 'namePrefix', |
||
43 | 'firstName', |
||
44 | 'middleName', |
||
45 | 'lastName', |
||
46 | 'nameSuffix' |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * @param EntityManager $em |
||
51 | * @param ConvertAddressToContactAdress $convertAddressToContactAdress |
||
52 | */ |
||
53 | public function __construct( |
||
61 | |||
62 | /** |
||
63 | * @param int[]|null $customersIds |
||
64 | * @param int[]|null $integrationIds |
||
65 | * @param int $batchSize |
||
66 | */ |
||
67 | public function copyToContact($customersIds = null, $integrationIds = null, $batchSize = 25) |
||
105 | |||
106 | /** |
||
107 | * @param Contact $contact |
||
108 | * @param ContactAddress $contactAddress |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | protected function contactHasAddress(Contact $contact, ContactAddress $contactAddress) |
||
123 | |||
124 | /** |
||
125 | * @param ContactAddress $address1 |
||
126 | * @param ContactAddress $address2 |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | protected function isEqualAddresses(ContactAddress $address1, ContactAddress $address2) |
||
141 | } |
||
142 |
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.