|
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\Interfaces\Plugins\Matcher\MatcherClassNotFoundHandlerInterface; |
|
20
|
|
|
use Maslosoft\Addendum\Matcher\Helpers\Processor; |
|
21
|
|
|
use Maslosoft\Addendum\Matcher\Traits\PluginsTrait; |
|
22
|
|
|
use Maslosoft\Addendum\Utilities\ClassChecker; |
|
23
|
|
|
use Maslosoft\Addendum\Utilities\ReflectionName; |
|
24
|
|
|
use Maslosoft\Gazebo\PluginFactory; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ClassLiteralMatcher |
|
28
|
|
|
* |
|
29
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
30
|
|
|
*/ |
|
31
|
|
|
class ClassLiteralMatcher implements MatcherInterface |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
use PluginsTrait; |
|
35
|
|
|
|
|
36
|
14 |
|
protected function process($matches) |
|
37
|
|
|
{ |
|
38
|
14 |
|
return Processor::process($this, $matches[1]); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
44 |
|
public function matches($string, &$value) |
|
42
|
|
|
{ |
|
43
|
44 |
|
$matches = []; |
|
44
|
44 |
|
$regex = '([A-Z\\\][a-zA-Z0-9_\\\]+)'; |
|
45
|
44 |
|
if (preg_match("/^{$regex}/", $string, $matches)) |
|
46
|
44 |
|
{ |
|
47
|
14 |
|
$value = $this->process($matches); |
|
48
|
14 |
|
if (!ClassChecker::exists($value)) |
|
49
|
14 |
|
{ |
|
50
|
|
|
// Might be constant... |
|
51
|
4 |
|
if (!defined($matches[0])) |
|
52
|
4 |
|
{ |
|
53
|
1 |
|
$name = ReflectionName::createName($this->getPlugins()->reflection); |
|
54
|
|
|
|
|
55
|
|
|
$params = [ |
|
56
|
1 |
|
$matches[0], |
|
57
|
1 |
|
$name, |
|
58
|
|
|
$string |
|
59
|
1 |
|
]; |
|
60
|
1 |
|
$plugins = $this->getPlugins()->addendum->plugins->matcher; |
|
61
|
|
|
|
|
62
|
1 |
|
$instances = PluginFactory::fly()->create($plugins, $this, MatcherClassNotFoundHandlerInterface::class); |
|
63
|
|
|
|
|
64
|
|
|
/* @var $instances MatcherClassNotFoundHandlerInterface[] */ |
|
65
|
|
|
|
|
66
|
1 |
|
foreach($instances as $ignorer) |
|
67
|
|
|
{ |
|
68
|
1 |
|
if($ignorer->shouldSkip($matches[0])) |
|
69
|
1 |
|
{ |
|
70
|
1 |
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
throw new ClassNotFoundException(vsprintf("Could not find class %s, when processing annotations on %s, near %s", $params)); |
|
74
|
|
|
} |
|
75
|
3 |
|
return false; |
|
76
|
|
|
} |
|
77
|
11 |
|
return strlen($matches[0]); |
|
78
|
|
|
} |
|
79
|
39 |
|
$value = false; |
|
80
|
39 |
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|