Permalink
Browse files

Added auto loading capabilities

  • Loading branch information...
clphillips committed Feb 11, 2015
1 parent 34f812a commit aaf09a470f8fd7146a370e35d641a60bc6d3c6d9
View
@@ -0,0 +1,2 @@
<?php
spl_autoload_register(array('Loader', 'autoload'), true, true);
View
@@ -112,20 +112,11 @@
*/
define("VENDORDIR", ROOTWEBDIR . "vendors" . DS);
// Include core libraries
include_once LIBDIR . "unknown_exception.php";
include_once LIBDIR . "stdlib.php";
include_once LIBDIR . "configure.php";
include_once LIBDIR . "router.php";
include_once LIBDIR . "loader.php";
include_once LIBDIR . "autoload.php";
include_once LIBDIR . "stdlib.php";
// Include core configuration
include_once CONFIGDIR . "core.php";
// Include any other dependancies
include_once LIBDIR . "language.php";
include_once LIBDIR . "cache.php";
// Include MVC libraries
include_once LIBDIR . "model.php";
include_once LIBDIR . "view.php";
include_once LIBDIR . "controller.php";
include_once LIBDIR . "dispatcher.php";
?>
View
@@ -14,6 +14,60 @@ protected function __construct() {
}
/**
* Autoload classes
*
* @param string $class
* @return boolean True if loaded, false otherwise
*/
public static function autoload($class) {
// Skip namespaces
if (strpos($class, "\\") !== false) {
return false;
}
$paths = array(
LIBDIR,
ROOTWEBDIR . APPDIR,
CONTROLLERDIR,
MODELDIR,
COMPONENTDIR,
HELPERDIR
);
$plugin = null;
if (($c = strpos($class, "."))) {
$plugin = self::fromCamelCase(substr($class, 0, $c)) . DIRECTORY_SEPARATOR;
$class = substr($class, $c+1);
}
if ($plugin !== null) {
$paths = array(
PLUGINDIR . $plugin,
PLUGINDIR . $plugin . "models" . DIRECTORY_SEPARATOR,
PLUGINDIR . $plugin . "controllers" . DIRECTORY_SEPARATOR,
PLUGINDIR . $plugin . "components" . DIRECTORY_SEPARATOR,
PLUGINDIR . $plugin . "helpers" . DIRECTORY_SEPARATOR
);
}
$class_file = self::fromCamelCase($class);
$file_name = $class_file . ".php";
foreach ($paths as $path) {
if (file_exists($path . $file_name)) {
include $path . $file_name;
return true;
}
elseif (file_exists($path . $class_file . DIRECTORY_SEPARATOR . $file_name)) {
include $path . $class_file . DIRECTORY_SEPARATOR . $file_name;
return true;
}
}
return false;
}
/**
* Loads models, which may or may not exist within a plugin of the same
* name. First looks in the plugin directory, if no match is found, looks
@@ -1,6 +1,4 @@
<?php
require_once SUT_PATH . "app/app_controller.php";
/**
*
*/
@@ -1,6 +1,4 @@
<?php
require_once SUT_PATH . "app/app_model.php";
/**
*
*/
@@ -1,8 +1,3 @@
<?php
// Define the path to the System Under Test
define("SUT_PATH", dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR);
// Set the SUT Path as an include path to ease loading
set_include_path(get_include_path() . PATH_SEPARATOR . SUT_PATH);
require_once "lib" . DIRECTORY_SEPARATOR . "init.php";
?>
$src_path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "src";
require_once $src_path . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "init.php";
View
@@ -1,8 +1,3 @@
<?php
// Define the path to the System Under Test
define("SUT_PATH", dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR);
// Set the SUT Path as an include path to ease loading
set_include_path(get_include_path() . PATH_SEPARATOR . SUT_PATH);
require_once "lib" . DIRECTORY_SEPARATOR . "init.php";
?>
$src_path = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "src";
require_once $src_path . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "init.php";
@@ -1,6 +1,4 @@
<?php
require_once "components" . DIRECTORY_SEPARATOR . "input" . DIRECTORY_SEPARATOR . "input.php";
class InputTest extends PHPUnit_Framework_TestCase
{
@@ -1,6 +1,4 @@
<?php
require_once "components" . DIRECTORY_SEPARATOR . "record" . DIRECTORY_SEPARATOR . "record.php";
class RecordTest extends PHPUnit_Framework_TestCase
{

0 comments on commit aaf09a4

Please sign in to comment.