Example #1
0
 /**
  * @param  array $record
  * @return array
  */
 public function __invoke(array $record)
 {
     // return if the level is not high enough
     if ($record['level'] < $this->level) {
         return $record;
     }
     $trace = debug_backtrace();
     // skip first since it's always the current method
     array_shift($trace);
     // the call_user_func call is also skipped
     array_shift($trace);
     $i = 0;
     //dd($trace);
     while (isset($trace[$i]['class'])) {
         foreach ($this->skipClassesPartials as $part) {
             if (strpos($trace[$i]['class'], $part) !== false) {
                 // This is the reason to the existance of this class
                 // I know, it sucks.
                 $i += 3;
                 // Back to normal
                 continue 2;
             }
         }
         break;
     }
     // we should have the call source now
     $record['extra'] = array_merge($record['extra'], array('file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null, 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, 'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null, 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, 'environment' => Kernel::env()));
     return $record;
 }
Example #2
0
File: Jar.php Project: queued/mavis
 /**
  * Class constructor
  */
 public function __construct()
 {
     $this->slim = Kernel::instance()->getSlim();
     $container = $this->slim->getContainer();
     $this->cipher = $container->get('cipher');
     $this->response = $container->get('response');
 }
Example #3
0
 /**
  * Adds a log record at an arbitrary level.
  *
  * This method allows for compatibility with common interfaces.
  *
  * @param mixed $level   The log level
  * @param string $message The log message
  * @param array $context The log context
  * @return bool
  */
 public function log($level = Logger::DEBUG, $message, array $context = [])
 {
     $level = static::nameToLevel($level);
     if (Config::get('kernel.environment.' . Kernel::env() . '.logging') == false) {
         // Logging is disabled for this environment
         return false;
     }
     return $this->getLogger()->addRecord($level, $message, $context);
 }
Example #4
0
 public function __invoke($request, $response, $next)
 {
     $slim = Kernel::instance()->getSlim();
     $container = $slim->getContainer();
     $handler = new InvocableHandler($slim, $container);
     $container['errorHandler'] = function () use($handler) {
         return $handler;
     };
     $container['exhan'] = $handler;
     return $next($request, $response);
 }
Example #5
0
 public function __construct()
 {
     $slim = Kernel::instance()->getSlim();
     $container = $slim->getContainer();
     $container['errorHandler'] = $this;
     // Set error handler
     set_error_handler(['Mavis\\Middlewares\\Errors\\ServerError', 'errorHandler']);
     // Set fatal error handler
     register_shutdown_function(['Mavis\\Middlewares\\Errors\\ServerError', 'errorHandler']);
     // Supress the error displaing
     ini_set('display_errors', 'Off');
     // Enable the PHP to log errors
     ini_set('log_errors', 'On');
     // Set the PHP log file
     ini_set('error_log', path('storage') . 'logs' . DS . 'error.log');
 }
Example #6
0
 /**
  * Class constructor
  */
 public function __construct()
 {
     $this->slim = Kernel::instance()->getSlim();
     $this->container = $this->slim->getContainer();
     $this->logger = $this->container->get('logger');
     $this->httpcache = $this->container->get('httpcache');
     $this->session = $this->container->get('session');
     $this->cookie = $this->container->get('cookie');
     $this->flash = $this->container->get('flash');
     $this->csrf = $this->container->get('csrf');
     $this->view = $this->container->get('view');
     $this->acl = $this->container->get('acl');
     /*
     $class = get_called_class();
     $class = str_replace(['Mavis\\App\\Controllers\\', 'Controller'], '', $class);
     $view = ($this->template) ? $this->template : strtolower($class);
     $this->view->setTemplate($view);
     */
 }
Example #7
0
 public function __construct()
 {
     $this->container = Kernel::instance()->getSlim()->getContainer();
 }
Example #8
0
 /**
  * Handles the available handlers and pushes them to the Monolog\Logger instance
  *
  * @return void
  */
 protected function pushHandlers()
 {
     foreach (Config::get('kernel.logs.handlers') as $handler => $options) {
         switch ($handler) {
             case 'RotatingFileHandler':
                 if (!$options['enabled']) {
                     continue;
                 }
                 $level = static::nameToLevel($options['level']);
                 $chmod = 0 . $options['chmod'];
                 /*
                 $class = 'Monolog\\Formatter\\' . $options['formatter'];
                 $formatter = new $class();
                 */
                 // Is this handler enabled for this environment?
                 if (array_exists(array_flip($options['environments']), Kernel::env())) {
                     $rotateHandler = new RotatingFileHandler(path('logs') . $options['filename'] . '.log', $options['max'], $level, $chmod);
                     $rotateHandler->setFilenameFormat('{filename}-{date}', $options['date_format']);
                     $this->getLogger()->pushHandler($rotateHandler);
                 }
                 break;
             case 'BrowserConsoleHandler':
                 if (!$options['enabled']) {
                     continue;
                 }
                 // Is this handler enabled for this environment?
                 if (array_exists(array_flip($options['environments']), Kernel::env())) {
                     $this->getLogger()->pushHandler(new BrowserConsoleHandler());
                 }
                 break;
         }
     }
 }