1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/container |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\Container\EntryNameResolver; |
7
|
|
|
|
8
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
9
|
|
|
use Zend\ServiceManager\FactoryInterface; |
10
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
11
|
|
|
use Nnx\EntryNameResolver\EntryNameResolverChain; |
12
|
|
|
use Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface; |
13
|
|
|
use Nnx\Container\Options\ModuleOptions; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class DefaultEntryNameResolverFactory |
17
|
|
|
* |
18
|
|
|
* @package Nnx\Container\EntryNameResolver |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class DefaultEntryNameResolverFactory implements FactoryInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @inheritdoc |
24
|
|
|
* |
25
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
26
|
|
|
* |
27
|
|
|
* @return DefaultEntryNameResolver |
28
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
29
|
|
|
*/ |
30
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
31
|
|
|
{ |
32
|
|
|
$appServiceLocator = $serviceLocator; |
33
|
|
|
if ($serviceLocator instanceof AbstractPluginManager) { |
34
|
|
|
$appServiceLocator = $serviceLocator->getServiceLocator(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */ |
38
|
|
|
$moduleOptionsPluginManager = $appServiceLocator->get(ModuleOptionsPluginManagerInterface::class); |
39
|
|
|
|
40
|
|
|
/** @var ModuleOptions $moduleOptions */ |
41
|
|
|
$moduleOptions = $moduleOptionsPluginManager->get(ModuleOptions::class); |
42
|
|
|
$entryNameResolversConfig = $moduleOptions->getEntryNameResolvers(); |
43
|
|
|
|
44
|
|
|
$creationOptions = [ |
45
|
|
|
'resolvers' => $entryNameResolversConfig, |
46
|
|
|
'className' => DefaultEntryNameResolver::class |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
$entryNameResolverChain = $serviceLocator->get(EntryNameResolverChain::class, $creationOptions); |
|
|
|
|
50
|
|
|
|
51
|
|
|
return $entryNameResolverChain; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.