public function __construct(Settings $dsn = null) { if (null === $dsn) { throw new Client\Exception('Log filename required in config dsn', Client\Exception::DSN_REQUIRED); } $this->fileName = $dsn->path; $this->fileName = '/' == $this->fileName[0] ? $this->fileName : App::instance()->logPath . $this->fileName; }
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 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(); } }