2121 */
2222class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializable
2323{
24- const EXISTS_OK = 1 ;
25- const EXISTS_KO = 0 ;
26- const EXISTS_KO_WITH_THROWING_AUTOLOADER = -1 ;
27-
2824 private $ resource ;
29- private $ existsStatus ;
25+ private $ exists ;
3026
3127 private static $ autoloadLevel = 0 ;
3228 private static $ existsCache = array ();
3329
3430 /**
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
3733 */
38- public function __construct ($ resource , $ existsStatus = null )
34+ public function __construct ($ resource , $ exists = null )
3935 {
4036 $ this ->resource = $ resource ;
41- if (null !== $ existsStatus ) {
42- $ this ->existsStatus = (int ) $ existsStatus ;
37+ if (null !== $ exists ) {
38+ $ this ->exists = (bool ) $ exists ;
4339 }
4440 }
4541
@@ -64,11 +60,13 @@ public function getResource()
6460 */
6561 public function isFresh ($ timestamp )
6662 {
63+ $ loaded = class_exists ($ this ->resource , false ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
64+
6765 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 ) {
7068 if (!self ::$ autoloadLevel ++) {
71- spl_autoload_register (' Symfony\Component\Config\Resource\ClassExistenceResource ::throwOnRequiredClass ' );
69+ spl_autoload_register (__CLASS__ . ' ::throwOnRequiredClass ' );
7270 }
7371
7472 try {
@@ -77,38 +75,36 @@ public function isFresh($timestamp)
7775 $ exists = false ;
7876 } finally {
7977 if (!--self ::$ autoloadLevel ) {
80- spl_autoload_unregister (' Symfony\Component\Config\Resource\ClassExistenceResource ::throwOnRequiredClass ' );
78+ spl_autoload_unregister (__CLASS__ . ' ::throwOnRequiredClass ' );
8179 }
8280 }
83- } else {
84- $ exists = class_exists ($ this ->resource ) || interface_exists ($ this ->resource , false ) || trait_exists ($ this ->resource , false );
8581 }
8682
87- if (null === $ this ->existsStatus ) {
88- $ this ->existsStatus = $ exists ? self :: EXISTS_OK : self :: EXISTS_KO ;
83+ if (null === $ this ->exists ) {
84+ $ this ->exists = $ exists ;
8985 }
9086
91- return self :: EXISTS_OK === $ this ->existsStatus xor !$ exists ;
87+ return $ this ->exists xor !$ exists ;
9288 }
9389
9490 /**
9591 * {@inheritdoc}
9692 */
9793 public function serialize ()
9894 {
99- if (null === $ this ->existsStatus ) {
95+ if (null === $ this ->exists ) {
10096 $ this ->isFresh (0 );
10197 }
10298
103- return serialize (array ($ this ->resource , $ this ->existsStatus ));
99+ return serialize (array ($ this ->resource , $ this ->exists ));
104100 }
105101
106102 /**
107103 * {@inheritdoc}
108104 */
109105 public function unserialize ($ serialized )
110106 {
111- list ($ this ->resource , $ this ->existsStatus ) = unserialize ($ serialized );
107+ list ($ this ->resource , $ this ->exists ) = unserialize ($ serialized );
112108 }
113109
114110 /**
0 commit comments