Factory method support

Currently I'm working on some Open Source CMS, which is quite old. It works with PHP 5.2+, so there is no namespaces, traits and any other new PHP features in the code. The script has a superglobal object named $iaCore. It's visible almost everywhere in the source and within this class (iaCore) there is a few factory methods implemented. Here's the main one:

 
public function factory($name, $type = self::CORE)
{
   $result = null;
   if
(is_string($name))
   {
      $className = self::CLASSNAME_PREFIX . ucfirst(strtolower($name));
      if
(isset($this->_classInstances[$className]))
      {
         $result = $this->_classInstances[$className];
      
}
      else
      
{
         iaSystem::renderTime('class', 'Loading class ' . $className);
         $fileSize = $this->loadClass
($type, (strtolower($name) == 'db') ? INTELLI_CONNECT : $name);
         if
(false === $fileSize)
         {
            return false;
         
}

         iaDebug::debug('ia.' . $type . '.' . $name . iaSystem::EXECUTABLE_FILE_EXT . ' (' . iaSystem::byteView($fileSize) . ')', 'Initialized Classes List', 'info');

         $result = new $className
();
         $result->init
();

         $this->_classInstances
[$className] = $result;
      
}
   }
   elseif (is_array($name))
   {
      $result = array();
      foreach
($name as $className)
      {
         $result[] = $this->factory($className, $type);
      
}
   }

   return $result;
}
 
public function loadClass($type = self::CORE, $className = '', $pluginName = null, $packageName = null)
{
   $name = strtolower($className);
   $filename = iaSystem::CLASSES_PREFIX . $type . '.' . $name . iaSystem::EXECUTABLE_FILE_EXT;

   if
($packageName)
   {
      $classFile = IA_PACKAGES . $packageName . IA_DS . 'includes' . IA_DS . 'classes' . IA_DS . $filename;
   
}
   elseif ($pluginName)
   {
      $classFile = IA_PLUGINS . $pluginName . IA_DS . 'includes' . IA_DS . 'classes' . IA_DS . $filename;
   
}
   else
   
{
      $classFile = IA_CLASSES . $filename;
   
}

   if (file_exists($classFile))
   {
      include_once $classFile;

      return filesize
($classFile);
   
}

   return false;
}



and usage is like this:

 
$iaUtil = $iaCore->factory('util');


My questions are:

1) How to make $iaCore object to be visible i.e. when I click on it with Ctrl key pressed it will open iaCore class, it works perfectly with static methods, static properties and constants, by the way?
2) How to make the same result with any objects, instantiated with factory method?

Any help is appreciated.

Thank you.

Please sign in to leave a comment.