コード例 #1
0
 /**
  * Tests that the MDB2::fileExists() method correctly identifies
  * existing/non-existing files.
  */
 function test_fileExists()
 {
     $this->assertTrue(MDB2::fileExists('PEAR.php'), 'fileExists');
     $this->assertFalse(MDB2::fileExists('itIsHopedThatNoOneHasAFileWithThisName.php'), 'fileExists');
 }
コード例 #2
0
ファイル: MDB2.php プロジェクト: BackupTheBerlios/wcms
 /**
  * loads a module
  *
  * @param string $module name of the module that should be loaded
  *      (only used for error messages)
  * @param string $property name of the property into which the class will be loaded
  * @return object on success a reference to the given module is returned
  *                and on failure a PEAR error
  * @access public
  */
 function &loadModule($module, $property = null)
 {
     if (!$property) {
         $property = strtolower($module);
     }
     if (!isset($this->{$property})) {
         $version = false;
         $class_name = 'MDB2_' . $module;
         $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
         if (!class_exists($class_name) && !MDB2::fileExists($file_name)) {
             $class_name = 'MDB2_Driver_' . $module . '_' . $this->phptype;
             $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
             $version = true;
             if (!class_exists($class_name) && !MDB2::fileExists($file_name)) {
                 return $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to find module: ' . $file_name);
             }
         }
         if (!class_exists($class_name) && !(include_once $file_name)) {
             return $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to load manager driver class: ' . $file_name);
         }
         // load modul in a specific version
         if ($version) {
             if (method_exists($class_name, 'getClassName')) {
                 $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
                 if ($class_name != $class_name_new) {
                     $class_name = $class_name_new;
                     $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
                     if (!MDB2::fileExists($file_name)) {
                         return $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to find module: ' . $file_name);
                     }
                     if (!(include_once $file_name)) {
                         return $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to load manager driver class: ' . $file_name);
                     }
                 }
             }
         }
         if (!class_exists($class_name)) {
             return $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to load module: ' . $module . ' into property: ' . $property);
         }
         $this->{$property} =& new $class_name($this->db_index);
         $this->modules[$module] =& $this->{$property};
         if ($version) {
             // this wil be used in the connect method to determine if the module
             // needs to be loaded with a different version if the server
             // version changed in between connects
             $this->loaded_version_modules[] = $property;
         }
     }
     return $this->{$property};
 }
コード例 #3
0
ファイル: MDB2.php プロジェクト: Alphenus/ilmomasiina-php
 /**
  * loads a module
  *
  * @param   string  name of the module that should be loaded
  *                  (only used for error messages)
  * @param   string  name of the property into which the class will be loaded
  * @param   bool    if the class to load for the module is specific to the
  *                  phptype
  *
  * @return  object  on success a reference to the given module is returned
  *                  and on failure a PEAR error
  *
  * @access  public
  */
 function loadModule($module, $property = null, $phptype_specific = null)
 {
     if (!$property) {
         $property = strtolower($module);
     }
     if (!isset($this->{$property})) {
         $version = $phptype_specific;
         if ($phptype_specific !== false) {
             $version = true;
             $class_name = 'MDB2_Driver_' . $module . '_' . $this->phptype;
             $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
         }
         if ($phptype_specific === false || !MDB2::classExists($class_name) && !MDB2::fileExists($file_name)) {
             $version = false;
             $class_name = 'MDB2_' . $module;
             $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
         }
         $err = MDB2::loadClass($class_name, $this->getOption('debug'));
         if ((new PEAR())->isError($err)) {
             return $err;
         }
         // load module in a specific version
         if ($version) {
             if (method_exists($class_name, 'getClassName')) {
                 $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
                 if ($class_name != $class_name_new) {
                     $class_name = $class_name_new;
                     $err = MDB2::loadClass($class_name, $this->getOption('debug'));
                     if ((new PEAR())->isError($err)) {
                         return $err;
                     }
                 }
             }
         }
         if (!MDB2::classExists($class_name)) {
             $err = $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, "unable to load module '{$module}' into property '{$property}'", __FUNCTION__);
             return $err;
         }
         $this->{$property} = new $class_name($this->db_index);
         $this->modules[$module] = $this->{$property};
         if ($version) {
             // this will be used in the connect method to determine if the module
             // needs to be loaded with a different version if the server
             // version changed in between connects
             $this->loaded_version_modules[] = $property;
         }
     }
     return $this->{$property};
 }
コード例 #4
0
ファイル: MDB2.php プロジェクト: BackupTheBerlios/lesen-svn
 /**
 * loads a module
 *
 * @param string $module name of the module that should be loaded
 *      (only used for error messages)
 * @param string $property name of the property into which the class will be loaded
 * @param boolean $phptype_specific if the class to load for the module
                                    is specific to the phptype
 * @return object on success a reference to the given module is returned
 *                and on failure a PEAR error
 * @access public
 */
 function &loadModule($module, $property = null, $phptype_specific = null)
 {
     if (!$property) {
         $property = strtolower($module);
     }
     if (!isset($this->{$property})) {
         $version = $phptype_specific;
         if ($phptype_specific != false) {
             $version = true;
             $class_name = 'MDB2_Driver_' . $module . '_' . $this->phptype;
             $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
         } else {
             if ($phptype_specific == false || !class_exists($class_name) && !MDB2::fileExists($file_name)) {
                 $version = false;
                 $class_name = 'MDB2_' . $module;
                 //print $class_name . " clase <br>";
                 $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
                 //print $file_name . " archivo <br>";
             }
         }
         if (!class_exists($class_name)) {
             if ($this->options['debug']) {
                 $include = (include_once $file_name);
             } else {
                 $include = @(include_once $file_name);
             }
             if (!$include) {
                 if (!MDB2::fileExists($file_name)) {
                     $msg = "unable to find module '{$module}' file '{$file_name}'";
                 } else {
                     $msg = "unable to load '{$module}' driver class from file '{$file_name}'";
                 }
                 $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, $msg);
                 return $err;
             }
         }
         // load modul in a specific version
         if ($version) {
             if (method_exists($class_name, 'getClassName')) {
                 $class_name_new = call_user_func(array($class_name, 'getClassName'), $this->db_index);
                 if ($class_name != $class_name_new) {
                     $class_name = $class_name_new;
                     $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
                     if ($this->options['debug']) {
                         $include = (include_once $file_name);
                     } else {
                         $include = @(include_once $file_name);
                     }
                     if (!$include) {
                         if (!MDB2::fileExists($file_name)) {
                             $msg = "unable to find module '{$module}' file '{$file_name}'";
                         } else {
                             $msg = "unable to load '{$module}' driver class from file '{$file_name}'";
                         }
                         $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, $msg);
                         return $err;
                     }
                 }
             }
         }
         if (!class_exists($class_name)) {
             $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, "unable to load module '{$module}' into property '{$property}'");
             return $err;
         }
         $this->{$property} =& new $class_name($this->db_index);
         $this->modules[$module] =& $this->{$property};
         if ($version) {
             // this wil be used in the connect method to determine if the module
             // needs to be loaded with a different version if the server
             // version changed in between connects
             $this->loaded_version_modules[] = $property;
         }
     }
     return $this->{$property};
 }