|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Composite Utils package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Emily Shepherd <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the |
|
8
|
|
|
* LICENSE.md file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @package spaark/composite-utils |
|
11
|
|
|
* @author Emily Shepherd <[email protected]> |
|
12
|
|
|
* @license MIT |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Spaark\CompositeUtils\Factory\Reflection; |
|
16
|
|
|
|
|
17
|
|
|
use Spaark\CompositeUtils\Model\Reflection\ReflectionComposite; |
|
18
|
|
|
use Spaark\CompositeUtils\Model\Reflection\ReflectionMethod; |
|
19
|
|
|
use \ReflectionMethod as PHPNativeReflectionMethod; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Builds a ReflectionMethod for a given method and optionally links |
|
23
|
|
|
* this to a parent ReflectionComposite |
|
24
|
|
|
*/ |
|
25
|
|
|
class ReflectionMethodFactory extends ReflectorFactory |
|
26
|
|
|
{ |
|
27
|
|
|
const REFLECTION_OBJECT = ReflectionMethod::class; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var PHPNativeReflectionMethod |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $reflector; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ReflectionMethod |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $object; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Returns a new ReflectionMethodFactory using the given class and |
|
41
|
|
|
* method names |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $class The classname of the method |
|
44
|
|
|
* @param string $method The method to reflect |
|
45
|
|
|
* @return ReflectionMethodFactory |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function fromName(string $class, string $method) |
|
48
|
|
|
{ |
|
49
|
|
|
return new static(new PHPNativeReflectionMethod |
|
50
|
|
|
( |
|
51
|
|
|
$class, $method |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Builds the ReflectionMethod from the provided parameters, |
|
57
|
|
|
* optionally linking to a parent ReflectionComposite |
|
58
|
|
|
* |
|
59
|
|
|
* @param ReflectionComposite $parent The reflector for the class |
|
60
|
|
|
* this method belongs to |
|
61
|
|
|
* @return ReflectionMethod |
|
62
|
|
|
*/ |
|
63
|
19 |
|
public function build(?ReflectionComposite $parent = null) |
|
64
|
|
|
{ |
|
65
|
19 |
|
$this->accessor->setRawValue('owner', $parent); |
|
66
|
19 |
|
$this->accessor->setRawValue |
|
67
|
|
|
( |
|
68
|
19 |
|
'name', |
|
69
|
19 |
|
$this->reflector->getName() |
|
|
|
|
|
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
19 |
|
return $this->object; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|