|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/nnx-framework/jms-serializer-module |
|
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Nnx\JmsSerializerModule\MetadataDriver; |
|
7
|
|
|
|
|
8
|
|
|
use Zend\ServiceManager\AbstractFactoryInterface; |
|
9
|
|
|
use Zend\ServiceManager\MutableCreationOptionsInterface; |
|
10
|
|
|
use Zend\ServiceManager\MutableCreationOptionsTrait; |
|
11
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
12
|
|
|
use ReflectionClass; |
|
13
|
|
|
use Metadata\Driver\AbstractFileDriver; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class FileDriverAbstractFactory |
|
17
|
|
|
* |
|
18
|
|
|
* @package Nnx\JmsSerializerModule\MetadataDriver |
|
19
|
|
|
*/ |
|
20
|
|
|
class FileDriverAbstractFactory implements AbstractFactoryInterface, MutableCreationOptionsInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use MutableCreationOptionsTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @inheritdoc |
|
26
|
|
|
* |
|
27
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
28
|
|
|
* @param $name |
|
29
|
|
|
* @param $requestedName |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool|void |
|
32
|
|
|
*/ |
|
33
|
|
|
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
|
34
|
|
|
{ |
|
35
|
|
|
return class_exists($requestedName) && is_subclass_of($requestedName, AbstractFileDriver::class); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @inheritdoc |
|
40
|
|
|
* |
|
41
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
42
|
|
|
* @param $name |
|
43
|
|
|
* @param $requestedName |
|
44
|
|
|
* |
|
45
|
|
|
* @return AbstractFileDriver |
|
46
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
47
|
|
|
* @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
|
50
|
|
|
{ |
|
51
|
|
|
$creationOptions = $this->getCreationOptions(); |
|
52
|
|
|
|
|
53
|
|
|
if (!array_key_exists('fileLocator', $creationOptions)) { |
|
54
|
|
|
$errMsg = 'File locator name not specified'; |
|
55
|
|
|
throw new Exception\RuntimeException($errMsg); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$fileLocatorName = $creationOptions['fileLocator']; |
|
59
|
|
|
$fileLocator = $serviceLocator->get($fileLocatorName); |
|
60
|
|
|
|
|
61
|
|
|
$r = new ReflectionClass($requestedName); |
|
62
|
|
|
return $r->newInstance($fileLocator); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|