1 | <?php |
||
24 | abstract class AbstractValidatorFactory implements FactoryInterface |
||
|
|||
25 | { |
||
26 | // phpcs:enable SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming |
||
27 | public const DEFAULT_OBJECTMANAGER_KEY = 'doctrine.entitymanager.orm_default'; |
||
28 | |||
29 | /** @var mixed[] */ |
||
30 | protected $creationOptions = []; |
||
31 | |||
32 | /** @var string $validatorClass */ |
||
33 | protected $validatorClass; |
||
34 | |||
35 | /** |
||
36 | * @param mixed[] $options |
||
37 | * |
||
38 | * @throws ServiceCreationException |
||
39 | */ |
||
40 | 3 | protected function getRepository(ContainerInterface $container, ?array $options = null) : ObjectRepository |
|
41 | { |
||
42 | 3 | if (empty($options['target_class'])) { |
|
43 | 1 | throw new ServiceCreationException(sprintf( |
|
44 | 1 | "Option 'target_class' is missing when creating validator %s", |
|
45 | 1 | self::class |
|
46 | )); |
||
47 | } |
||
48 | |||
49 | 2 | $objectManager = $this->getObjectManager($container, $options); |
|
50 | 2 | $targetClassName = $options['target_class']; |
|
51 | |||
52 | 2 | return $objectManager->getRepository($targetClassName); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param mixed[] $options |
||
57 | */ |
||
58 | 2 | protected function getObjectManager(ContainerInterface $container, ?array $options = null) : ObjectManager |
|
59 | { |
||
60 | 2 | $objectManager = $options['object_manager'] ?? self::DEFAULT_OBJECTMANAGER_KEY; |
|
61 | |||
62 | 2 | if (is_string($objectManager)) { |
|
63 | 1 | $objectManager = $container->get($objectManager); |
|
64 | } |
||
65 | |||
66 | 2 | return $objectManager; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param mixed[] $options |
||
71 | * |
||
72 | * @return mixed[] |
||
73 | */ |
||
74 | 2 | protected function getFields(array $options) : array |
|
75 | { |
||
76 | 2 | if (isset($options['fields'])) { |
|
77 | 2 | return (array) $options['fields']; |
|
78 | } |
||
79 | |||
80 | return []; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Helper to merge options array passed to `__invoke` |
||
85 | * together with the options array created based on the above |
||
86 | * helper methods. |
||
87 | * |
||
88 | * @param mixed[] $previousOptions |
||
89 | * @param mixed[] $newOptions |
||
90 | * |
||
91 | * @return mixed[] |
||
92 | */ |
||
93 | 1 | protected function merge(array $previousOptions, array $newOptions) : array |
|
94 | { |
||
95 | 1 | return ArrayUtils::merge($previousOptions, $newOptions, true); |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * Helper method for ZF2 compatiblity. |
||
100 | * |
||
101 | * In ZF2 the plugin manager instance if passed to `createService` |
||
102 | * instead of the global service manager instance (as in ZF3). |
||
103 | */ |
||
104 | 2 | protected function container(ContainerInterface $container) : ContainerInterface |
|
105 | { |
||
106 | 2 | if ($container instanceof ServiceLocatorAwareInterface) { |
|
107 | $container = $container->getServiceLocator(); |
||
108 | } |
||
109 | |||
110 | 2 | return $container; |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * {@inheritDoc} |
||
115 | */ |
||
116 | 1 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
120 | |||
121 | /** |
||
122 | * @param mixed[] $options |
||
123 | */ |
||
124 | 1 | public function setCreationOptions(array $options) : void |
|
125 | { |
||
128 | } |
||
129 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.