Exemplo n.º 1
0
 /**
  *	importing a unique class or an entire package
  *	@param	string  a class name or a package name
  *  @param	string $module nom du module ou trouver la class a charger
  *	@return void
  *	@access public
  */
 function import($package, $module = NULL)
 {
     // already registered ?
     if (APIClassRegistry::isRegistered($package)) {
         return;
     }
     // extracting package name
     $packagename = APIClassRegistry::extractPackageName($package);
     $path = APIClassRegistry::convertToPath($package, $module);
     if (APIClassRegistry::isPackage($package)) {
         // filtering php class and running parser
         if (isset($path) && is_dir($path)) {
             APIClassRegistry::register($package);
             $handle = opendir($path);
             while ($file = readdir($handle)) {
                 if ($file !== '.' && $file !== '..' && preg_match('/(\\.php)$/i', $file) > 0) {
                     require_once $path . $file;
                     APIClassRegistry::register($packagename, substr($file, 0, strlen($file) - 4));
                 }
             }
             closedir($handle);
         }
     } else {
         if (APIClassRegistry::isClass($package)) {
             // extracting class name
             $classname = APIClassRegistry::extractClassName($package);
             // loadclass
             $path .= '.php';
             if (isset($path) && is_file($path)) {
                 // register
                 APIClassRegistry::register($packagename, $classname);
                 require_once $path;
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * display all class and import that have been register
  * @return void
  * @access public static
  */
 function _debug()
 {
     static $registry;
     // get unique instance
     if (!isset($registry)) {
         $registry =& APIClassRegistry::getInstance();
     }
     print "<font style='font-family: Courier New; font-size: 9pt; color:#0000ff'><strong>Packages importation :</strong><ol>";
     $keys = array_keys($registry->packages);
     $len = count($keys);
     if ($len > 0) {
         for ($i = 0; $i < $len; $i++) {
             $pos = strpos($keys[$i], 'core.');
             if ($pos !== FALSE && $pos === 0) {
                 print "<li><font color=#ff3300><strong>" . $keys[$i] . "</strong></font>";
             } else {
                 print "<li>" . $keys[$i];
             }
         }
     } else {
         print "<li> no existance of package import";
     }
     print "</ol></font>";
     print "<font style='font-family: Courier New; font-size: 9pt; color:#0000ff'><strong>Classes importation :</strong><ol>";
     $keys = array_keys($registry->classes);
     $len = count($keys);
     if ($len > 0) {
         for ($i = 0; $i < $len; $i++) {
             $class = $registry->classes[$keys[$i]] . ".<b>" . $keys[$i] . "</b>";
             $pos = strpos($class, 'core.');
             if ($pos !== FALSE && $pos === 0) {
                 print "<li><font color=#ff3300>" . $class . "</font>";
             } else {
                 print "<li>" . $class;
             }
         }
     } else {
         print "<li> no existance of class import";
     }
     print "</ol></font>";
 }
Exemplo n.º 3
0
 /**
  * 
  * Méthode static d'instanciation de class / object;
  * 
  * 
  *
  * @param string  $class nom de class à charger et à instancier ; espace de nommage identique a celle utilisée en java.
  * @param array   $parameters parametres de la class s'il y en a.
  * @param boolean $new_class indique si, lorsque la class est déjà dans le registre, on doit en instancier une nouvelle.
  * @return object un pointeur sur la class instancié
  * @access public
  * @since 1.1
  * @update 06/06/2002
  */
 function &loadClass($class, $parameters = NULL, $new_class = FALSE, $module = NULL)
 {
     APIC::import("org.apicnet.io.File");
     if ($new_class) {
         //	echo(" OK <br>");
         $classname = APIClassRegistry::extractClassName($class);
         if (!APIClassRegistry::isClass($class) || !APIClassRegistry::isRegistered($class)) {
             $path = new File(APIClassRegistry::convertToPath($class, $module) . '.php');
             //		echo($path->getFilePath()."<br>");
             if ($path->exists()) {
                 APIC::import($class, $module);
             } else {
                 die("Class " . $class . " cannot be found");
             }
         }
         $params = '';
         if ($parameters != NULL && is_array($parameters)) {
             $plen = count($parameters);
             if ($plen > 0) {
                 for ($i = 0; $i < $plen; $i++) {
                     $params .= '$parameters[' . $i . ']';
                     if ($i < $plen - 1) {
                         $params .= ', ';
                     }
                 }
             }
         }
         $obj = NULL;
         eval('$obj = new ' . $classname . '(' . $params . ');');
         APIClassRegistry::registerClass($class, $obj);
         return $obj;
     } else {
         // fin du if New_class
         //	APIC::_debug();
         if (APIClassRegistry::isRegistered($class)) {
             //		echo($class." loaded ...");
             return APIClassRegistry::loadClass($class, $parameters);
         } else {
             if (!APIClassRegistry::isClass($class) || !APIClassRegistry::isRegistered($class)) {
                 $path = new File(APIClassRegistry::convertToPath($class, $module) . '.php');
                 //			echo($path->getFilePath()."<br>");
                 if ($path->exists()) {
                     //				echo($class." instanciate ...");
                     APIC::import($class, $module);
                     return APIC::loadClass($class, $parameters, TRUE, $module);
                 } else {
                     die("Class " . $class . " cannot be found");
                 }
             }
         }
     }
 }