コード例 #1
0
 /**
  * Tests that the MDB2::classExists() method correctly tests for
  * existence of a class.
  */
 function test_classExists()
 {
     $this->assertFalse(MDB2::classExists('null'), 'classExists');
     $this->assertTrue(MDB2::classExists('MDB2'), 'classExists');
 }
コード例 #2
0
ファイル: InternalsTest.php プロジェクト: gauthierm/MDB2
 /**
  * Tests that the MDB2::classExists() method correctly tests for
  * existence of a class.
  * @dataProvider provider
  */
 public function test_classExists($ci)
 {
     $this->manualSetUp($ci);
     $this->assertFalse(MDB2::classExists('null'), 'classExists');
     $this->assertTrue(MDB2::classExists('MDB2'), 'classExists');
 }
コード例 #3
0
ファイル: MDB2.php プロジェクト: Alphenus/ilmomasiina-php
 /**
  * wrap a result set into the correct class
  *
  * @param   resource result handle
  * @param   mixed   array that contains the types of the columns in
  *                        the result set
  * @param   mixed   string which specifies which result class to use
  * @param   mixed   string which specifies which class to wrap results in
  * @param   string  number of rows to select
  * @param   string  first row to select
  *
  * @return mixed   an MDB2_Result, a MDB2 error on failure
  *
  * @access  protected
  */
 function _wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)
 {
     if ($types === true) {
         if ($this->supports('result_introspection')) {
             $this->loadModule('Reverse', null, true);
             $tableInfo = $this->reverse->tableInfo($result_resource);
             if ((new PEAR())->isError($tableInfo)) {
                 return $tableInfo;
             }
             $types = array();
             foreach ($tableInfo as $field) {
                 $types[] = $field['mdb2type'];
             }
         } else {
             $types = null;
         }
     }
     if ($result_class === true) {
         $result_class = $this->options['result_buffering'] ? $this->options['buffered_result_class'] : $this->options['result_class'];
     }
     if ($result_class) {
         $class_name = sprintf($result_class, $this->phptype);
         if (!MDB2::classExists($class_name)) {
             $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'result class does not exist ' . $class_name, __FUNCTION__);
             return $err;
         }
         $result = new $class_name($this, $result_resource, $limit, $offset);
         if (!MDB2::isResultCommon($result)) {
             $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'result class is not extended from MDB2_Result_Common', __FUNCTION__);
             return $err;
         }
         if (!empty($types)) {
             $err = $result->setResultTypes($types);
             if ((new PEAR())->isError($err)) {
                 $result->free();
                 return $err;
             }
         }
     }
     if ($result_wrap_class === true) {
         $result_wrap_class = $this->options['result_wrap_class'];
     }
     if ($result_wrap_class) {
         if (!MDB2::classExists($result_wrap_class)) {
             $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'result wrap class does not exist ' . $result_wrap_class, __FUNCTION__);
             return $err;
         }
         $result = new $result_wrap_class($result_resource, $this->fetchmode);
     }
     return $result;
 }
コード例 #4
0
ファイル: MDB2.php プロジェクト: Spark-Eleven/revive-adserver
 /**
  * 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 (PEAR::isError($err)) {
             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;
                     $err = MDB2::loadClass($class_name, $this->getOption('debug'));
                     if (PEAR::isError($err)) {
                         return $err;
                     }
                 }
             }
         }
         if (!class_exists($class_name)) {
             $err =& $this->customRaiseError(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};
 }