Exemplo n.º 1
0
 /**
  * Contructor of class
  *
  * @param array $xmlArr
  * @param string $childClassName
  * @param object $parentObj
  * @return void
  */
 public function __construct(&$xmlArr, $childClassName, $parentObj = null)
 {
     $this->parentObj = $parentObj;
     if (!$xmlArr) {
         return;
     }
     if (isset($xmlArr["ATTRIBUTES"])) {
         $className = isset($xmlArr["ATTRIBUTES"]['CLASS']) ? $xmlArr["ATTRIBUTES"]['CLASS'] : $childClassName;
         if ((bool) strpos($className, ".")) {
             $a_package_name = explode(".", $className);
             $className = array_pop($a_package_name);
             $clsLoaded = ClassLoader::loadMetadataClass($className, implode(".", $a_package_name));
         }
         //if (!$clsLoaded) trigger_error("Cannot find the load class $className", E_USER_ERROR);
         $className = Openbiz::objectFactory()->getClassNameFromAlias($className);
         $obj = new $className($xmlArr, $parentObj);
         $this->varValue[$obj->objectName] = $obj;
     } else {
         foreach ($xmlArr as $child) {
             $className = isset($child["ATTRIBUTES"]['CLASS']) ? $child["ATTRIBUTES"]['CLASS'] : $childClassName;
             /**
              * If a '.' is found within className we need to require such class
              * and then get the className after the last dot
              * ex. shared.dataobjs.FieldName, in this case FieldName is the class, shared/dataobjs the path
              *
              * The best solution to this is enable object factory to specify its resulting object constructor parameters
              */
             if ($className) {
                 //bug fixed by jixian for resolve load an empty classname
                 if ((bool) strpos($className, ".")) {
                     $a_package_name = explode(".", $className);
                     $className = array_pop($a_package_name);
                     $clsLoaded = ClassLoader::loadMetadataClass($className, implode(".", $a_package_name));
                 } elseif ($parentObj->package) {
                     $clsLoaded = ClassLoader::loadMetadataClass($className, $parentObj->package);
                 }
                 $className = Openbiz::objectFactory()->getClassNameFromAlias($className);
                 $obj = new $className($child, $parentObj);
                 $this->varValue[$obj->objectName] = $obj;
             }
         }
     }
 }
Exemplo n.º 2
0
 protected function getElementObject(&$xmlArr, $defaultClassName, $parentObj = null)
 {
     // find the class attribute
     $className = isset($xmlArr["ATTRIBUTES"]['CLASS']) ? $xmlArr["ATTRIBUTES"]['CLASS'] : $defaultClassName;
     if ((bool) strpos($className, ".")) {
         $a_package_name = explode(".", $className);
         $className = array_pop($a_package_name);
         $clsLoaded = ClassLoader::loadMetadataClass($className, implode(".", $a_package_name));
         if (!$clsLoaded) {
             trigger_error("Cannot find the load class {$className}", E_USER_ERROR);
         }
     }
     //echo "classname is $className\n";
     $obj = new $className($xmlArr, $parentObj);
     return $obj;
 }
Exemplo n.º 3
0
 protected function invokeLoadHandler($event)
 {
     $modfile = Openbiz::$app->getModulePath() . "/" . $this->objectName . "/mod.xml";
     $xml = simplexml_load_file($modfile);
     if (!isset($xml['LoadHandler']) && !empty($xml['LoadHandler'])) {
         return;
     }
     $modLoadHandler = $xml['LoadHandler'];
     $dotPos = strrpos($modLoadHandler, ".");
     $package = $dotPos > 0 ? substr($modLoadHandler, 0, $dotPos) : null;
     $class = $dotPos > 0 ? substr($modLoadHandler, $dotPos + 1) : $modLoadHandler;
     if (ClassLoader::loadMetadataClass($class, $package)) {
         $loadHandler = new $class();
         switch ($event) {
             case "beforeLoadingModule":
             case "postLoadingModule":
             case "beforeUnloadModule":
             case "postUnloadModule":
                 $loadHandler->{$event}($this);
                 break;
         }
     }
 }
Exemplo n.º 4
0
<?php

use Openbiz\ClassLoader;
include_once "ClassLoader.php";
spl_autoload_register(['\\Openbiz\\ClassLoader', 'autoload']);
// loadCoreClassMap
$coreClassMap = (include __DIR__ . DIRECTORY_SEPARATOR . 'autoload_classmap.php');
ClassLoader::registerClassMap($coreClassMap);
// loadVendorAutoLoadClassMap
$othersClassMap = (include realpath(__DIR__ . '/../../autoload_classmap_selected.php'));
ClassLoader::registerClassMap($othersClassMap);
define('ZF2_PATH', realpath(__DIR__ . '/../../Zend2/library'));
require_once ZF2_PATH . '/Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
Exemplo n.º 5
0
 /**
  * Construct an instance of an object
  *
  * @param string $objName object name
  * @param array $xmlArr xml array
  * @return object the instance of the object
  */
 protected function constructObject($objName, &$xmlArr = null)
 {
     //echo '<pre>';
     //echo __METHOD__.'-'.__LINE__ . ' : BEGIN ========================<br />';
     //echo 'par: objName : ' . $objName . '<br />';
     if (!$xmlArr) {
         $xmlFile = ObjectFactoryHelper::getXmlFileWithPath($objName);
         //echo __METHOD__.'-'.__LINE__ . ' $xmlFile : ' . $xmlFile . '<br>';
         if ($xmlFile) {
             $xmlArr = ObjectFactoryHelper::getXmlArray($xmlFile);
             //echo __METHOD__.'-'.__LINE__ . '<br />';
             //echo var_dump($xmlArr);
         } 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) {
         //echo __METHOD__.'-'.__LINE__ . ' <br />';
         //if ($objName == 'system.view.UserListView')
         //  echo var_dump($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;
 }