1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under AGPL, Commercial license. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/addendum |
7
|
|
|
* @licence AGPL, Commercial |
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes) |
9
|
|
|
* @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes) |
10
|
|
|
* @copyright Copyright (c) Jan Suchal (Original version, builder, parser) |
11
|
|
|
* @link https://maslosoft.com/addendum/ - maslosoft addendum |
12
|
|
|
* @link https://code.google.com/p/addendum/ - original addendum project |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Maslosoft\Addendum\Utilities; |
16
|
|
|
|
17
|
|
|
use Exception; |
18
|
|
|
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedClass; |
19
|
|
|
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod; |
20
|
|
|
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* ReflectionHelper |
24
|
|
|
* |
25
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
26
|
|
|
*/ |
27
|
|
|
class ReflectionHelper |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get reflection class. |
32
|
|
|
* @param ReflectionAnnotatedClass|ReflectionAnnotatedProperty|ReflectionAnnotatedMethod $reflection Reflection |
33
|
|
|
* @return ReflectionAnnotatedClass |
34
|
|
|
* @throws Exception |
35
|
|
|
*/ |
36
|
15 |
|
public static function getReflectionClass($reflection) |
37
|
|
|
{ |
38
|
15 |
|
if (null === $reflection) |
39
|
15 |
|
{ |
40
|
|
|
throw new Exception(sprintf('No reflection class for matcher `%s`', get_class($this))); |
|
|
|
|
41
|
|
|
} |
42
|
15 |
|
if ($reflection instanceof ReflectionAnnotatedMethod) |
43
|
15 |
|
{ |
44
|
|
|
return $reflection->getDeclaringClass(); |
45
|
|
|
} |
46
|
15 |
|
if ($reflection instanceof ReflectionAnnotatedProperty) |
47
|
15 |
|
{ |
48
|
6 |
|
return $reflection->getDeclaringClass(); |
49
|
|
|
} |
50
|
9 |
|
return $reflection; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|