Skip to content

Commit

Permalink
Add trait_exists() in addition to class_exists() and interface_exists…
Browse files Browse the repository at this point in the history
…() everywhere, but check function_exists('trait_exists') first. This does also merge in the pull request at #3 by paul-vg. The pull request had the OR pieces broken to multiple lines, which is reasonable.
  • Loading branch information
donquixote committed Jul 10, 2013
2 parents 13b278d + e49c131 commit 78c60a1
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/Krautoload/ClassLoader/Pluggable.php
Expand Up @@ -51,7 +51,10 @@ function loadClass($class) {
else {
// Assume that the file MAY define the class.
include_once $file;
if (class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE)) {
if (class_exists($class, FALSE)
|| interface_exists($class, FALSE)
|| (function_exists('trait_exists') && trait_exists($class, FALSE))
) {
return TRUE;
}
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ protected function includedFileWithClassCandidate($file, $relativeClassName) {
elseif (interface_exists($class, FALSE)) {
$this->confirmedFileWithInterface($file, $class);
}
elseif (trait_exists($class, FALSE)) {
elseif (function_exists('trait_exists') && trait_exists($class, FALSE)) {
$this->confirmedFileWithTrait($file, $class);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Krautoload/InjectedAPI/ClassFinder/LoadClass.php
Expand Up @@ -22,6 +22,9 @@ function claimFile($file) {
*/
function claimFileCandidate($file) {
require_once $file;
return class_exists($this->className, FALSE) || interface_exists($this->className, FALSE) || trait_exists($this->className, FALSE);
return class_exists($this->className, FALSE)
|| interface_exists($this->className, FALSE)
|| (function_exists('trait_exists') && trait_exists($this->className, FALSE))
;
}
}
10 changes: 8 additions & 2 deletions src/Krautoload/InjectedAPI/ClassFinder/LoadClassGetFile.php
Expand Up @@ -34,7 +34,10 @@ function guessFile($file) {
function guessFileCandidate($file) {
if (is_file($file)) {
include_once $file;
if (class_exists($this->className, FALSE) || interface_exists($this->className, FALSE) || trait_exists($class, FALSE)) {
if (class_exists($this->className, FALSE)
|| interface_exists($this->className, FALSE)
|| (function_exists('trait_exists') && trait_exists($this->className, FALSE))
) {
$this->file = $file;
return TRUE;
}
Expand All @@ -55,7 +58,10 @@ function claimFile($file) {
*/
function claimFileCandidate($file) {
require_once $file;
if (class_exists($this->className, FALSE) || interface_exists($this->className, FALSE) || trait_exists($this->className, FALSE)) {
if (class_exists($this->className, FALSE)
|| interface_exists($this->className, FALSE)
|| (function_exists('trait_exists') && trait_exists($this->className, FALSE))
) {
$this->file = $file;
return TRUE;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Krautoload/NamespacePathPlugin/ShallowPSR0.php
Expand Up @@ -37,7 +37,10 @@ function pluginLoadClass($class, $baseDir, $relativePath) {
// We don't know if the file defines the class,
// and whether it was already included.
include_once $file;
return class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE);
return class_exists($class, FALSE)
|| interface_exists($class, FALSE)
|| (function_exists('trait_exists') && trait_exists($class, FALSE))
;
}
}

Expand Down
Expand Up @@ -35,7 +35,10 @@ function pluginLoadClass($class, $baseDir, $relativePath) {
// We don't know if the file exists.
if (FALSE !== $file = Util::findFileInIncludePath($baseDir . $relativePath)) {
include_once $file;
return class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE);
return class_exists($class, FALSE)
|| interface_exists($class, FALSE)
|| (function_exists('trait_exists') && trait_exists($class, FALSE))
;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/Krautoload/PrefixPathPlugin/ShallowPEAR/Uncertain.php
Expand Up @@ -11,7 +11,10 @@ function pluginFindFile($api, $baseDir, $relativePath) {
function pluginLoadClass($class, $baseDir, $relativePath) {
if (is_file($file = $baseDir . $relativePath)) {
include_once $file;
return class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE);
return class_exists($class, FALSE)
|| interface_exists($class, FALSE)
|| (function_exists('trait_exists') && trait_exists($class, FALSE))
;
}
}
}
Expand Up @@ -21,7 +21,10 @@ function pluginLoadClass($class, $baseDir, $relativePath) {
// We don't know if the file exists.
if (FALSE !== $file = Util::findFileInIncludePath($baseDir . $relativePath)) {
include_once $file;
return class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE);
return class_exists($class, FALSE)
|| interface_exists($class, FALSE)
|| (function_exists('trait_exists') && trait_exists($class, FALSE))
;
}
}
}
6 changes: 5 additions & 1 deletion src/Krautoload/Util.php
Expand Up @@ -18,6 +18,7 @@ static function calledFromClassExists() {
case 'class_exists':
case 'interface_exists':
case 'method_exists':
case 'trait_exists':
case 'is_callable':
// @todo Add more cases.
return TRUE;
Expand All @@ -29,7 +30,10 @@ static function calledFromClassExists() {
}

static function classIsDefined($class) {
return class_exists($class, FALSE) || interface_exists($class, FALSE) || trait_exists($class, FALSE);
return class_exists($class, FALSE)
|| interface_exists($class, FALSE)
|| (function_exists('trait_exists') && trait_exists($class, FALSE))
;
}

/**
Expand Down

0 comments on commit 78c60a1

Please sign in to comment.