src/Object/ObjectFactory.php
protected function constructObject($objName, &$xmlArr = null)
    {               
        
        if (!$xmlArr) {
            $xmlFile = ObjectFactoryHelper::getXmlFileWithPath($objName);            
            if ($xmlFile) { 
                $xmlArr = ObjectFactoryHelper::getXmlArray($xmlFile);                
            } else {
                
                //$this->_createObjectFromClass($objName);
                /* 
                 * if not have metadata, create object from class directly
                 * metadata is on the class it self.                 * 
                 */
                
                $class = str_replace('.', '\\', $objName);
                
                /*
                $dotPos = strrpos($objName, ".");
                if ($dotPos > 0) { // if has package/namespace
                    $objectPackage =  substr($objName, 0, $dotPos) ;
                    $class = substr($objName, $dotPos + 1);
                } else {
                    $objectPackage = null;
                    $class = $objName;
                }
                * 
                */
                
            }
        }        
        
        if ($xmlArr) {           
            $keys = array_keys($xmlArr);
            $root = $keys[0];

            // add by mr_a_ton , atrubut name must match with object name
            $dotPos = strrpos($objName, ".");
            $shortObjectName = $dotPos > 0 ? substr($objName, $dotPos + 1) : $objName;
            if ($xmlArr[$root]["ATTRIBUTES"]["NAME"] == "") {
                $xmlArr[$root]["ATTRIBUTES"]["NAME"] = $shortObjectName;
            } else {
                if ($shortObjectName != $xmlArr[$root]["ATTRIBUTES"]["NAME"]) {
                    trigger_error("Metadata file parsing error for object $objName. Name attribut [" . $xmlArr[$root]["ATTRIBUTES"]["NAME"] . "] not same with object name. Please double check your metadata xml file again.", E_USER_ERROR);
                }
            }
            
            $class = $xmlArr[$root]["ATTRIBUTES"]["CLASS"];
            
            //echo __METHOD__.'-'.__LINE__ . ' class : ' . $class . ' <br />';
            
            // if class has package name as prefix, change the package to the prefix
            $dotPos = strrpos($class, ".");
            if ($dotPos > 0) {
                $classPrefix = substr($class, 0, $dotPos);
                $classPackage = $classPrefix;
                $shortClass = substr($class, $dotPos + 1);
            } else {
                $classPrefix = null;
                $classPackage = null;                
                $shortClass = $class;
            }            
           
            //echo 'shortclass : ' . $shortClass .'<br />' ;
            // set object package
            $dotPos = strrpos($objName, ".");
            $objectPackage = $dotPos > 0 ? substr($objName, 0, $dotPos) : null;
            if (strpos($objectPackage, '@') === 0) {
                $objectPackage = substr($objectPackage, 1);
            }
            if (!$classPackage) {
                $classPackage = $objectPackage;
            }
            $xmlArr[$root]["ATTRIBUTES"]["PACKAGE"] = $objectPackage;
        }


        //$package = $xmlArr[$root]["ATTRIBUTES"]["PACKAGE"];
        //$class = $xmlArr[$root]["ATTRIBUTES"]["CLASS"];

        $class = $shortClass;
        
        // echo $class . '<br />';
        
        $class = $this->getClassNameFromAlias($class);
        
        if (strrpos($class, '\\' ) !== false) {
            $obj_ref = new $class($xmlArr);
            return $obj_ref;
        }        

        //echo $class . '<br />';
        //echo $classPackage . '<br />';
        
        if (!class_exists($class, false)) {
            //echo 'class not exist<br />';
            $classFile = ClassLoader::getLibFileWithPath($class, $classPackage);
            //echo 'classFile: '.$classFile .'<br />';
            if (!$classFile) {
                if ($objectPackage) {
                    trigger_error("Cannot find the class with name as $objectPackage.$class", E_USER_ERROR);
                } else {
                    trigger_error("Cannot find the class with name as $class of $objName", E_USER_ERROR);
                }
                exit();
            }
            include_once($classFile);
        }

        //echo 'class_exists($class, false): '. (class_exists($class, false)? 'true':'false') . '<br />';
        if (class_exists($class, false)) {
            //if ($objName == "collab.calendar.form.EventListForm") { print_r($xmlArr); exit; }
            $obj_ref = new $class($xmlArr);
            if ($obj_ref) {
                return $obj_ref;
            }
        } else {
            trigger_error("Cannot find the class with name as $class in $classFile", E_USER_ERROR);
        }
        return null;
    }
protected function constructObject($objName, &$xmlArr = null)
    {               
        
        if (!$xmlArr) {
            $xmlFile = ObjectFactoryHelper::getXmlFileWithPath($objName);            
            if ($xmlFile) { 
                $xmlArr = ObjectFactoryHelper::getXmlArray($xmlFile);                
            } else {
                
                //$this->_createObjectFromClass($objName);
                /* 
                 * if not have metadata, create object from class directly
                 * metadata is on the class it self.                 * 
                 */
                
                $class = str_replace('.', '\\', $objName);
                
                /*
                $dotPos = strrpos($objName, ".");
                if ($dotPos > 0) { // if has package/namespace
                    $objectPackage =  substr($objName, 0, $dotPos) ;
                    $class = substr($objName, $dotPos + 1);
                } else {
                    $objectPackage = null;
                    $class = $objName;
                }
                * 
                */
                
            }
        }        
        
        if ($xmlArr) {           
            $keys = array_keys($xmlArr);
            $root = $keys[0];

            // add by mr_a_ton , atrubut name must match with object name
            $dotPos = strrpos($objName, ".");
            $shortObjectName = $dotPos > 0 ? substr($objName, $dotPos + 1) : $objName;
            if ($xmlArr[$root]["ATTRIBUTES"]["NAME"] == "") {
                $xmlArr[$root]["ATTRIBUTES"]["NAME"] = $shortObjectName;
            } else {
                if ($shortObjectName != $xmlArr[$root]["ATTRIBUTES"]["NAME"]) {
                    trigger_error("Metadata file parsing error for object $objName. Name attribut [" . $xmlArr[$root]["ATTRIBUTES"]["NAME"] . "] not same with object name. Please double check your metadata xml file again.", E_USER_ERROR);
                }
            }
            
            $class = $xmlArr[$root]["ATTRIBUTES"]["CLASS"];
            
            //echo __METHOD__.'-'.__LINE__ . ' class : ' . $class . ' <br />';
            
            // if class has package name as prefix, change the package to the prefix
            $dotPos = strrpos($class, ".");
            if ($dotPos > 0) {
                $classPrefix = substr($class, 0, $dotPos);
                $classPackage = $classPrefix;
                $shortClass = substr($class, $dotPos + 1);
            } else {
                $classPrefix = null;
                $classPackage = null;                
                $shortClass = $class;
            }            
           
            //echo 'shortclass : ' . $shortClass .'<br />' ;
            // set object package
            $dotPos = strrpos($objName, ".");
            $objectPackage = $dotPos > 0 ? substr($objName, 0, $dotPos) : null;
            if (strpos($objectPackage, '@') === 0) {
                $objectPackage = substr($objectPackage, 1);
            }
            if (!$classPackage) {
                $classPackage = $objectPackage;
            }
            $xmlArr[$root]["ATTRIBUTES"]["PACKAGE"] = $objectPackage;
        }


        //$package = $xmlArr[$root]["ATTRIBUTES"]["PACKAGE"];
        //$class = $xmlArr[$root]["ATTRIBUTES"]["CLASS"];

        $class = $shortClass;
        
        // echo $class . '<br />';
        
        $class = $this->getClassNameFromAlias($class);
        
        if (strrpos($class, '\\' ) !== false) {
            $obj_ref = new $class($xmlArr);
            return $obj_ref;
        }        

        //echo $class . '<br />';
        //echo $classPackage . '<br />';
        
        if (!class_exists($class, false)) {
            //echo 'class not exist<br />';
            $classFile = ClassLoader::getLibFileWithPath($class, $classPackage);
            //echo 'classFile: '.$classFile .'<br />';
            if (!$classFile) {
                if ($objectPackage) {
                    trigger_error("Cannot find the class with name as $objectPackage.$class", E_USER_ERROR);
                } else {
                    trigger_error("Cannot find the class with name as $class of $objName", E_USER_ERROR);
                }
                exit();
            }
            include_once($classFile);
        }

        //echo 'class_exists($class, false): '. (class_exists($class, false)? 'true':'false') . '<br />';
        if (class_exists($class, false)) {
            //if ($objName == "collab.calendar.form.EventListForm") { print_r($xmlArr); exit; }
            $obj_ref = new $class($xmlArr);
            if ($obj_ref) {
                return $obj_ref;
            }
        } else {
            trigger_error("Cannot find the class with name as $class in $classFile", E_USER_ERROR);
        }
        return null;
    }
Construct an instance of an object

@param string $objName object name
@param array $xmlArr xml array
@return object the instance of the object