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\Matcher; |
16
|
|
|
|
17
|
|
|
use Maslosoft\Addendum\Exceptions\ClassNotFoundException; |
18
|
|
|
use Maslosoft\Addendum\Interfaces\Matcher\MatcherInterface; |
19
|
|
|
use Maslosoft\Addendum\Matcher\Helpers\Processor; |
20
|
|
|
use Maslosoft\Addendum\Utilities\ClassChecker; |
21
|
|
|
|
22
|
|
|
class StaticConstantMatcher extends RegexMatcher implements MatcherInterface |
23
|
|
|
{ |
24
|
|
|
|
25
|
50 |
|
public function __construct() |
26
|
|
|
{ |
27
|
50 |
|
parent::__construct('([\w\\\]+::\w+)'); |
28
|
50 |
|
} |
29
|
|
|
|
30
|
6 |
|
protected function process($matches) |
31
|
|
|
{ |
32
|
6 |
|
$value = $matches[1]; |
33
|
6 |
|
$parts = explode('::', $value); |
34
|
6 |
|
$className = $parts[0]; |
35
|
6 |
|
$constName = $parts[1]; |
36
|
6 |
|
$className = Processor::process($this, $className); |
37
|
6 |
|
$value = sprintf('%s::%s', $className, $constName); |
38
|
6 |
|
$value = Processor::process($this, $value); |
39
|
6 |
|
if ($className !== 'self' && $className !== 'static') |
40
|
|
|
{ |
41
|
6 |
|
if (!ClassChecker::exists($className)) |
42
|
|
|
{ |
43
|
|
|
throw new ClassNotFoundException("Class $className not found while parsing annotations"); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
6 |
|
if($constName === 'class' && $value === $className) |
48
|
|
|
{ |
49
|
2 |
|
return $value; |
50
|
|
|
} |
51
|
|
|
|
52
|
5 |
|
if (!defined($value)) |
53
|
|
|
{ |
54
|
|
|
return false; |
55
|
|
|
} |
56
|
5 |
|
return constant($value); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|