Пример #1
0
 /**
  * autoload Class
  *
  * @param  string|array  $class  Class
  * @param  string  $table  Table trying to load.
  * @access private
  * @return string classname on Success
  */
 function _autoloadClass($class, $table = false)
 {
     global $_DB_DATAOBJECT;
     if (empty($_DB_DATAOBJECT['CONFIG'])) {
         DB_DataObject::_loadConfig();
     }
     $class_prefix = empty($_DB_DATAOBJECT['CONFIG']['class_prefix']) ? '' : $_DB_DATAOBJECT['CONFIG']['class_prefix'];
     $table = $table ? $table : substr($class, strlen($class_prefix));
     // only include the file if it exists - and barf badly if it has parse errors :)
     if (!empty($_DB_DATAOBJECT['CONFIG']['proxy']) || empty($_DB_DATAOBJECT['CONFIG']['class_location'])) {
         return false;
     }
     // support for:
     // class_location = mydir/ => maps to mydir/Tablename.php
     // class_location = mydir/myfile_%s.php => maps to mydir/myfile_Tablename
     // with directory sepr
     // class_location = mydir/:mydir2/: => tries all of thes locations.
     $cl = $_DB_DATAOBJECT['CONFIG']['class_location'];
     switch (true) {
         case strpos($cl, '%s') !== false:
             $file = sprintf($cl, preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table)));
             break;
         case strpos($cl, PATH_SEPARATOR) !== false:
             $file = array();
             foreach (explode(PATH_SEPARATOR, $cl) as $p) {
                 $file[] = $p . '/' . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table)) . ".php";
             }
             break;
         default:
             $file = $cl . '/' . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table)) . ".php";
             break;
     }
     $cls = is_array($class) ? $class : array($class);
     if (is_array($file) || !file_exists($file)) {
         $found = false;
         $file = is_array($file) ? $file : array($file);
         $search = implode(PATH_SEPARATOR, $file);
         foreach ($file as $f) {
             foreach (explode(PATH_SEPARATOR, '' . PATH_SEPARATOR . ini_get('include_path')) as $p) {
                 $ff = empty($p) ? $f : "{$p}/{$f}";
                 if (file_exists($ff)) {
                     $file = $ff;
                     $found = true;
                     break;
                 }
             }
             if ($found) {
                 break;
             }
         }
         if (!$found) {
             DB_DataObject::raiseError("autoload:Could not find class " . implode(',', $cls) . " using class_location value :" . $search . " using include_path value :" . ini_get('include_path'), DB_DATAOBJECT_ERROR_INVALIDCONFIG);
             return false;
         }
     }
     include_once $file;
     $ce = false;
     foreach ($cls as $c) {
         $ce = substr(phpversion(), 0, 1) > 4 ? class_exists($c, false) : class_exists($c);
         if ($ce) {
             $class = $c;
             break;
         }
     }
     if (!$ce) {
         DB_DataObject::raiseError("autoload:Could not autoload " . implode(',', $cls), DB_DATAOBJECT_ERROR_INVALIDCONFIG);
         return false;
     }
     return $class;
 }
Пример #2
0
 /**
  * autoload Class
  *
  * @param  string  $class  Class
  * @access private
  * @return string classname on Success
  */
 function _autoloadClass($class)
 {
     global $_DB_DATAOBJECT;
     if (empty($_DB_DATAOBJECT['CONFIG'])) {
         DB_DataObject::_loadConfig();
     }
     $table = substr($class, strlen($_DB_DATAOBJECT['CONFIG']['class_prefix']));
     // only include the file if it exists - and barf badly if it has parse errors :)
     if (!empty($_DB_DATAOBJECT['CONFIG']['proxy']) && empty($_DB_DATAOBJECT['CONFIG']['class_location'])) {
         return false;
     }
     if (strpos($_DB_DATAOBJECT['CONFIG']['class_location'], '%s') !== false) {
         $file = sprintf($_DB_DATAOBJECT['CONFIG']['class_location'], preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table)));
     } else {
         $file = $_DB_DATAOBJECT['CONFIG']['class_location'] . '/' . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table)) . ".php";
     }
     if (!file_exists($file)) {
         $found = false;
         foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $p) {
             if (file_exists("{$p}/{$file}")) {
                 $file = "{$p}/{$file}";
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             DB_DataObject::raiseError("autoload:Could not find class {$class} using class_location value", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
             return false;
         }
     }
     include_once $file;
     if (!class_exists($class)) {
         DB_DataObject::raiseError("autoload:Could not autoload {$class}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
         return false;
     }
     return $class;
 }
Пример #3
0
 /**
  * autoload Class
  *
  * @param  string  $class  Class
  * @access private
  * @return string classname on Success
  */
 function _autoloadClass($class)
 {
     global $_DB_DATAOBJECT;
     if (empty($_DB_DATAOBJECT['CONFIG'])) {
         DB_DataObject::_loadConfig();
     }
     $class_prefix = empty($_DB_DATAOBJECT['CONFIG']['class_prefix']) ? '' : $_DB_DATAOBJECT['CONFIG']['class_prefix'];
     $table = substr($class, strlen($class_prefix));
     // only include the file if it exists - and barf badly if it has parse errors :)
     if (!empty($_DB_DATAOBJECT['CONFIG']['proxy']) || empty($_DB_DATAOBJECT['CONFIG']['class_location'])) {
         return false;
     }
     // CHANGED FOR PLUGINS
     // array of plugin class locations
     // see DAL _setupDataObjectOptions
     if (!is_array($_DB_DATAOBJECT['CONFIG']['class_location'])) {
         $location = $_DB_DATAOBJECT['CONFIG']['class_location'];
         $file = DB_DataObject::findTableFile($location, $table);
     } else {
         foreach ($_DB_DATAOBJECT['CONFIG']['class_location'] as $k => $location) {
             $file = DB_DataObject::findTableFile($location, $table);
             if ($file) {
                 break;
             }
         }
     }
     if (!$file) {
         DB_DataObject::raiseError("autoload:Could not find class {$class} using class_location value", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
         return false;
     }
     include_once $file;
     $ce = substr(phpversion(), 0, 1) > 4 ? class_exists($class, false) : class_exists($class);
     if (!$ce) {
         DB_DataObject::raiseError("autoload:Could not autoload {$class}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
         return false;
     }
     return $class;
 }
 /**
  * Delete record by it's primary key id
  *
  * @param int $primaryId
  * @param boolean $useWhere
  * @param boolean $cascadeDelete
  * @return boolean  True on success
  * @see DB_DataObjectCommon::delete()
  * @access public
  */
 function deleteById($primaryId, $useWhere = false, $cascadeDelete = true)
 {
     $keys = $this->keys();
     if (count($keys) != 1) {
         DB_DataObject::raiseError("no primary key defined or more than one pk in table '{$this->_tableName}'", DB_DATAOBJECT_ERROR_INVALIDARGS);
         return false;
     }
     $primaryKey = $keys[0];
     $this->{$primaryKey} = $primaryId;
     return $this->delete($useWhere, $cascadeDelete);
 }
Пример #5
0
 public function raiseError($message, $type = null, $behaviour = null)
 {
     $error = parent::raiseError($message, $type, $behaviour);
     throw new Exception($type . ' ' . $message . ' ' . $error->getUserInfo());
 }
Пример #6
0
 /**
  * Copies items that are in the table definitions from an
  * array or object into the current object
  * will not override key values.
  *
  *
  * @param    array | object  $from
  * @param    string  $format eg. map xxxx_name to $object->name using 'xxxx_%s' (defaults to %s - eg. name -> $object->name
  * @access   public
  * @return   true on success or array of key=>setValue error message
  */
 function setFrom(&$from, $format = '%s')
 {
     global $_DB_DATAOBJECT;
     $keys = $this->_get_keys();
     $items = $this->_get_table();
     if (!$items) {
         DB_DataObject::raiseError("setFrom:Could not find table definition for {$this->__table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
         return;
     }
     $overload_return = array();
     foreach (array_keys($items) as $k) {
         if (in_array($k, $keys)) {
             continue;
             // dont overwrite keys
         }
         if (!$k) {
             continue;
             // ignore empty keys!!! what
         }
         if (is_object($from) && isset($from->{sprintf($format, $k)})) {
             if ($_DB_DATAOBJECT['OVERLOADED']) {
                 $kk = strtolower($k) == 'from' ? '_from' : $k;
                 $ret = $this->{'set' . $kk}($from->{sprintf($format, $k)});
                 if (is_string($ret)) {
                     $overload_return[$k] = $ret;
                 }
                 continue;
             }
             $this->{$k} = $from->{sprintf($format, $k)};
             continue;
         }
         if (is_object($from)) {
             continue;
         }
         if (!isset($from[sprintf($format, $k)])) {
             continue;
         }
         if (is_object($from[sprintf($format, $k)])) {
             continue;
         }
         if (is_array($from[sprintf($format, $k)])) {
             continue;
         }
         if ($_DB_DATAOBJECT['OVERLOADED']) {
             $kk = strtolower($k) == 'from' ? '_from' : $k;
             $ret = $this->{'set' . $kk}($from[sprintf($format, $k)]);
             if (is_string($ret)) {
                 $overload_return[$k] = $ret;
             }
             continue;
         }
         $this->{$k} = $from[sprintf($format, $k)];
     }
     if ($overload_return) {
         return $overload_return;
     }
     return true;
 }