/** * @param $message * @param string $type * @return $this */ public function push($message, $type = Log::TYPE_MESSAGE) { $message = App::time('log')->date('Y-m-d H:i:s') . "\t" . print_r($message, 1) . "\n"; if (++$this->hits > 5) { if (is_null($this->handle)) { $this->handle = fopen($this->fileName, 'a'); } fwrite($this->handle, $message); } else { file_put_contents($this->fileName, $message, FILE_APPEND); } return $this; }
public function __construct(Settings $dsn = null) { $this->dsn = $dsn ? $dsn : new Settings(); if (empty($dsn->proxyClient)) { throw new Exception('proxyClient required in dsn', Exception::PROXY_REQUIRED); } $this->table = new Symbol($dsn->path ? $dsn->path : 'key_value_storage'); $this->keyField = new Symbol('k'); $this->valueField = new Symbol('v'); $this->expireField = new Symbol('e'); $this->db = Database::getInstance($this->dsn->proxyClient); $this->time = App::time($this->dsn->dateSource); // TODO use getInstance after Date_Source refactoring }
protected function setUpErrorHandling() { $app = $this; $errorLevels = array(E_ERROR => 'error', E_WARNING => 'warning', E_PARSE => 'parse', E_NOTICE => 'notice', E_CORE_ERROR => 'core-error', E_CORE_WARNING => 'core-warning', E_COMPILE_ERROR => 'compile-error', E_COMPILE_WARNING => 'compile-warning', E_USER_ERROR => 'user-error', E_USER_WARNING => 'user-warning', E_USER_NOTICE => 'user-notice', E_STRICT => 'strict', E_RECOVERABLE_ERROR => 'recoverable-error', E_DEPRECATED => 'deprecated', E_USER_DEPRECATED => 'user-deprecated', E_ALL => 'all'); $errorHandler = function ($errno, $errstr, $errfile, $errline, $errcontext) use($app, $errorLevels) { file_put_contents($this->errorLogPath . 'php-errors-' . $errorLevels[$errno] . '.log', date('r') . "\t" . App::instance()->path . "\t" . $errno . "\t" . $errstr . "\t" . $errfile . ':' . $errline . "\t" . PHP_EOL, FILE_APPEND); if (E_RECOVERABLE_ERROR == $errno) { throw new \Exception($errstr, $errno); } }; register_shutdown_function(function () use($errorHandler) { $error = error_get_last(); if (null !== $error) { $errorHandler($error['type'], $error['message'], $error['file'], $error['line'], null); } }); set_error_handler($errorHandler); }
public function auth() { Auth::getInstance('dev')->demand(isset($_GET['logout']), '/'); App::redirect('/'); }
public static function redirect($url, $permanent = false, $stop = true) { if ($permanent) { header('HTTP/1.1 301 Moved Permanently'); } header('Location: ' . $url); if ($stop) { App::instance()->stop(); } }