21
21
*/
22
22
class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializable
23
23
{
24
- const EXISTS_OK = 1 ;
25
- const EXISTS_KO = 0 ;
26
- const EXISTS_KO_WITH_THROWING_AUTOLOADER = -1 ;
27
-
28
24
private $ resource ;
29
- private $ existsStatus ;
25
+ private $ exists ;
30
26
31
27
private static $ autoloadLevel = 0 ;
32
28
private static $ existsCache = array ();
33
29
34
30
/**
35
- * @param string $resource The fully-qualified class name
36
- * @param int |null $existsStatus One of the self::EXISTS_* const if the existency check has already been done
31
+ * @param string $resource The fully-qualified class name
32
+ * @param bool |null $exists Boolean when the existency check has already been done
37
33
*/
38
- public function __construct ($ resource , $ existsStatus = null )
34
+ public function __construct ($ resource , $ exists = null )
39
35
{
40
36
$ this ->resource = $ resource ;
41
- if (null !== $ existsStatus ) {
42
- $ this ->existsStatus = (int ) $ existsStatus ;
37
+ if (null !== $ exists ) {
38
+ $ this ->exists = (bool ) $ exists ;
43
39
}
44
40
}
45
41
@@ -64,11 +60,13 @@ public function getResource()
64
60
*/
65
61
public function isFresh ($ timestamp )
66
62
{
63
+ $ loaded = class_exists ($ this ->resource , false ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
64
+
67
65
if (null !== $ exists = &self ::$ existsCache [$ this ->resource ]) {
68
- $ exists = $ exists || class_exists ( $ this -> resource , false ) || interface_exists ( $ this -> resource , false ) || trait_exists ( $ this -> resource , false ) ;
69
- } elseif (self :: EXISTS_KO_WITH_THROWING_AUTOLOADER === $ this -> existsStatus ) {
66
+ $ exists = $ exists || $ loaded ;
67
+ } elseif (! $ exists = $ loaded ) {
70
68
if (!self ::$ autoloadLevel ++) {
71
- spl_autoload_register (' Symfony\Component\Config\Resource\ClassExistenceResource ::throwOnRequiredClass ' );
69
+ spl_autoload_register (__CLASS__ . ' ::throwOnRequiredClass ' );
72
70
}
73
71
74
72
try {
@@ -77,38 +75,36 @@ public function isFresh($timestamp)
77
75
$ exists = false ;
78
76
} finally {
79
77
if (!--self ::$ autoloadLevel ) {
80
- spl_autoload_unregister (' Symfony\Component\Config\Resource\ClassExistenceResource ::throwOnRequiredClass ' );
78
+ spl_autoload_unregister (__CLASS__ . ' ::throwOnRequiredClass ' );
81
79
}
82
80
}
83
- } else {
84
- $ exists = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
85
81
}
86
82
87
- if (null === $ this ->existsStatus ) {
88
- $ this ->existsStatus = $ exists ? self :: EXISTS_OK : self :: EXISTS_KO ;
83
+ if (null === $ this ->exists ) {
84
+ $ this ->exists = $ exists ;
89
85
}
90
86
91
- return self :: EXISTS_OK === $ this ->existsStatus xor !$ exists ;
87
+ return $ this ->exists xor !$ exists ;
92
88
}
93
89
94
90
/**
95
91
* {@inheritdoc}
96
92
*/
97
93
public function serialize ()
98
94
{
99
- if (null === $ this ->existsStatus ) {
95
+ if (null === $ this ->exists ) {
100
96
$ this ->isFresh (0 );
101
97
}
102
98
103
- return serialize (array ($ this ->resource , $ this ->existsStatus ));
99
+ return serialize (array ($ this ->resource , $ this ->exists ));
104
100
}
105
101
106
102
/**
107
103
* {@inheritdoc}
108
104
*/
109
105
public function unserialize ($ serialized )
110
106
{
111
- list ($ this ->resource , $ this ->existsStatus ) = unserialize ($ serialized );
107
+ list ($ this ->resource , $ this ->exists ) = unserialize ($ serialized );
112
108
}
113
109
114
110
/**
0 commit comments