Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ClassLoader] created protected findFile() method to allow creating a…

… cache layer via inheritance
  • Loading branch information...
commit 608bce3ef1bcffc3e0776a97ed0e2b82a5145b83 1 parent 7567a77
@kriswallsmith kriswallsmith authored
Showing with 19 additions and 9 deletions.
  1. +19 −9 UniversalClassLoader.php
View
28 UniversalClassLoader.php
@@ -182,11 +182,25 @@ public function register($prepend = false)
*/
public function loadClass($class)
{
+ if ($file = $this->findFile($class)) {
+ require $file;
+ }
+ }
+
+ /**
+ * Finds the path to the file where the class is defined.
+ *
+ * @param string $class The name of the class
+ *
+ * @return string|null The path, if found
+ */
+ protected function findFile($class)
+ {
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
- if (false !== ($pos = strrpos($class, '\\'))) {
+ if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$namespace = substr($class, 0, $pos);
foreach ($this->namespaces as $ns => $dirs) {
@@ -195,8 +209,7 @@ public function loadClass($class)
$className = substr($class, $pos + 1);
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
if (file_exists($file)) {
- require $file;
- return;
+ return $file;
}
}
}
@@ -205,8 +218,7 @@ public function loadClass($class)
foreach ($this->namespaceFallback as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($file)) {
- require $file;
- return;
+ return $file;
}
}
} else {
@@ -216,8 +228,7 @@ public function loadClass($class)
if (0 === strpos($class, $prefix)) {
$file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($file)) {
- require $file;
- return;
+ return $file;
}
}
}
@@ -226,8 +237,7 @@ public function loadClass($class)
foreach ($this->prefixFallback as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($file)) {
- require $file;
- return;
+ return $file;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.