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 http://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\Matcher\Traits\PluginsTrait; |
21
|
|
|
use Maslosoft\Addendum\Utilities\ClassChecker; |
22
|
|
|
use Maslosoft\Addendum\Utilities\ReflectionName; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* ClassLiteralMatcher |
26
|
|
|
* |
27
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
28
|
|
|
*/ |
29
|
|
|
class ClassLiteralMatcher implements MatcherInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
use PluginsTrait; |
33
|
|
|
|
34
|
12 |
|
protected function process($matches) |
35
|
|
|
{ |
36
|
12 |
|
return Processor::process($this, $matches[1]); |
37
|
|
|
} |
38
|
|
|
|
39
|
39 |
|
public function matches($string, &$value) |
40
|
|
|
{ |
41
|
39 |
|
$matches = []; |
42
|
39 |
|
$regex = '([A-Z\\\][a-zA-Z0-9_\\\]+)'; |
43
|
39 |
|
if (preg_match("/^{$regex}/", $string, $matches)) |
44
|
|
|
{ |
45
|
12 |
|
$value = $this->process($matches); |
46
|
12 |
|
if (!ClassChecker::exists($value)) |
47
|
|
|
{ |
48
|
|
|
// Might be constant... |
49
|
2 |
|
if (!defined($matches[0])) |
50
|
|
|
{ |
51
|
|
|
$name = ReflectionName::createName($this->getPlugins()->reflection); |
52
|
|
|
|
53
|
|
|
$params = [ |
54
|
|
|
$matches[0], |
55
|
|
|
$name, |
56
|
|
|
$string |
57
|
|
|
]; |
58
|
|
|
throw new ClassNotFoundException(vsprintf("Could not find class %s, when processing annotations on %s, near %s", $params)); |
59
|
|
|
} |
60
|
2 |
|
return false; |
61
|
|
|
} |
62
|
11 |
|
return strlen($matches[0]); |
63
|
|
|
} |
64
|
35 |
|
$value = false; |
65
|
35 |
|
return false; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|