Updating classloading for normal and Rest, requests

This commit is contained in:
Erik Amaru Ortiz
2014-03-14 11:57:27 -04:00
parent 8e9b30f706
commit dad40d77f6
5 changed files with 252 additions and 332 deletions

View File

@@ -5,6 +5,8 @@ class ClassLoader
{
private static $includePath = array();
private static $includePathNs = array();
private static $includeModelPath = array();
private static $includeClassPath = array();
protected static $instance;
/**
@@ -60,6 +62,22 @@ class ClassLoader
}
}
public function addModelClassPath($classPath)
{
self::$includeModelPath[] = $classPath;
}
public function addClass($class, $path)
{
self::$includeClassPath[$class] = $path;
}
/**
* Loads the given class or interface.
*
* @param string $className The name of the class to load.
* @return void
*/
function loadClass($className)
{
$classPath = str_replace(NS, DS, $className);
@@ -78,9 +96,25 @@ class ClassLoader
}
}
if (isset(self::$includeClassPath[$className]) && file_exists(self::$includeClassPath[$className])) {
require self::$includeClassPath[$className];
}
foreach (self::$includeModelPath as $path) {
if (file_exists($path.$className.".php")) {
require $path.$className.".php";
return true;
} elseif (file_exists($path."om".DS.$className.".php")) {
require $path."om".DS.$className.".php";
return true;
} elseif (file_exists($path."map".DS.$className.".php")) {
require $path."map".DS.$className.".php";
return true;
}
}
foreach (self::$includePath as $path) {
$filename = $path . $classPath . ".php";
//var_dump($filename);
if (file_exists($filename)) {
require $filename;
@@ -91,27 +125,6 @@ class ClassLoader
return false;
}
/**
* Loads the given class or interface.
*
* @param string $className The name of the class to load.
* @return void
*/
public function loadClass2($className)
{
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
$fileName = '';
$namespace = '';
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
}
}
}

View File

@@ -257,6 +257,7 @@ class WebApplication
define('PATH_RBAC', PATH_RBAC_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP); //to enable rbac version 2
define('PATH_RBAC_CORE', PATH_RBAC_HOME . 'engine' . PATH_SEP);
define('PATH_CORE', PATH_HOME . 'engine' . PATH_SEP);
define('PATH_CLASSES', PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP);
define('PATH_SKINS', PATH_CORE . 'skins' . PATH_SEP);
define('PATH_SKIN_ENGINE', PATH_CORE . 'skinEngine' . PATH_SEP);
define('PATH_METHODS', PATH_CORE . 'methods' . PATH_SEP);
@@ -283,18 +284,17 @@ class WebApplication
spl_autoload_register(array("Bootstrap", "autoloadClass"));
\Bootstrap::registerClass("G", PATH_GULLIVER . "class.g.php");
\Bootstrap::registerClass("System", PATH_HOME . "engine/classes/class.system.php");
// \Bootstrap::registerClass("G", PATH_GULLIVER . "class.g.php");
// \Bootstrap::registerClass("System", PATH_HOME . "engine/classes/class.system.php");
// define autoloading for others
\Bootstrap::registerClass("wsBase", PATH_HOME . "engine/classes/class.wsBase.php");
\Bootstrap::registerClass('Xml_Node', PATH_GULLIVER . "class.xmlDocument.php");
\Bootstrap::registerClass('XmlForm_Field_TextPM', PATH_HOME . "engine/classes/class.XmlForm_Field_TextPM.php");
\Bootstrap::registerClass('XmlForm_Field_SimpleText', PATH_GULLIVER . "class.xmlformExtension.php");
\Bootstrap::registerClass('XmlForm_Field', PATH_GULLIVER . "class.xmlform.php");
// \Bootstrap::registerClass("wsBase", PATH_HOME . "engine/classes/class.wsBase.php");
// \Bootstrap::registerClass('Xml_Node', PATH_GULLIVER . "class.xmlDocument.php");
// \Bootstrap::registerClass('XmlForm_Field_TextPM', PATH_HOME . "engine/classes/class.XmlForm_Field_TextPM.php");
// \Bootstrap::registerClass('XmlForm_Field_SimpleText', PATH_GULLIVER . "class.xmlformExtension.php");
// \Bootstrap::registerClass('XmlForm_Field', PATH_GULLIVER . "class.xmlform.php");
//\Bootstrap::registerDir('model', PATH_CORE . 'classes' . PATH_SEP . 'model');
//\Bootstrap::registerDir('rbac/model', PATH_RBAC_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP . 'model');
//\Bootstrap::LoadThirdParty("smarty/libs", "Smarty.class");
@@ -319,7 +319,6 @@ class WebApplication
define('MEMCACHED_SERVER', $config['memcached_server']);
define('TIME_ZONE', $config['time_zone']);
// set include path
set_include_path(
PATH_CORE . PATH_SEPARATOR .
@@ -335,7 +334,7 @@ class WebApplication
*/
// include the server installed configuration
require_once FILE_PATHS_INSTALLED;
require_once PATH_CORE . 'config' . PATH_SEP . 'paths_installed.php';
define('SYS_SYS', $workspace);
@@ -373,7 +372,7 @@ class WebApplication
}
// create memcached singleton
\Bootstrap::LoadClass('memcached');
//\Bootstrap::LoadClass('memcached');
//$memcache = PMmemcached::getSingleton( SYS_SYS );
\Propel::init(PATH_CONFIG . "databases.php");