| @@ 21-50 (lines=30) @@ | ||
| 18 | * |
|
| 19 | * @package Nnx\JmsSerializerModule\MetadataDriver |
|
| 20 | */ |
|
| 21 | class AnnotationDriverFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
| 22 | { |
|
| 23 | use MutableCreationOptionsTrait; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @param ServiceLocatorInterface $serviceLocator |
|
| 27 | * |
|
| 28 | * @return AnnotationDriver |
|
| 29 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
| 30 | * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
|
| 31 | */ |
|
| 32 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
| 33 | { |
|
| 34 | $creationOptions = $this->getCreationOptions(); |
|
| 35 | ||
| 36 | if (!array_key_exists('reader', $creationOptions)) { |
|
| 37 | $errMsg = 'Annotation reader not specified'; |
|
| 38 | throw new Exception\RuntimeException($errMsg); |
|
| 39 | } |
|
| 40 | ||
| 41 | $reader = $serviceLocator->get($creationOptions['reader']); |
|
| 42 | ||
| 43 | if (!$reader instanceof Reader) { |
|
| 44 | $errMsg = sprintf('Annotation reader not implement %s', Reader::class); |
|
| 45 | throw new Exception\RuntimeException($errMsg); |
|
| 46 | } |
|
| 47 | ||
| 48 | return new AnnotationDriver($reader); |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 20-47 (lines=28) @@ | ||
| 17 | * |
|
| 18 | * @package Nnx\JmsSerializerModule\MetadataDriver |
|
| 19 | */ |
|
| 20 | class FileLocatorFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
| 21 | { |
|
| 22 | use MutableCreationOptionsTrait; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param ServiceLocatorInterface $serviceLocator |
|
| 26 | * |
|
| 27 | * @return FileLocator |
|
| 28 | * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
|
| 29 | */ |
|
| 30 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
| 31 | { |
|
| 32 | $creationOptions = $this->getCreationOptions(); |
|
| 33 | ||
| 34 | if (!array_key_exists('directories', $creationOptions)) { |
|
| 35 | $errMsg = 'Directories for FileLocator is not specified'; |
|
| 36 | throw new Exception\RuntimeException($errMsg); |
|
| 37 | } |
|
| 38 | $directories = $creationOptions['directories']; |
|
| 39 | ||
| 40 | if (!is_array($directories)) { |
|
| 41 | $errMsg = 'Directories for FileLocator is not array'; |
|
| 42 | throw new Exception\RuntimeException($errMsg); |
|
| 43 | } |
|
| 44 | ||
| 45 | return new FileLocator($directories); |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| @@ 19-47 (lines=29) @@ | ||
| 16 | * |
|
| 17 | * @package Nnx\JmsSerializerModule\MetadataDriver |
|
| 18 | */ |
|
| 19 | class LazyLoadingDriverFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
| 20 | { |
|
| 21 | use MutableCreationOptionsTrait; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @param ServiceLocatorInterface $serviceLocator |
|
| 25 | * |
|
| 26 | * @return LazyLoadingDriver |
|
| 27 | * @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
|
| 28 | */ |
|
| 29 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
| 30 | { |
|
| 31 | $creationOptions = $this->getCreationOptions(); |
|
| 32 | ||
| 33 | if (!array_key_exists('realDriverId', $creationOptions)) { |
|
| 34 | $errMsg = 'RealDriverId in LazyLoadingDriver not found'; |
|
| 35 | throw new Exception\RuntimeException($errMsg); |
|
| 36 | } |
|
| 37 | ||
| 38 | $realDriverId = $creationOptions['realDriverId']; |
|
| 39 | ||
| 40 | if (!$serviceLocator instanceof ContainerInterface) { |
|
| 41 | $errMsg = sprintf('Service locator not implement %s', ContainerInterface::class); |
|
| 42 | throw new Exception\RuntimeException($errMsg); |
|
| 43 | } |
|
| 44 | ||
| 45 | return new LazyLoadingDriver($serviceLocator, $realDriverId); |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||