Exemple #1
0
 /**
  * Hayate_Excetion
  *
  * @param string|Exception $message Error message or Wrapped exception
  * @param int $code Error code or number
  * @param Exception $prev From (php >= 5.3.0)
  *
  * This constructor also optionally accept and Exception object as
  * the 3rd argument (php >= 5.3.0)
  */
 public function __construct($message = '', $code = 0, Exception $prev = null)
 {
     if ($message instanceof Exception) {
         parent::__construct($message->getMessage(), (int) $message->getCode());
         $this->setFile($message->getFile());
         $this->setLine($message->getLine());
         require_once 'Hayate/Log.php';
         Hayate_Log::error($message->getMessage());
     } else {
         if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
             parent::__construct($message, $code, $prev);
         } else {
             parent::__construct($message, $code);
             if ($prev instanceof Exception) {
                 $this->setFile($prev->getFile());
                 $this->setLine($prev->getLine());
             }
         }
         require_once 'Hayate/Log.php';
         Hayate_Log::error($message);
     }
 }
Exemple #2
0
 protected function getSession($id, $mode = PDO::FETCH_OBJ)
 {
     try {
         $stm = $this->db->prepare('SELECT * FROM sessions WHERE session_id=:id LIMIT 1');
         $stm->bindValue(':id', $id, PDO::PARAM_STR);
         $stm->execute();
         $ses = $stm->fetch($mode);
         $stm->closeCursor();
         return $ses;
     } catch (Exception $ex) {
         Hayate_Log::error($ex, true);
     }
     return false;
 }
Exemple #3
0
 public function count($table = null, array $where = array())
 {
     if (null === $table) {
         if (!isset($this->from[0])) {
             throw new Hayate_Database_Exception(sprintf(_('Missing table name in: %s'), __METHOD__));
         }
         $table = $this->from[0];
     }
     $sql = 'SELECT COUNT(*) FROM ' . $table;
     if (count($where)) {
         $this->where($where);
         $sql .= ' WHERE ' . implode(' ', $this->where);
     } else {
         if (count($this->where)) {
             $sql .= ' WHERE ' . implode(' ', $this->where);
         }
     }
     try {
         $ret = $this->query($sql, self::FETCH_COLUMN, 0)->fetch(self::FETCH_NUM);
         return $ret[0];
     } catch (Exception $ex) {
         Hayate_Log::error("{$ex}");
     }
     return 0;
 }
Exemple #4
0
 public static function shutdown_function()
 {
     $error = error_get_last();
     if (is_array($error)) {
         $msg = 'Fatal error: ' . $error['message'] . ' in: ' . $error['file'] . ' on line: ' . $error['line'];
         Hayate_Log::error($msg);
     }
 }
Exemple #5
0
 /**
  * @return bool TRUE if credentials are valid, FALSE otherwise
  */
 public function authenticate($identifier, $secret, $salt = '', $algo = NULL, $remember = FALSE)
 {
     $this->setStatus(FALSE);
     if (is_string($algo)) {
         $secret = hash($algo, $salt . $secret);
     }
     try {
         $this->identity = $this->db->from($this->table)->where($this->identifier, $identifier)->get();
         if (!$this->identity) {
             $this->setStatus(self::ERROR_IDENTIFIER);
             return FALSE;
         }
         if (0 !== strcmp($secret, $this->identity->{$this->secret})) {
             $this->setStatus(self::ERROR_SECRET);
             return FALSE;
         }
         // unset the secret
         unset($this->identity->{$this->secret});
         // store in session
         $this->session->set(self::AUTHID, $this->identity);
         if (is_numeric($remember)) {
             $this->cookie->set(self::AUTHID, $this->identity, $remember);
         }
         $this->setStatus(self::SUCCESS);
         return TRUE;
     } catch (Exception $ex) {
         Hayate_Log::error($ex);
     }
     return FALSE;
 }