示例#1
0
 public function __call($name, $args)
 {
     if (!empty($this->extra_functions[$name])) {
         return call_user_func_array($this->extra_functions[$name], $args);
     } else {
         trigger_error('Call to undefined method ' . get_class($this) . '::' . $name . '() in ' . trace_blame_line(array('__call')), E_USER_ERROR);
     }
 }
示例#2
0
 /**
  * dbh_do_bind() - Execute a (possibly write access) SQL query with bound parameters
  *
  * @param string $sql      The SQL query to run
  * @param mixed $params   this can either be called passing an array of bind params, or just by passing the bind params as args after the SQL arg
  * @return PDOStatement
  */
 function dbh_do_bind($sql)
 {
     $use_dbh = $this->dbh();
     if (ORM_SQL_PROFILE) {
         START_TIMER('dbh_do_bind');
     }
     $bind_params = array_slice(func_get_args(), 1);
     ###  Allow params passed in an array or as args
     if (is_a($bind_params[count($bind_params) - 1], 'PDO') || is_a($bind_params[count($bind_params) - 1], 'PhoneyPDO')) {
         $use_dbh = array_pop($bind_params);
     }
     if (count($bind_params) == 1 && is_array(array_shift(array_values($bind_params)))) {
         $bind_params = array_shift(array_values($bind_params));
     }
     $this->reverse_t_bools($bind_params);
     if (ORM_SQL_DEBUG || ORM_SQL_WRITE_DEBUG) {
         bug($sql, $bind_params);
     }
     $GLOBALS['ORM_SQL_LOG'][] = array(microtime(true), $sql, $bind_params);
     try {
         $sth = $use_dbh->prepare($sql);
         $rv = $sth->execute($bind_params);
     } catch (PDOException $e) {
         trace_dump();
         $err_msg = 'There was an error running a SQL statement, [' . $sql . '] with (' . join(',', $bind_params) . '): ' . $e->getMessage() . ' in ' . trace_blame_line();
         if (strlen($err_msg) > 1024) {
             bug($err_msg, $sql, $bind_params, $e->getMessage());
             $sql = substr($sql, 0, 1020 + strlen($sql) - strlen($err_msg)) . '...';
         }
         trigger_error('There was an error running a SQL statement, [' . $sql . '] with (' . join(',', $bind_params) . '): ' . $e->getMessage() . ' in ' . trace_blame_line(), E_USER_ERROR);
         return false;
     }
     if (ORM_SQL_PROFILE) {
         END_TIMER('dbh_do_bind');
     }
     return $rv;
 }
示例#3
0
 public function run_hook($area, $sequence_from, $sequence_to = null)
 {
     if (STARK_EXTEND_PROFILE) {
         START_TIMER('Stark__Extend->run_hook');
     }
     if (!is_numeric($sequence_from)) {
         return trigger_error("Stark__Extend->run_hook() parameter 2 (sequence_from) must be numeric in " . trace_blame_line(array('run_hook')), E_USER_ERROR);
     }
     $trace = debug_backtrace();
     ///  If caller was rhni (and call_user_func_array(), then skip those 2
     if (empty($trace[0]['file']) && $trace[1]['file'] == __FILE__ && $trace[2]['function'] == 'rhni') {
         array_splice($trace, 0, 2);
     }
     if (is_null($sequence_to)) {
         if (empty($this->last_hook_caller[$area]) || $sequence_from < $this->last_hook_caller[$area]['sequence_to'] || $trace[0]['file'] != $this->last_hook_caller[$area]['file'] || $trace[0]['line'] < $this->last_hook_caller[$area]['line']) {
             $sequence_to = $sequence_from;
             $sequence_from = -10000;
         } else {
             if ($trace[0]['line'] == $this->last_hook_caller[$area]['line']) {
                 $sequence_to = $sequence_from;
             } else {
                 $sequence_to = $sequence_from;
                 $sequence_from = $this->last_hook_caller[$area]['sequence_to'] + 1.0E-5;
             }
         }
     }
     $this->last_hook_caller[$area] = array('sequence_to' => $sequence_to, 'file' => $trace[0]['file'], 'line' => $trace[0]['line']);
     $GLOBALS['__Stark__Extend__object__'] = $this;
     if (!is_numeric($sequence_to)) {
         return trigger_error("Stark__Extend->run_hook() parameter 3 (sequence_to) must be numeric in " . trace_blame_line(array('run_hook')), E_USER_ERROR);
     }
     if ($sequence_to < $sequence_from) {
         return trigger_error("In Stark__Extend->run_hook() sequence_to cannot be less than sequence_from in " . trace_blame_line(array('run_hook')), E_USER_ERROR);
     }
     $scope = $this->enter_scope();
     if (!empty($this->hooks[$area])) {
         ksort($this->hooks[$area], SORT_NUMERIC);
         foreach (array_keys($this->hooks[$area]) as $sequence) {
             ksort($this->hooks[$area][$sequence], SORT_NUMERIC);
             if ($sequence >= $sequence_from && $sequence <= $sequence_to) {
                 foreach (array_keys($this->hooks[$area][$sequence]) as $priority) {
                     ///  If this hook is in the range, then include it...
                     ksort($this->hooks[$area][$sequence][$priority], SORT_NUMERIC);
                     foreach ($this->hooks[$area][$sequence][$priority] as $callback) {
                         $scope->__hooks[] = $callback;
                     }
                 }
             }
         }
     }
     ///  This is the file to be included
     $return = $this->dirname_file . '/Extend/run_hooks.inc.php';
     return $return;
 }