/**
  * Registers custom error handler
  *
  * @access public
  * @static
  *
  * @return void
  */
 public static function loadErrorHandler()
 {
     set_error_handler(function ($errno, $errmsg, $filename, $linenum) {
         $date = date('Y-m-d H:i:s (T)');
         if (!file_exists(__DIR__ . '/../../app/logs/')) {
             mkdir(__DIR__ . '/../../app/logs/');
         }
         $f = fopen(__DIR__ . '/../../app/logs/errorlog.txt', 'a');
         if (!empty($f)) {
             $error = "____________________________________________________________\n";
             $error .= $date . "\n";
             $error .= $errno . "\n";
             $error .= $errmsg . "\n";
             $error .= $filename . "\n";
             $error .= $linenum . "\n";
             $error .= "____________________________________________________________\n";
             fwrite($f, $error);
             fclose($f);
         }
         if (Service::get('config')['mode'] == 'user') {
             $renderer = new Renderer(Service::get('config')['layouts']);
             $renderer->set('code', 500);
             $renderer->set('message', 'Oooops');
             $content = $renderer->generatePage('500.html');
             $response = new Response($content, array(), 500);
             $response->send();
         }
     });
 }
 /**
  * Content rendering method
  *
  * @access protected
  *
  * @param string $template
  * @param array  $args
  *
  * @return Response
  */
 protected function render($template, $args = array())
 {
     $renderer = new Renderer($this->generatePath());
     $keys = array();
     foreach ($args as $arg => $value) {
         $renderer->set($arg, $value);
         $keys[] = $arg;
     }
     return new Response($renderer->generatePage($template, $keys));
 }
 /**
  * Handles exception for user
  *
  * @access public
  * @static
  *
  * @param \Exception $exception
  * @param array      $messages
  *
  * @return Response
  * @throws ServiceException
  */
 public static function handleForUser(\Exception $exception, $messages = array())
 {
     if ($exception == null) {
         $exception = new \Exception('Sorry for the inconvenience. We are working to resolve this issue.
         Thank you for your patience.');
     }
     $renderer = new Renderer(Service::get('config')['error_500'], true);
     foreach ($messages as $message => $m) {
         $renderer->set($message, $m);
     }
     $content = $renderer->generatePage();
     $response = new Response($content, array(), 500);
     $exception->saveExceptionLog();
     return $response;
 }