1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Dispatcher\Resolver\Pipeline; |
4
|
|
|
|
5
|
|
|
use League\Pipeline\InterruptibleProcessor; |
6
|
|
|
use League\Pipeline\PipelineBuilder as AbstractBuilder; |
7
|
|
|
use League\Pipeline\PipelineInterface; |
8
|
|
|
use League\Pipeline\ProcessorInterface; |
9
|
|
|
use Nip\Dispatcher\Commands\Command; |
10
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\ActionCallStage; |
11
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\ClassInstanceStage; |
12
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\ClosureStage; |
13
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\InstanceReturnStage; |
14
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\MethodCallStage; |
15
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\ModuleControllerStage; |
16
|
|
|
use Nip\Dispatcher\Resolver\Pipeline\Stages\RequestStage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class InstanceBuilder |
20
|
|
|
* @package Nip\Dispatcher\Resolver\Pipeline |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class InstanceBuilder extends AbstractBuilder |
|
|
|
|
23
|
|
|
{ |
24
|
1 |
|
public function __construct() |
25
|
|
|
{ |
26
|
1 |
|
$this->add(new ClosureStage()); |
27
|
1 |
|
$this->add(new RequestStage()); |
28
|
1 |
|
$this->add(new ModuleControllerStage()); |
29
|
1 |
|
$this->add(new ClassInstanceStage()); |
30
|
1 |
|
$this->add(new MethodCallStage()); |
31
|
1 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Build a new Pipeline object |
35
|
|
|
* |
36
|
|
|
* @param ProcessorInterface|null $processor |
37
|
|
|
* |
38
|
|
|
* @return PipelineInterface |
39
|
|
|
*/ |
40
|
1 |
|
public function build(ProcessorInterface $processor = null): PipelineInterface |
41
|
|
|
{ |
42
|
1 |
|
if ($processor == null) { |
43
|
1 |
|
$processor = new InterruptibleProcessor( |
44
|
1 |
|
function (Command $command) { |
45
|
|
|
return !$command->hasActionParam('instance'); |
46
|
1 |
|
} |
47
|
|
|
); |
48
|
|
|
} |
49
|
1 |
|
return parent::build($processor); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
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.