Index: branches/5.2.x/core/install/install_data.sql
===================================================================
diff -u -N -r15738 -r15747
--- branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 15738)
+++ branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 15747)
@@ -1032,5 +1032,5 @@
INSERT INTO PromoBlockGroups VALUES (DEFAULT, 'Default Group', UNIX_TIMESTAMP(), '1', '7.00', '0.60', '1', 'fade', '');
-INSERT INTO Modules VALUES ('Core', 'core/', 'adm', DEFAULT, 1, 1, '', 0, NULL, NULL);
-INSERT INTO Modules VALUES ('In-Portal', 'core/', 'm', DEFAULT, 1, 0, '', 0, NULL, NULL);
\ No newline at end of file
+INSERT INTO Modules VALUES ('Core', 'core/', 'Intechnic\\InPortal\\Core', 'adm', DEFAULT, 1, 1, '', 0, NULL, NULL);
+INSERT INTO Modules VALUES ('In-Portal', 'core/', 'Intechnic\\InPortal\\Core', 'm', DEFAULT, 1, 0, '', 0, NULL, NULL);
\ No newline at end of file
Index: branches/5.2.x/core/install/install_schema.sql
===================================================================
diff -u -N -r15608 -r15747
--- branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 15608)
+++ branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 15747)
@@ -194,6 +194,7 @@
CREATE TABLE Modules (
`Name` varchar(255) NOT NULL DEFAULT '',
Path varchar(255) NOT NULL DEFAULT '',
+ ClassNamespace varchar(255) NOT NULL DEFAULT '',
Var varchar(100) NOT NULL DEFAULT '',
Version varchar(10) NOT NULL DEFAULT '0.0.0',
Loaded tinyint(4) NOT NULL DEFAULT '1',
Index: branches/5.2.x/core/install/upgrades.sql
===================================================================
diff -u -N -r15739 -r15747
--- branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15739)
+++ branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15747)
@@ -2879,3 +2879,8 @@
# ===== v 5.2.1-B2 =====
DELETE FROM LanguageLabels WHERE PhraseKey = 'LA_TAB_REPORTS';
+ALTER TABLE Modules ADD ClassNamespace VARCHAR(255) NOT NULL DEFAULT '' AFTER Path;
+
+UPDATE Modules
+SET ClassNamespace = 'Intechnic\\InPortal\\Core'
+WHERE `Name` IN ('Core', 'In-Portal');
Index: branches/5.2.x/core/units/modules/modules_config.php
===================================================================
diff -u -N -r15107 -r15747
--- branches/5.2.x/core/units/modules/modules_config.php (.../modules_config.php) (revision 15107)
+++ branches/5.2.x/core/units/modules/modules_config.php (.../modules_config.php) (revision 15747)
@@ -1,6 +1,6 @@
Array(
'Name' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
'Path' => Array('type' => 'string','not_null' => '1','default' => ''),
+ 'ClassNamespace' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
'Var' => Array('type' => 'string','not_null' => '1','default' => ''),
'Version' => Array('type' => 'string','not_null' => '1','default' => '0.0.0'),
'Loaded' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array(1 => 'la_Active', 0 => 'la_Disabled'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1),
Index: branches/5.2.x/core/kernel/utility/factory.php
===================================================================
diff -u -N -r15420 -r15747
--- branches/5.2.x/core/kernel/utility/factory.php (.../factory.php) (revision 15420)
+++ branches/5.2.x/core/kernel/utility/factory.php (.../factory.php) (revision 15747)
@@ -1,6 +1,6 @@
Files = $data['Factory.Files'];
+ $this->classMap = $data['Factory.Files'];
$this->realClasses = $data['Factory.realClasses'];
}
/**
* Performs automatic loading of classes registered with the factory
*
- * @param string $class_name
- * @return void
- * @throws kFactoryException
+ * @param string $class
+ * @return bool|null
* @access public
*/
- public function autoload($class_name)
+ public function autoload($class)
{
- if ( !isset($this->Files[$class_name]) ) {
- // class not from our factory -> let other autoloaders handle it
- return;
+ $file = $this->findFile($class);
+
+ if ( $file ) {
+ kUtil::includeOnce(FULL_PATH . $file);
+
+ return true;
}
- if ( !file_exists(FULL_PATH . $this->Files[$class_name]) ) {
- throw new kFactoryException('File ' . FULL_PATH . $this->Files[$class_name] . ' containing class ' . $class_name . ' definition not found');
+ return null;
+ }
+
+ /**
+ * Finds the path to the file where the class is defined.
+ *
+ * @param string $class The name of the class
+ * @return string|bool The path if found, false otherwise
+ * @access protected
+ */
+ protected function findFile($class)
+ {
+ if ( $class[0] == '\\' ) {
+ $class = substr($class, 1);
}
- kUtil::includeOnce(FULL_PATH . $this->Files[$class_name]);
+ if ( isset($this->classMap[$class]) ) {
+ return $this->classMap[$class];
+ }
+
+ $pos = strrpos($class, '\\');
+
+ if ( $pos !== false ) {
+ // namespaced class name
+ $class_path = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
+ $class_name = substr($class, $pos + 1);
+ }
+ else {
+ // PEAR-like class name
+ $class_path = null;
+ $class_name = $class;
+ }
+
+ $class_path .= str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
+
+ foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
+ if ( $module_name == 'In-Portal' ) {
+ continue;
+ }
+
+ if ( strpos($class, $module_info['ClassNamespace']) === 0 ) {
+ $test_class_path = str_replace(
+ str_replace('\\', DIRECTORY_SEPARATOR, $module_info['ClassNamespace']),
+ rtrim($module_info['Path'], '/'),
+ $class_path
+ );
+
+ if ( file_exists(FULL_PATH . DIRECTORY_SEPARATOR . $test_class_path) ) {
+ return DIRECTORY_SEPARATOR . $test_class_path;
+ }
+ }
+ }
+
+ return $this->classMap[$class] = false;
}
/**
@@ -95,7 +146,7 @@
public function getToCache()
{
return Array (
- 'Factory.Files' => $this->Files,
+ 'Factory.Files' => $this->classMap,
'Factory.realClasses' => $this->realClasses,
);
}
@@ -269,8 +320,8 @@
$pseudo_class = $real_class;
}
- if ( !isset($this->Files[$real_class]) ) {
- $this->Files[$real_class] = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $file, 1);
+ if ( !isset($this->classMap[$real_class]) ) {
+ $this->classMap[$real_class] = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $file, 1);
}
$this->realClasses[$pseudo_class] = $real_class;
@@ -286,7 +337,7 @@
*/
public function unregisterClass($real_class, $pseudo_class = null)
{
- unset($this->Files[$real_class]);
+ unset($this->classMap[$real_class]);
}
}