Index: core/kernel/utility/factory.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/kernel/utility/factory.php (revision 15716)
+++ core/kernel/utility/factory.php (revision )
@@ -17,14 +17,6 @@
class kFactory extends kBase implements kiCacheable {
/**
- * Where all created objects are stored
- *
- * @var Array
- * @access protected
- */
- protected $Storage = Array ();
-
- /**
* Mapping between class name and file name
* where class definition can be found.
* File path absolute!
@@ -32,7 +24,7 @@
* @var Array
* @access protected
*/
- protected $Files = Array ();
+ protected $classMap = Array ();
/**
* Map class names to their pseudo
@@ -44,6 +36,14 @@
*/
protected $realClasses = Array ();
+ /**
+ * Where all created objects are stored
+ *
+ * @var Array|kBase[]
+ * @access protected
+ */
+ protected $Storage = Array ();
+
public function __construct()
{
parent::__construct();
@@ -60,32 +60,83 @@
*/
public function setFromCache(&$data)
{
- $this->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;
- }
+ }
- kUtil::includeOnce(FULL_PATH . $this->Files[$class_name]);
+ /**
+ * 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);
- }
+ }
+ 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;
+ }
+
/**
* Gets object data for caching
*
@@ -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]);
}
}
\ No newline at end of file
Index: core/install/install_data.sql
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/install/install_data.sql (revision 15738)
+++ core/install/install_data.sql (revision )
@@ -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: core/install/upgrades.sql
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/install/upgrades.sql (revision 15739)
+++ core/install/upgrades.sql (revision )
@@ -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: core/units/modules/modules_config.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/modules/modules_config.php (revision 15716)
+++ core/units/modules/modules_config.php (revision )
@@ -83,6 +83,7 @@
'Fields' => 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),
\ No newline at end of file
Index: core/install/install_schema.sql
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/install/install_schema.sql (revision 15716)
+++ core/install/install_schema.sql (revision )
@@ -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',
\ No newline at end of file