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
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ClassChecker |
21
|
|
|
* |
22
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
23
|
|
|
*/ |
24
|
|
|
class ClassChecker |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Array with existent classes |
29
|
|
|
* @var string[] |
30
|
|
|
*/ |
31
|
|
|
private static $_exists = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Check whenever class is anonymous. |
35
|
|
|
* @param string $class |
36
|
|
|
* @return bool True if class is anonymous |
37
|
|
|
*/ |
38
|
67 |
|
public static function isAnonymous($class) |
39
|
|
|
{ |
40
|
67 |
|
return strpos($class, 'class@anonymous') !== false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Check whenever class or trait or interface exists. |
45
|
|
|
* It does autoload if needed. |
46
|
|
|
* @param string $class |
47
|
|
|
* @return bool True if class or trait or interface exists |
48
|
|
|
*/ |
49
|
65 |
|
public static function exists($class) |
50
|
|
|
{ |
51
|
65 |
|
if (Blacklister::ignores($class)) |
52
|
|
|
{ |
53
|
4 |
|
return false; |
54
|
|
|
} |
55
|
65 |
|
if (self::isConfirmed($class)) |
56
|
|
|
{ |
57
|
65 |
|
return true; |
58
|
|
|
} |
59
|
|
|
try |
60
|
|
|
{ |
61
|
26 |
|
if (@class_exists($class)) |
62
|
|
|
{ |
63
|
26 |
|
return self::confirm($class); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
catch (Exception $ex) |
67
|
|
|
{ |
68
|
|
|
// Some class loaders throw exception if class not found |
69
|
|
|
} |
70
|
|
|
try |
71
|
|
|
{ |
72
|
19 |
|
if (@trait_exists($class)) |
73
|
|
|
{ |
74
|
19 |
|
return self::confirm($class); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
catch (Exception $ex) |
78
|
|
|
{ |
79
|
|
|
// Some class loaders throw exception if class not found |
80
|
|
|
} |
81
|
|
|
try |
82
|
|
|
{ |
83
|
19 |
|
if (@interface_exists($class)) |
84
|
|
|
{ |
85
|
19 |
|
return self::confirm($class); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
catch (Exception $ex) |
89
|
|
|
{ |
90
|
|
|
// Some class loaders throw exception if class not found |
91
|
|
|
} |
92
|
18 |
|
Blacklister::ignore($class); |
93
|
18 |
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
65 |
|
private static function isConfirmed($class) |
97
|
|
|
{ |
98
|
65 |
|
return isset(self::$_exists[$class]); |
99
|
|
|
} |
100
|
|
|
|
101
|
23 |
|
private static function confirm($class) |
102
|
|
|
{ |
103
|
23 |
|
self::$_exists[$class] = true; |
104
|
23 |
|
return true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|