1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\View\Traits; |
4
|
|
|
|
5
|
|
|
use League\Pipeline\InterruptibleProcessor; |
6
|
|
|
use Nip\View\Methods\Pipeline\MethodCall; |
7
|
|
|
use Nip\View\Methods\Pipeline\MethodsPipelineBuilder as PipelineBuilder; |
8
|
|
|
use Nip\View\Methods\Pipeline\Stages\StageInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Trait MethodsOverloadingTrait |
12
|
|
|
* @package Nip\View\Traits |
13
|
|
|
*/ |
14
|
|
|
trait MethodsOverloadingTrait |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var null|PipelineBuilder |
18
|
|
|
*/ |
19
|
|
|
protected $callPipelineBuilder = null; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param $method |
23
|
|
|
* @param array $args |
24
|
|
|
* @return mixed |
25
|
|
|
*/ |
26
|
2 |
|
public function __call($method, array $args) |
27
|
|
|
{ |
28
|
2 |
|
$methodReturn = $this->processCallPipeline($method, $args); |
29
|
2 |
|
if ($methodReturn->hasReturn()) { |
30
|
2 |
|
return $methodReturn->getReturn(); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
throw new \BadMethodCallException("No method {$method} found for view engine."); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $method |
37
|
|
|
* @param array $arguments |
38
|
|
|
* @return MethodCall |
39
|
|
|
*/ |
40
|
2 |
|
public function processCallPipeline($method, array $arguments) |
41
|
|
|
{ |
42
|
2 |
|
$pipeline = $this->buildCallPipeline(); |
43
|
2 |
|
return $pipeline->process((new MethodCall($this, $method, $arguments))); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return \League\Pipeline\PipelineInterface|\League\Pipeline\Pipeline |
48
|
|
|
*/ |
49
|
2 |
|
protected function buildCallPipeline() |
50
|
|
|
{ |
51
|
2 |
|
return $this->getCallPipelineBuilder()->build( |
52
|
|
|
( |
53
|
2 |
|
new InterruptibleProcessor(function (MethodCall $method) { |
54
|
2 |
|
return !$method->hasReturn(); |
55
|
2 |
|
}) |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return PipelineBuilder |
62
|
|
|
*/ |
63
|
6 |
|
public function getCallPipelineBuilder() |
64
|
|
|
{ |
65
|
6 |
|
if ($this->callPipelineBuilder === null) { |
66
|
6 |
|
$this->initCallPipeline(); |
67
|
|
|
} |
68
|
6 |
|
return $this->callPipelineBuilder; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param StageInterface $stage |
73
|
|
|
*/ |
74
|
6 |
|
public function addCallPipeline(StageInterface $stage) |
75
|
|
|
{ |
76
|
6 |
|
$this->getCallPipelineBuilder()->add($stage); |
77
|
6 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param PipelineBuilder $callPipelineBuilder |
81
|
|
|
*/ |
82
|
|
|
public function setCallPipelineBuilder(PipelineBuilder $callPipelineBuilder): void |
83
|
|
|
{ |
84
|
|
|
$this->callPipelineBuilder = $callPipelineBuilder; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
6 |
|
public function initCallPipeline() |
89
|
|
|
{ |
90
|
6 |
|
$this->callPipelineBuilder = (new PipelineBuilder); |
91
|
6 |
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.