Slimore
  • Namespace
  • Class

Namespaces

  • None
  • Slimore
    • Cache
      • Exception
    • Captcha
    • Database
    • Debug
    • Http
    • Image
    • Log
    • Middleware
    • Mvc
    • Pagination
    • Upload

Classes

  • Slimore\Cache\File
  • Slimore\Captcha\Builder
  • Slimore\Database\Manager
  • Slimore\Debug\Simpler
  • Slimore\Http\Client
  • Slimore\Image\Gd
  • Slimore\Log\Writer
  • Slimore\Middleware\Exceptions
  • Slimore\Mvc\Application
  • Slimore\Mvc\Controller
  • Slimore\Mvc\Model
  • Slimore\Mvc\View
  • Slimore\Pagination\Paginator
  • Slimore\Upload\Uploader

Exceptions

  • Slimore\Cache\Exception\File
  • Slimore\Captcha\Exception
  • Slimore\Database\Exception
  • Slimore\Http\Exception
  • Slimore\Mvc\Exception
  • Slimore\Pagination\Exception
  • Slimore\Upload\Exception

Functions

  • arrayToObject
  • console
  • controller
  • ctl
  • currentUrl
  • decrypt
  • detectDevice
  • encrypt
  • fileFormatSize
  • getDirectoryItems
  • getDpi
  • hexToRGB
  • html
  • imageDataUrl
  • iPad
  • iPhone
  • iPod
  • isAndroid
  • isApache
  • isBlackberry
  • isChrome
  • isCli
  • isFirefox
  • isFreeBSD
  • isIE
  • isIIS
  • isJson
  • isLinux
  • isMacOSX
  • isMobile
  • isNginx
  • isOpera
  • isSafari
  • isTablet
  • isUnix
  • isUnixLike
  • isWebOS
  • isWindows
  • js
  • jsonToArray
  • linkTag
  • password
  • phoneMaskCode
  • randomCharacters
  • replaceDirSeparator
  • rgbToHex
  • script
  • shortUrl
  • style
  1 <?php
  2 
  3 /**
  4  * Slimore - The fully (H)MVC framework based on the Slim PHP framework.
  5  *
  6  * @author      Pandao <slimore@ipandao.com>
  7  * @copyright   2015 Pandao
  8  * @link        http://github.com/slimore/slimore
  9  * @license     MIT License https://github.com/slimore/slimore#license
 10  * @version     0.1.0
 11  * @package     Slimore\Middleware
 12  */
 13 
 14 namespace Slimore\Middleware;
 15 
 16 /**
 17  * Class Exceptions
 18  *
 19  * @author Pandao
 20  * @package Slimore\Middleware
 21  */
 22 
 23 class Exceptions extends \Slim\Middleware
 24 {
 25     /**
 26      * @var array
 27      */
 28     protected $settings;
 29 
 30     /**
 31      * Constructor
 32      * @param array $settings
 33      */
 34 
 35     public function __construct($settings = [])
 36     {
 37         $this->settings = $settings;
 38     }
 39 
 40     /**
 41      * Call
 42      */
 43 
 44     public function call()
 45     {
 46         try
 47         {
 48             $this->next->call();
 49         }
 50         catch (\Exception $e)
 51         {
 52             $log = $this->app->getLog(); // Force Slim to append log to env if not already
 53             $env = $this->app->environment();
 54             $env['slim.log'] = $log;
 55             $env['slim.log']->error($e);
 56             $this->app->contentType('text/html');
 57             $this->app->response()->status(500);
 58             $this->app->response()->body($this->renderBody($env, $e));
 59         }
 60     }
 61 
 62     /**
 63      * Render response body
 64      *
 65      * @param  array      $env
 66      * @param  \Exception $exception
 67      * @return string
 68      */
 69 
 70     public function renderBody(&$env, $exception)
 71     {
 72         $title   = 'Slimore Application ErrorException';
 73         $code    = $exception->getCode();
 74         $message = $exception->getMessage();
 75         $file    = $exception->getFile();
 76         $line    = $exception->getLine();
 77         $type    = get_class($exception);
 78         $trace   = str_replace(array('#', "\n"), array('<div class="trace-line">#', '</div>'), $exception->getTraceAsString());
 79 
 80         $html = html($title, [
 81             '<meta http-equiv="X-UA-Compatible" content="IE=edge" />',
 82             '<meta name="renderer" content="webkit" />',
 83             '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />',
 84             style([
 85                 '*{margin:0;padding:0;}',
 86                 'html {font-size: 62.5%;}',
 87                 'html, body {max-width: 100%;width: 100%;}',
 88                 'body {font-size: 1.4rem;font-family: "Microsoft Yahei", Helvetica, Tahoma, STXihei, arial,verdana,sans-serif;background:#fff;color:#555;}',
 89                 'img {border: none;}',
 90                 'pre, pre code {font-family:Consolas, arial,verdana,sans-serif;}',
 91                 '#layout {padding: 6rem;}',
 92                 '#main {margin: 0 auto;line-height: 1.5;}',
 93                 '#main > h1 {font-size: 10rem;margin-bottom: 1rem;}',
 94                 '#main > h3 {margin-bottom: 2rem; font-size: 1.8rem;}',
 95                 '#main > h4 {margin-bottom: 1rem; font-size: 1.8rem;}',
 96                 '#main pre {margin: 1.5rem 0;white-space: pre-wrap;word-wrap: break-word;}',
 97                 '#main > p {white-space: pre-wrap;word-wrap: break-word;line-height: 1.3;margin-bottom: 0.6rem;}',
 98                 '#main > p > strong {width: 7rem;display:inline-block;}',
 99                 '.logo {text-align: left;border-top:1px solid #eee;margin-top: 5rem;padding: 3rem 0 0;color: #ccc;}',
100                 '.logo > h1 {font-weight: normal;font-size: 5rem;}',
101                 '.logo img {margin-left: -2rem;}',
102                 '.trace-line {padding: 0.3rem 0.6rem;margin-left:-0.6rem;-webkit-transition: background-color 300ms ease-out;transition: background-color 300ms ease-out;}',
103                 '.trace-line:hover {background:#fffccc;}'
104             ])
105         ], [
106             '<div id="layout">',
107                 '<div id="main">',
108                     '<h1>:(</h1>',
109                     '<h3>' . $type . '</h3>',
110                     '<h4>Details :</h4>',
111                     '<p><strong>Type: </strong> ' . $type . '</p>',
112                     '<p><strong>Message: </strong> ' . $message . '</p>',
113                     '<p><strong>File: </strong> ' . $file . '</p>',
114                     '<p><strong>Line: </strong> ' . $line . '</p>',
115                     '<br/>',
116                     '<h4>Trace:</h4>',
117                     '<pre>' . $trace . '</pre>',
118                     '<div class="logo">',
119                         '<h1>Slimore</h1>',
120                         '<p>The fully (H)MVC framework, based on the Slim PHP Framwork.</p>',
121                     '</div>',
122                 '</div>',
123             '</div>'
124         ]);
125 
126         return $html;
127     }
128 }
Slimore API documentation generated by ApiGen