commit 3c2a89797f88c34a1f11d11cf315c65fc6248779
parent d2517d13fff42437aebec9a6e72bac6a49e6d1a4
Author: mtrnord <mtrnord1@gmail.com>
Date: Sun, 4 Oct 2015 20:43:33 +0200
update bootstrap
Diffstat:
2 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/tests/AutoLoader.php b/tests/AutoLoader.php
@@ -0,0 +1,35 @@
+<?php
+class AutoLoader {
+ static private $classNames = array();
+
+ /**
+ * Store the filename (sans extension) & full path of all ".php" files found
+ */
+ public static function registerDirectory($dirName) {
+
+ $di = new DirectoryIterator($dirName);
+ foreach ($di as $file) {
+ if ($file->isDir() && !$file->isLink() && !$file->isDot()) {
+ // recurse into directories other than a few special ones
+ self::registerDirectory($file->getPathname());
+ } elseif (substr($file->getFilename(), -4) === '.php') {
+ // save the class name / path of a .php file found
+ $className = substr($file->getFilename(), 0, -4);
+ AutoLoader::registerClass($className, $file->getPathname());
+ }
+ }
+ }
+
+ public static function registerClass($className, $fileName) {
+ AutoLoader::$classNames[$className] = $fileName;
+ }
+
+ public static function loadClass($className) {
+ if (isset(AutoLoader::$classNames[$className])) {
+ require_once(AutoLoader::$classNames[$className]);
+ }
+ }
+
+ }
+
+ spl_autoload_register(array('AutoLoader', 'loadClass'));
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
@@ -1,10 +1,4 @@
<?php
-function loader($class)
-{
- $file = $class . '.php';
- if (file_exists($file)) {
- require $file;
- }
-}
-spl_autoload_register('loader');
+include_once('AutoLoader.php');
+AutoLoader::registerDirectory('.');