1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/old-town/workflow-zf2-dispatch |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace OldTown\Workflow\ZF2\Dispatch\RunParamsHandler; |
7
|
|
|
|
8
|
|
|
use Zend\ServiceManager\FactoryInterface; |
9
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
10
|
|
|
use OldTown\Workflow\ZF2\Dispatch\Options\ModuleOptions; |
11
|
|
|
use OldTown\Workflow\ZF2\Dispatch\Metadata\MetadataReaderManager; |
12
|
|
|
use Zend\Log\Logger; |
13
|
|
|
use Zend\Log\Writer\Noop; |
14
|
|
|
use OldTown\Workflow\ZF2\ServiceEngine\Workflow; |
15
|
|
|
use OldTown\Workflow\ZF2\ServiceEngine\WorkflowServiceInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class RouteHandlerFactory |
19
|
|
|
* |
20
|
|
|
* @package OldTown\Workflow\ZF2\Dispatch\RunParamsHandler |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class RouteHandlerFactory implements FactoryInterface |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
26
|
|
|
* |
27
|
|
|
* @return RouteHandler |
28
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
29
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
30
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotCreatedException |
31
|
|
|
* @throws \Zend\ServiceManager\Exception\RuntimeException |
32
|
|
|
* @throws \Zend\Log\Exception\InvalidArgumentException |
33
|
|
|
*/ |
34
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
35
|
|
|
{ |
36
|
|
|
/** @var ModuleOptions $moduleOptions */ |
37
|
|
|
$moduleOptions = $serviceLocator->get(ModuleOptions::class); |
38
|
|
|
|
39
|
|
|
$readerName = $moduleOptions->getRunWorkflowParamsMetadataReader(); |
40
|
|
|
/** @var MetadataReaderManager $readerManager */ |
41
|
|
|
$readerManager = $serviceLocator->get(MetadataReaderManager::class); |
42
|
|
|
|
43
|
|
|
$reader = $readerManager->get($readerName); |
44
|
|
|
|
45
|
|
|
$logName = $moduleOptions->getLogName(); |
46
|
|
|
if (null === $logName) { |
47
|
|
|
$log = new Logger(); |
48
|
|
|
$writer = new Noop(); |
49
|
|
|
$log->addWriter($writer); |
50
|
|
|
} else { |
51
|
|
|
$log = $serviceLocator->get($logName); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @var WorkflowServiceInterface $workflowService */ |
55
|
|
|
$workflowService = $serviceLocator->get(Workflow::class); |
56
|
|
|
|
57
|
|
|
$options = [ |
58
|
|
|
'metadataReader' => $reader, |
59
|
|
|
'workflowService' => $workflowService, |
60
|
|
|
'log' => $log |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
return new RouteHandler($options); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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.