@@ -40,7 +40,6 @@ |
||
| 40 | 40 | * Create a new route file registrar instance. |
| 41 | 41 | * |
| 42 | 42 | * @param \Syscodes\Components\Routing\Router $router |
| 43 | - |
|
| 44 | 43 | * @return void |
| 45 | 44 | */ |
| 46 | 45 | public function __construct(Router $router) |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | protected function registerUrlGenerator() |
| 76 | 76 | { |
| 77 | - $this->app->singleton('url', function ($app) { |
|
| 77 | + $this->app->singleton('url', function($app) { |
|
| 78 | 78 | $routes = $app['router']->getRoutes(); |
| 79 | 79 | |
| 80 | 80 | return new UrlGenerator($routes, $app['request']); |
| 81 | 81 | }); |
| 82 | 82 | |
| 83 | - $this->app->extend('url', function (UrlGeneratorContract $url, $app) { |
|
| 84 | - $url->setSessionResolver(function () use ($app) { |
|
| 83 | + $this->app->extend('url', function(UrlGeneratorContract $url, $app) { |
|
| 84 | + $url->setSessionResolver(function() use ($app) { |
|
| 85 | 85 | return $app['session'] ?? null; |
| 86 | 86 | }); |
| 87 | 87 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | protected function registerRedirector() |
| 98 | 98 | { |
| 99 | - $this->app->singleton('redirect', function ($app) { |
|
| 99 | + $this->app->singleton('redirect', function($app) { |
|
| 100 | 100 | $redirector = new Redirector($app['url']); |
| 101 | 101 | |
| 102 | 102 | if (isset($app['session.store'])) { |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return string|null |
| 154 | 154 | */ |
| 155 | - protected function getPreviousUrlSession(): string|null |
|
| 155 | + protected function getPreviousUrlSession(): string | null |
|
| 156 | 156 | { |
| 157 | 157 | $session = $this->getSession(); |
| 158 | 158 | |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | */ |
| 428 | 428 | public function format($root, $path, $tail = ''): string |
| 429 | 429 | { |
| 430 | - return trim($root .'/' .trim($path .'/' .$tail, '/'), '/'); |
|
| 430 | + return trim($root.'/'.trim($path.'/'.$tail, '/'), '/'); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /** |
@@ -103,7 +103,7 @@ |
||
| 103 | 103 | $uri = $this->url->format( |
| 104 | 104 | $root, |
| 105 | 105 | $this->replaceRouteParameters($route->getUri(), $parameters) |
| 106 | - ); |
|
| 106 | + ); |
|
| 107 | 107 | |
| 108 | 108 | if (preg_match_all('/{(.*?)}/', $uri, $missingParameters)) { |
| 109 | 109 | throw UrlGeneratorException::missingParameters($route, $missingParameters[1]); |
@@ -286,10 +286,10 @@ |
||
| 286 | 286 | // parameters that are in the array and add them to the query string or we |
| 287 | 287 | // will make the initial query string if it wasn't started with strings. |
| 288 | 288 | if (count($keyed) < count($parameters)) { |
| 289 | - $query .= '&' .implode('&', $this->getNumericParameters($parameters)); |
|
| 289 | + $query .= '&'.implode('&', $this->getNumericParameters($parameters)); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - return '?' .trim($query, '&'); |
|
| 292 | + return '?'.trim($query, '&'); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | if ($bytes < 1024) { |
| 106 | 106 | return $bytes.'B'; |
| 107 | 107 | } else if ($bytes < 1048576) { |
| 108 | - return round($bytes/1024, 2).'KB'; |
|
| 108 | + return round($bytes / 1024, 2).'KB'; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return round($bytes/1048576, 2).'MB'; |
|
| 111 | + return round($bytes / 1048576, 2).'MB'; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $origin = str_replace(["\r\n", "\r"], "\n", $origin); |
| 182 | - $origin = explode("\n", highlight_string($origin , true)); |
|
| 182 | + $origin = explode("\n", highlight_string($origin, true)); |
|
| 183 | 183 | $origin = str_replace('<br />', "\n", $origin [1]); |
| 184 | 184 | |
| 185 | 185 | $origin = explode("\n", str_replace("\r\n", "\n", $origin)); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $start = $start < 0 ? 0 : $start; |
| 190 | 190 | |
| 191 | 191 | // Get just the lines we need to display, while keeping line numbers... |
| 192 | - $origin = array_splice($origin, $start, $lines, true); |
|
| 192 | + $origin = array_splice($origin, $start, $lines, true); |
|
| 193 | 193 | |
| 194 | 194 | // Used to format the line number in the source |
| 195 | 195 | $format = '% '.strlen($start + $lines).'d'; |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $spans += substr_count($row, '<span') - substr_count($row, '</span'); |
| 206 | 206 | $row = str_replace(["\r", "\n"], ['', ''], $row); |
| 207 | 207 | |
| 208 | - if (($n+$start+1) == $lineNumber) { |
|
| 208 | + if (($n + $start + 1) == $lineNumber) { |
|
| 209 | 209 | preg_match_all('#<[^>]+>#', $row, $tags); |
| 210 | 210 | $out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s", |
| 211 | 211 | $n + $start + 1, |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | implode('', $tags[0]) |
| 214 | 214 | ); |
| 215 | 215 | } else { |
| 216 | - $out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start + 1, $row) ."\n"; |
|
| 216 | + $out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start + 1, $row)."\n"; |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | public function slug($original): string |
| 246 | 246 | { |
| 247 | 247 | $slug = str_replace(" ", "-", $original); |
| 248 | - $slug = preg_replace('/[^\w\d\-\_]/i',' ', $slug); |
|
| 248 | + $slug = preg_replace('/[^\w\d\-\_]/i', ' ', $slug); |
|
| 249 | 249 | |
| 250 | 250 | return strtolower($slug); |
| 251 | 251 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Instantiate the error view and prepare the vars |
| 271 | - call_user_func(function () { |
|
| 271 | + call_user_func(function() { |
|
| 272 | 272 | extract(func_get_arg(1)); |
| 273 | 273 | include func_get_arg(0); |
| 274 | 274 | }, $template, $vars); |
@@ -30,247 +30,247 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class TemplateHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * Benchmark instance. |
|
| 35 | - * |
|
| 36 | - * @var string $benchmark |
|
| 37 | - */ |
|
| 38 | - protected $benchmark; |
|
| 33 | + /** |
|
| 34 | + * Benchmark instance. |
|
| 35 | + * |
|
| 36 | + * @var string $benchmark |
|
| 37 | + */ |
|
| 38 | + protected $benchmark; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Nesting level of the output buffering mechanism. |
|
| 42 | - * |
|
| 43 | - * @var string $obLevel |
|
| 44 | - */ |
|
| 45 | - public $obLevel; |
|
| 40 | + /** |
|
| 41 | + * Nesting level of the output buffering mechanism. |
|
| 42 | + * |
|
| 43 | + * @var string $obLevel |
|
| 44 | + */ |
|
| 45 | + public $obLevel; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The functions of system what control errors and exceptions. |
|
| 49 | - * |
|
| 50 | - * @var string|object $system |
|
| 51 | - */ |
|
| 52 | - protected $system; |
|
| 47 | + /** |
|
| 48 | + * The functions of system what control errors and exceptions. |
|
| 49 | + * |
|
| 50 | + * @var string|object $system |
|
| 51 | + */ |
|
| 52 | + protected $system; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * An array of variables to be passed to all templates. |
|
| 56 | - * |
|
| 57 | - * @var array $variables |
|
| 58 | - */ |
|
| 59 | - protected $variables = []; |
|
| 54 | + /** |
|
| 55 | + * An array of variables to be passed to all templates. |
|
| 56 | + * |
|
| 57 | + * @var array $variables |
|
| 58 | + */ |
|
| 59 | + protected $variables = []; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Constructor. The TemplateHandler class instance. |
|
| 63 | - * |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public function __construct() |
|
| 67 | - { |
|
| 68 | - $this->system = new System; |
|
| 69 | - $this->benchmark = new Benchmark; |
|
| 70 | - $this->obLevel = $this->system->getOutputBufferLevel(); |
|
| 71 | - } |
|
| 61 | + /** |
|
| 62 | + * Constructor. The TemplateHandler class instance. |
|
| 63 | + * |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public function __construct() |
|
| 67 | + { |
|
| 68 | + $this->system = new System; |
|
| 69 | + $this->benchmark = new Benchmark; |
|
| 70 | + $this->obLevel = $this->system->getOutputBufferLevel(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Clean Path: This makes nicer looking paths for the error output. |
|
| 75 | - * |
|
| 76 | - * @param string $file |
|
| 77 | - * |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public function cleanPath($file): string |
|
| 81 | - { |
|
| 82 | - if (strpos($file, appPath().DIRECTORY_SEPARATOR) === 0) { |
|
| 83 | - $file = appPath().DIRECTORY_SEPARATOR.substr($file, strlen(appPath().DIRECTORY_SEPARATOR)); |
|
| 84 | - } elseif (strpos($file, basePath().DIRECTORY_SEPARATOR) === 0) { |
|
| 85 | - $file = basePath().DIRECTORY_SEPARATOR.substr($file, strlen(basePath().DIRECTORY_SEPARATOR)); |
|
| 86 | - } elseif (strpos($file, configPath().DIRECTORY_SEPARATOR) === 0) { |
|
| 87 | - $file = configPath().DIRECTORY_SEPARATOR.substr($file, strlen(configPath().DIRECTORY_SEPARATOR)); |
|
| 88 | - } elseif (strpos($file, resourcePath().DIRECTORY_SEPARATOR) === 0) { |
|
| 89 | - $file = resourcePath().DIRECTORY_SEPARATOR.substr($file, strlen(resourcePath().DIRECTORY_SEPARATOR)); |
|
| 90 | - } |
|
| 73 | + /** |
|
| 74 | + * Clean Path: This makes nicer looking paths for the error output. |
|
| 75 | + * |
|
| 76 | + * @param string $file |
|
| 77 | + * |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public function cleanPath($file): string |
|
| 81 | + { |
|
| 82 | + if (strpos($file, appPath().DIRECTORY_SEPARATOR) === 0) { |
|
| 83 | + $file = appPath().DIRECTORY_SEPARATOR.substr($file, strlen(appPath().DIRECTORY_SEPARATOR)); |
|
| 84 | + } elseif (strpos($file, basePath().DIRECTORY_SEPARATOR) === 0) { |
|
| 85 | + $file = basePath().DIRECTORY_SEPARATOR.substr($file, strlen(basePath().DIRECTORY_SEPARATOR)); |
|
| 86 | + } elseif (strpos($file, configPath().DIRECTORY_SEPARATOR) === 0) { |
|
| 87 | + $file = configPath().DIRECTORY_SEPARATOR.substr($file, strlen(configPath().DIRECTORY_SEPARATOR)); |
|
| 88 | + } elseif (strpos($file, resourcePath().DIRECTORY_SEPARATOR) === 0) { |
|
| 89 | + $file = resourcePath().DIRECTORY_SEPARATOR.substr($file, strlen(resourcePath().DIRECTORY_SEPARATOR)); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return $file; |
|
| 93 | - } |
|
| 92 | + return $file; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Display memory usage in real-world units. Intended for use |
|
| 97 | - * with memory_get_usage, etc. |
|
| 98 | - * |
|
| 99 | - * @param int $bytes |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function displayMemory(int $bytes): string |
|
| 104 | - { |
|
| 105 | - if ($bytes < 1024) { |
|
| 106 | - return $bytes.'B'; |
|
| 107 | - } else if ($bytes < 1048576) { |
|
| 108 | - return round($bytes/1024, 2).'KB'; |
|
| 109 | - } |
|
| 95 | + /** |
|
| 96 | + * Display memory usage in real-world units. Intended for use |
|
| 97 | + * with memory_get_usage, etc. |
|
| 98 | + * |
|
| 99 | + * @param int $bytes |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function displayMemory(int $bytes): string |
|
| 104 | + { |
|
| 105 | + if ($bytes < 1024) { |
|
| 106 | + return $bytes.'B'; |
|
| 107 | + } else if ($bytes < 1048576) { |
|
| 108 | + return round($bytes/1024, 2).'KB'; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - return round($bytes/1048576, 2).'MB'; |
|
| 112 | - } |
|
| 111 | + return round($bytes/1048576, 2).'MB'; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Escapes a string for output in an HTML document. |
|
| 116 | - * |
|
| 117 | - * @param string $text |
|
| 118 | - * |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - public function escape($text): string |
|
| 122 | - { |
|
| 123 | - $flags = ENT_QUOTES; |
|
| 114 | + /** |
|
| 115 | + * Escapes a string for output in an HTML document. |
|
| 116 | + * |
|
| 117 | + * @param string $text |
|
| 118 | + * |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + public function escape($text): string |
|
| 122 | + { |
|
| 123 | + $flags = ENT_QUOTES; |
|
| 124 | 124 | |
| 125 | - // HHVM has all constants defined, but only ENT_IGNORE |
|
| 126 | - // works at the moment |
|
| 127 | - if (defined("ENT_SUBSTITUTE") && ! defined("HHVM_VERSION")) { |
|
| 128 | - $flags |= ENT_SUBSTITUTE; |
|
| 129 | - } else { |
|
| 130 | - $flags |= ENT_IGNORE; |
|
| 131 | - } |
|
| 125 | + // HHVM has all constants defined, but only ENT_IGNORE |
|
| 126 | + // works at the moment |
|
| 127 | + if (defined("ENT_SUBSTITUTE") && ! defined("HHVM_VERSION")) { |
|
| 128 | + $flags |= ENT_SUBSTITUTE; |
|
| 129 | + } else { |
|
| 130 | + $flags |= ENT_IGNORE; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - $text = str_replace(chr(9), ' ', $text); |
|
| 133 | + $text = str_replace(chr(9), ' ', $text); |
|
| 134 | 134 | |
| 135 | - return htmlspecialchars($text, $flags, "UTF-8"); |
|
| 136 | - } |
|
| 135 | + return htmlspecialchars($text, $flags, "UTF-8"); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Returns all variables for this helper. |
|
| 140 | - * |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function getVariables(): array |
|
| 144 | - { |
|
| 145 | - return $this->variables; |
|
| 146 | - } |
|
| 138 | + /** |
|
| 139 | + * Returns all variables for this helper. |
|
| 140 | + * |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function getVariables(): array |
|
| 144 | + { |
|
| 145 | + return $this->variables; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Creates a syntax-highlighted version of a PHP file. |
|
| 150 | - * |
|
| 151 | - * @param string $file |
|
| 152 | - * @param int $lineNumber |
|
| 153 | - * @param int $lines |
|
| 154 | - * |
|
| 155 | - * @return bool|string |
|
| 156 | - * |
|
| 157 | - * @throws \Exception |
|
| 158 | - */ |
|
| 159 | - public function highlightFile($file, $lineNumber, $lines = 15) |
|
| 160 | - { |
|
| 161 | - if (empty ($file) || ! is_readable($file)) { |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 148 | + /** |
|
| 149 | + * Creates a syntax-highlighted version of a PHP file. |
|
| 150 | + * |
|
| 151 | + * @param string $file |
|
| 152 | + * @param int $lineNumber |
|
| 153 | + * @param int $lines |
|
| 154 | + * |
|
| 155 | + * @return bool|string |
|
| 156 | + * |
|
| 157 | + * @throws \Exception |
|
| 158 | + */ |
|
| 159 | + public function highlightFile($file, $lineNumber, $lines = 15) |
|
| 160 | + { |
|
| 161 | + if (empty ($file) || ! is_readable($file)) { |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - // Set our highlight colors: |
|
| 166 | - if (function_exists('ini_set')) { |
|
| 167 | - ini_set('highlight.bg', '#000'); |
|
| 168 | - ini_set('highlight.comment', '#959595'); |
|
| 169 | - ini_set('highlight.default', '#717DE8'); |
|
| 170 | - ini_set('highlight.html', '#06B'); |
|
| 171 | - ini_set('highlight.keyword', '#F47E3A'); |
|
| 172 | - ini_set('highlight.string', '#57C60D'); |
|
| 173 | - } |
|
| 165 | + // Set our highlight colors: |
|
| 166 | + if (function_exists('ini_set')) { |
|
| 167 | + ini_set('highlight.bg', '#000'); |
|
| 168 | + ini_set('highlight.comment', '#959595'); |
|
| 169 | + ini_set('highlight.default', '#717DE8'); |
|
| 170 | + ini_set('highlight.html', '#06B'); |
|
| 171 | + ini_set('highlight.keyword', '#F47E3A'); |
|
| 172 | + ini_set('highlight.string', '#57C60D'); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - try { |
|
| 176 | - $origin = file_get_contents($file); |
|
| 177 | - } catch (Exception $e) { |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 175 | + try { |
|
| 176 | + $origin = file_get_contents($file); |
|
| 177 | + } catch (Exception $e) { |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - $origin = str_replace(["\r\n", "\r"], "\n", $origin); |
|
| 182 | - $origin = explode("\n", highlight_string($origin , true)); |
|
| 183 | - $origin = str_replace('<br />', "\n", $origin [1]); |
|
| 181 | + $origin = str_replace(["\r\n", "\r"], "\n", $origin); |
|
| 182 | + $origin = explode("\n", highlight_string($origin , true)); |
|
| 183 | + $origin = str_replace('<br />', "\n", $origin [1]); |
|
| 184 | 184 | |
| 185 | - $origin = explode("\n", str_replace("\r\n", "\n", $origin)); |
|
| 185 | + $origin = explode("\n", str_replace("\r\n", "\n", $origin)); |
|
| 186 | 186 | |
| 187 | - // Get just the part to show |
|
| 188 | - $start = $lineNumber - (int) round($lines / 2); |
|
| 189 | - $start = $start < 0 ? 0 : $start; |
|
| 187 | + // Get just the part to show |
|
| 188 | + $start = $lineNumber - (int) round($lines / 2); |
|
| 189 | + $start = $start < 0 ? 0 : $start; |
|
| 190 | 190 | |
| 191 | - // Get just the lines we need to display, while keeping line numbers... |
|
| 192 | - $origin = array_splice($origin, $start, $lines, true); |
|
| 191 | + // Get just the lines we need to display, while keeping line numbers... |
|
| 192 | + $origin = array_splice($origin, $start, $lines, true); |
|
| 193 | 193 | |
| 194 | - // Used to format the line number in the source |
|
| 195 | - $format = '% '.strlen($start + $lines).'d'; |
|
| 194 | + // Used to format the line number in the source |
|
| 195 | + $format = '% '.strlen($start + $lines).'d'; |
|
| 196 | 196 | |
| 197 | - $out = ''; |
|
| 198 | - // Because the highlighting may have an uneven number |
|
| 199 | - // of open and close span tags on one line, we need |
|
| 200 | - // to ensure we can close them all to get the lines |
|
| 201 | - // showing correctly. |
|
| 202 | - $spans = 1; |
|
| 197 | + $out = ''; |
|
| 198 | + // Because the highlighting may have an uneven number |
|
| 199 | + // of open and close span tags on one line, we need |
|
| 200 | + // to ensure we can close them all to get the lines |
|
| 201 | + // showing correctly. |
|
| 202 | + $spans = 1; |
|
| 203 | 203 | |
| 204 | - foreach ($origin as $n => $row) { |
|
| 205 | - $spans += substr_count($row, '<span') - substr_count($row, '</span'); |
|
| 206 | - $row = str_replace(["\r", "\n"], ['', ''], $row); |
|
| 204 | + foreach ($origin as $n => $row) { |
|
| 205 | + $spans += substr_count($row, '<span') - substr_count($row, '</span'); |
|
| 206 | + $row = str_replace(["\r", "\n"], ['', ''], $row); |
|
| 207 | 207 | |
| 208 | - if (($n+$start+1) == $lineNumber) { |
|
| 209 | - preg_match_all('#<[^>]+>#', $row, $tags); |
|
| 210 | - $out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s", |
|
| 211 | - $n + $start + 1, |
|
| 212 | - strip_tags($row), |
|
| 213 | - implode('', $tags[0]) |
|
| 214 | - ); |
|
| 215 | - } else { |
|
| 216 | - $out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start + 1, $row) ."\n"; |
|
| 217 | - } |
|
| 218 | - } |
|
| 208 | + if (($n+$start+1) == $lineNumber) { |
|
| 209 | + preg_match_all('#<[^>]+>#', $row, $tags); |
|
| 210 | + $out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s", |
|
| 211 | + $n + $start + 1, |
|
| 212 | + strip_tags($row), |
|
| 213 | + implode('', $tags[0]) |
|
| 214 | + ); |
|
| 215 | + } else { |
|
| 216 | + $out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start + 1, $row) ."\n"; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - $out .= str_repeat('</span>', $spans); |
|
| 220 | + $out .= str_repeat('</span>', $spans); |
|
| 221 | 221 | |
| 222 | - return '<pre class="code-blocks"><code>'.$out.'</code></pre>'; |
|
| 223 | - } |
|
| 222 | + return '<pre class="code-blocks"><code>'.$out.'</code></pre>'; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Sets the variables to be passed to all templates rendered |
|
| 227 | - * by this template helper. |
|
| 228 | - * |
|
| 229 | - * @param array $variables |
|
| 230 | - * |
|
| 231 | - * @return void |
|
| 232 | - */ |
|
| 233 | - public function setVariables(array $variables): void |
|
| 234 | - { |
|
| 235 | - $this->variables = $variables; |
|
| 236 | - } |
|
| 225 | + /** |
|
| 226 | + * Sets the variables to be passed to all templates rendered |
|
| 227 | + * by this template helper. |
|
| 228 | + * |
|
| 229 | + * @param array $variables |
|
| 230 | + * |
|
| 231 | + * @return void |
|
| 232 | + */ |
|
| 233 | + public function setVariables(array $variables): void |
|
| 234 | + { |
|
| 235 | + $this->variables = $variables; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Convert a string to a slug version of itself. |
|
| 240 | - * |
|
| 241 | - * @param string $original |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function slug($original): string |
|
| 246 | - { |
|
| 247 | - $slug = str_replace(" ", "-", $original); |
|
| 248 | - $slug = preg_replace('/[^\w\d\-\_]/i',' ', $slug); |
|
| 238 | + /** |
|
| 239 | + * Convert a string to a slug version of itself. |
|
| 240 | + * |
|
| 241 | + * @param string $original |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function slug($original): string |
|
| 246 | + { |
|
| 247 | + $slug = str_replace(" ", "-", $original); |
|
| 248 | + $slug = preg_replace('/[^\w\d\-\_]/i',' ', $slug); |
|
| 249 | 249 | |
| 250 | - return strtolower($slug); |
|
| 251 | - } |
|
| 250 | + return strtolower($slug); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Given an exception and status code will display the error to the client. |
|
| 255 | - * |
|
| 256 | - * @param string $template |
|
| 257 | - * |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - public function render($template): void |
|
| 261 | - { |
|
| 262 | - $vars = $this->getVariables(); |
|
| 253 | + /** |
|
| 254 | + * Given an exception and status code will display the error to the client. |
|
| 255 | + * |
|
| 256 | + * @param string $template |
|
| 257 | + * |
|
| 258 | + * @return void |
|
| 259 | + */ |
|
| 260 | + public function render($template): void |
|
| 261 | + { |
|
| 262 | + $vars = $this->getVariables(); |
|
| 263 | 263 | |
| 264 | - $vars['template'] = $this; |
|
| 264 | + $vars['template'] = $this; |
|
| 265 | 265 | |
| 266 | - if ($this->system->getOutputBufferLevel() > $this->obLevel + 1) { |
|
| 267 | - @$this->system->endOutputBuffering(); |
|
| 268 | - } |
|
| 266 | + if ($this->system->getOutputBufferLevel() > $this->obLevel + 1) { |
|
| 267 | + @$this->system->endOutputBuffering(); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - // Instantiate the error view and prepare the vars |
|
| 271 | - call_user_func(function () { |
|
| 272 | - extract(func_get_arg(1)); |
|
| 273 | - include func_get_arg(0); |
|
| 274 | - }, $template, $vars); |
|
| 275 | - } |
|
| 270 | + // Instantiate the error view and prepare the vars |
|
| 271 | + call_user_func(function () { |
|
| 272 | + extract(func_get_arg(1)); |
|
| 273 | + include func_get_arg(0); |
|
| 274 | + }, $template, $vars); |
|
| 275 | + } |
|
| 276 | 276 | } |
| 277 | 277 | \ No newline at end of file |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $exception->getFile(), |
| 56 | 56 | $exception->getLine(), |
| 57 | 57 | $this->getTraceOutput() |
| 58 | - ); |
|
| 58 | + ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $frame->getFunction(), |
| 88 | 88 | $frame->getFile(), |
| 89 | 89 | $frame->getLine() |
| 90 | - ); |
|
| 90 | + ); |
|
| 91 | 91 | |
| 92 | 92 | $line--; |
| 93 | 93 | } |
@@ -213,13 +213,13 @@ |
||
| 213 | 213 | return $this->file; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * Sets the file path. |
|
| 218 | - * |
|
| 219 | - * @param string $file |
|
| 220 | - * |
|
| 221 | - * @return static |
|
| 222 | - */ |
|
| 216 | + /** |
|
| 217 | + * Sets the file path. |
|
| 218 | + * |
|
| 219 | + * @param string $file |
|
| 220 | + * |
|
| 221 | + * @return static |
|
| 222 | + */ |
|
| 223 | 223 | public function setFile($file): static |
| 224 | 224 | { |
| 225 | 225 | $this->file = $file; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $this->system->endOutputBuffering(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if (Misc::sendHeaders() && $handlerContentType) { |
|
| 159 | + if (Misc::sendHeaders() && $handlerContentType) { |
|
| 160 | 160 | header("Content-Type: {$handlerContentType}"); |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | if ( ! $handler instanceof MainHandler) { |
| 319 | 319 | throw new InvalidArgumentException( |
| 320 | - "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
| 320 | + "Argument to ".__METHOD__." must be a callable, or instance of ". |
|
| 321 | 321 | "Syscodes\Components\\Contracts\\Debug\\Handler" |
| 322 | 322 | ); |
| 323 | 323 | } |
@@ -139,8 +139,7 @@ |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
| 142 | - } |
|
| 143 | - finally { |
|
| 142 | + } finally { |
|
| 144 | 143 | // Returns the contents of the output buffer |
| 145 | 144 | $output = $this->system->CleanOutputBuffer(); |
| 146 | 145 | } |
@@ -38,414 +38,414 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class GDebug implements DebugContract |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * Allow Handlers to force the script to quit. |
|
| 43 | - * |
|
| 44 | - * @var bool $allowQuit |
|
| 45 | - */ |
|
| 46 | - protected $allowQuit = true; |
|
| 41 | + /** |
|
| 42 | + * Allow Handlers to force the script to quit. |
|
| 43 | + * |
|
| 44 | + * @var bool $allowQuit |
|
| 45 | + */ |
|
| 46 | + protected $allowQuit = true; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Benchmark instance. |
|
| 50 | - * |
|
| 51 | - * @var string|object $benchmark |
|
| 52 | - */ |
|
| 53 | - protected $benchmark; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The handler stack. |
|
| 57 | - * |
|
| 58 | - * @var array $handlerStack |
|
| 59 | - */ |
|
| 60 | - protected $handlerStack = []; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * The send Http code by default: 500 Internal Server Error. |
|
| 64 | - * |
|
| 65 | - * @var bool $sendHttpCode |
|
| 66 | - */ |
|
| 67 | - protected $sendHttpCode = 500; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The send output. |
|
| 71 | - * |
|
| 72 | - * @var bool $sendOutput |
|
| 73 | - */ |
|
| 74 | - protected $sendOutput = true; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * The functions of system what control errors and exceptions. |
|
| 78 | - * |
|
| 79 | - * @var string|object $system |
|
| 80 | - */ |
|
| 81 | - protected $system; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * In certain scenarios, like in shutdown handler, we can not throw exceptions. |
|
| 85 | - * |
|
| 86 | - * @var bool $throwExceptions |
|
| 87 | - */ |
|
| 88 | - protected $throwExceptions = true; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Constructor. The Debug class instance. |
|
| 92 | - * |
|
| 93 | - * @param \Syscodes\Components\Debug\Util\System|null $system |
|
| 94 | - * |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - public function __construct(System $system = null) |
|
| 98 | - { |
|
| 99 | - $this->system = $system ?: new System; |
|
| 100 | - $this->benchmark = new Benchmark; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
| 105 | - * error, display it if display_errors is on, and fire an event that allows custom actions |
|
| 106 | - * to be taken at this point. |
|
| 107 | - * |
|
| 108 | - * @param \Throwable $exception |
|
| 109 | - * |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function handleException(Throwable $exception): string |
|
| 113 | - { |
|
| 114 | - // The start benchmark |
|
| 115 | - $this->benchmark->start('total_execution', LENEVOR_START); |
|
| 116 | - |
|
| 117 | - $supervisor = $this->getSupervisor($exception); |
|
| 118 | - |
|
| 119 | - // Start buffer |
|
| 120 | - $this->system->startOutputBuferring(); |
|
| 121 | - |
|
| 122 | - $handlerResponse = null; |
|
| 123 | - $handlerContentType = null; |
|
| 48 | + /** |
|
| 49 | + * Benchmark instance. |
|
| 50 | + * |
|
| 51 | + * @var string|object $benchmark |
|
| 52 | + */ |
|
| 53 | + protected $benchmark; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The handler stack. |
|
| 57 | + * |
|
| 58 | + * @var array $handlerStack |
|
| 59 | + */ |
|
| 60 | + protected $handlerStack = []; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * The send Http code by default: 500 Internal Server Error. |
|
| 64 | + * |
|
| 65 | + * @var bool $sendHttpCode |
|
| 66 | + */ |
|
| 67 | + protected $sendHttpCode = 500; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The send output. |
|
| 71 | + * |
|
| 72 | + * @var bool $sendOutput |
|
| 73 | + */ |
|
| 74 | + protected $sendOutput = true; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * The functions of system what control errors and exceptions. |
|
| 78 | + * |
|
| 79 | + * @var string|object $system |
|
| 80 | + */ |
|
| 81 | + protected $system; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * In certain scenarios, like in shutdown handler, we can not throw exceptions. |
|
| 85 | + * |
|
| 86 | + * @var bool $throwExceptions |
|
| 87 | + */ |
|
| 88 | + protected $throwExceptions = true; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Constructor. The Debug class instance. |
|
| 92 | + * |
|
| 93 | + * @param \Syscodes\Components\Debug\Util\System|null $system |
|
| 94 | + * |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + public function __construct(System $system = null) |
|
| 98 | + { |
|
| 99 | + $this->system = $system ?: new System; |
|
| 100 | + $this->benchmark = new Benchmark; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
| 105 | + * error, display it if display_errors is on, and fire an event that allows custom actions |
|
| 106 | + * to be taken at this point. |
|
| 107 | + * |
|
| 108 | + * @param \Throwable $exception |
|
| 109 | + * |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function handleException(Throwable $exception): string |
|
| 113 | + { |
|
| 114 | + // The start benchmark |
|
| 115 | + $this->benchmark->start('total_execution', LENEVOR_START); |
|
| 116 | + |
|
| 117 | + $supervisor = $this->getSupervisor($exception); |
|
| 118 | + |
|
| 119 | + // Start buffer |
|
| 120 | + $this->system->startOutputBuferring(); |
|
| 121 | + |
|
| 122 | + $handlerResponse = null; |
|
| 123 | + $handlerContentType = null; |
|
| 124 | 124 | |
| 125 | - try { |
|
| 126 | - foreach (array_reverse($this->handlerStack) as $handler) { |
|
| 127 | - $handler->setDebug($this); |
|
| 128 | - $handler->setException($exception); |
|
| 129 | - $handler->setSupervisor($supervisor); |
|
| 125 | + try { |
|
| 126 | + foreach (array_reverse($this->handlerStack) as $handler) { |
|
| 127 | + $handler->setDebug($this); |
|
| 128 | + $handler->setException($exception); |
|
| 129 | + $handler->setSupervisor($supervisor); |
|
| 130 | 130 | |
| 131 | - $handlerResponse = $handler->handle(); |
|
| 131 | + $handlerResponse = $handler->handle(); |
|
| 132 | 132 | |
| 133 | - // Collect the content type for possible sending in the headers |
|
| 134 | - $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; |
|
| 133 | + // Collect the content type for possible sending in the headers |
|
| 134 | + $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; |
|
| 135 | 135 | |
| 136 | - if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) { |
|
| 137 | - break; |
|
| 138 | - } |
|
| 139 | - } |
|
| 136 | + if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) { |
|
| 137 | + break; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
|
| 142 | - } |
|
| 143 | - finally { |
|
| 144 | - // Returns the contents of the output buffer |
|
| 145 | - $output = $this->system->CleanOutputBuffer(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Returns the contents of the output buffer for loading time of page |
|
| 149 | - $totalTime = $this->benchmark->getElapsedTime('total_execution'); |
|
| 150 | - $output = str_replace('{{ elapsed_time }}', $totalTime, $output); |
|
| 151 | - |
|
| 152 | - if ($this->writeToOutput()) { |
|
| 153 | - if ($quit) { |
|
| 154 | - while ($this->system->getOutputBufferLevel() > 0) { |
|
| 155 | - // Cleanes the output buffer |
|
| 156 | - $this->system->endOutputBuffering(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - if (Misc::sendHeaders() && $handlerContentType) { |
|
| 160 | - header("Content-Type: {$handlerContentType}"); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $this->writeToOutputBuffer($output); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if ($quit) { |
|
| 168 | - $this->system->flushOutputBuffer(); |
|
| 169 | - $this->system->stopException($this->sendHttpCode()); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $output; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Allow Handlers to force the script to quit. |
|
| 177 | - * |
|
| 178 | - * @param bool|int|null $exit |
|
| 179 | - * |
|
| 180 | - * @return bool |
|
| 181 | - */ |
|
| 182 | - public function allowQuit($exit = null): bool |
|
| 183 | - { |
|
| 184 | - if (func_num_args() == 0) { |
|
| 185 | - return $this->allowQuit; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $this->allowQuit = (bool) $exit; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Lenevor Exception push output directly to the client it the data |
|
| 193 | - * if they are true, but if it is false, the output will be returned |
|
| 194 | - * by exception. |
|
| 195 | - * |
|
| 196 | - * @param bool|int|null $send |
|
| 197 | - * |
|
| 198 | - * @return bool |
|
| 199 | - */ |
|
| 200 | - public function writeToOutput($send = null): bool |
|
| 201 | - { |
|
| 202 | - if (func_num_args() == 0) { |
|
| 203 | - return $this->sendOutput; |
|
| 204 | - } |
|
| 141 | + $quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
|
| 142 | + } |
|
| 143 | + finally { |
|
| 144 | + // Returns the contents of the output buffer |
|
| 145 | + $output = $this->system->CleanOutputBuffer(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Returns the contents of the output buffer for loading time of page |
|
| 149 | + $totalTime = $this->benchmark->getElapsedTime('total_execution'); |
|
| 150 | + $output = str_replace('{{ elapsed_time }}', $totalTime, $output); |
|
| 151 | + |
|
| 152 | + if ($this->writeToOutput()) { |
|
| 153 | + if ($quit) { |
|
| 154 | + while ($this->system->getOutputBufferLevel() > 0) { |
|
| 155 | + // Cleanes the output buffer |
|
| 156 | + $this->system->endOutputBuffering(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + if (Misc::sendHeaders() && $handlerContentType) { |
|
| 160 | + header("Content-Type: {$handlerContentType}"); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $this->writeToOutputBuffer($output); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if ($quit) { |
|
| 168 | + $this->system->flushOutputBuffer(); |
|
| 169 | + $this->system->stopException($this->sendHttpCode()); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $output; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Allow Handlers to force the script to quit. |
|
| 177 | + * |
|
| 178 | + * @param bool|int|null $exit |
|
| 179 | + * |
|
| 180 | + * @return bool |
|
| 181 | + */ |
|
| 182 | + public function allowQuit($exit = null): bool |
|
| 183 | + { |
|
| 184 | + if (func_num_args() == 0) { |
|
| 185 | + return $this->allowQuit; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $this->allowQuit = (bool) $exit; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Lenevor Exception push output directly to the client it the data |
|
| 193 | + * if they are true, but if it is false, the output will be returned |
|
| 194 | + * by exception. |
|
| 195 | + * |
|
| 196 | + * @param bool|int|null $send |
|
| 197 | + * |
|
| 198 | + * @return bool |
|
| 199 | + */ |
|
| 200 | + public function writeToOutput($send = null): bool |
|
| 201 | + { |
|
| 202 | + if (func_num_args() == 0) { |
|
| 203 | + return $this->sendOutput; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - return $this->sendOutput = (bool) $send; |
|
| 207 | - } |
|
| 206 | + return $this->sendOutput = (bool) $send; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Generate output to the browser. |
|
| 211 | - * |
|
| 212 | - * @param string $output |
|
| 213 | - * |
|
| 214 | - * @return static |
|
| 215 | - */ |
|
| 216 | - protected function writeToOutputBuffer($output): static |
|
| 217 | - { |
|
| 218 | - if ($this->sendHttpCode() && Misc::sendHeaders()) { |
|
| 219 | - $this->system->setHttpResponseCode($this->sendHttpCode()); |
|
| 220 | - } |
|
| 209 | + /** |
|
| 210 | + * Generate output to the browser. |
|
| 211 | + * |
|
| 212 | + * @param string $output |
|
| 213 | + * |
|
| 214 | + * @return static |
|
| 215 | + */ |
|
| 216 | + protected function writeToOutputBuffer($output): static |
|
| 217 | + { |
|
| 218 | + if ($this->sendHttpCode() && Misc::sendHeaders()) { |
|
| 219 | + $this->system->setHttpResponseCode($this->sendHttpCode()); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - echo $output; |
|
| 222 | + echo $output; |
|
| 223 | 223 | |
| 224 | - return $this; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Error handler |
|
| 229 | - * |
|
| 230 | - * This will catch the php native error and treat it as a exception which will |
|
| 231 | - * provide a full back trace on all errors. |
|
| 232 | - * |
|
| 233 | - * @param int $level |
|
| 234 | - * @param string $message |
|
| 235 | - * @param string|null $file |
|
| 236 | - * @param int|null $line |
|
| 237 | - * |
|
| 238 | - * @return bool |
|
| 239 | - * |
|
| 240 | - * @throws \ErrorException |
|
| 241 | - */ |
|
| 242 | - public function handleError( |
|
| 243 | - int $level, |
|
| 244 | - string $message, |
|
| 245 | - string $file = null, |
|
| 246 | - int $line = null |
|
| 247 | - ): bool { |
|
| 248 | - if ($level & $this->system->getErrorReportingLevel()) { |
|
| 249 | - $exception = new ErrorException($message, $level, $level, $file, $line); |
|
| 250 | - |
|
| 251 | - if ($this->throwExceptions) { |
|
| 252 | - throw $exception; |
|
| 253 | - } else { |
|
| 254 | - $this->handleException($exception); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return true; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return false; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Appends a handler to the end of the stack. |
|
| 265 | - * |
|
| 266 | - * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
| 267 | - * |
|
| 268 | - * @return static |
|
| 269 | - */ |
|
| 270 | - public function appendHandler($handler): static |
|
| 271 | - { |
|
| 272 | - array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
| 273 | - |
|
| 274 | - return $this; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Prepends a handler to the start of the stack. |
|
| 279 | - * |
|
| 280 | - * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
| 281 | - * |
|
| 282 | - * @return static |
|
| 283 | - */ |
|
| 284 | - public function prependHandler($handler): static |
|
| 285 | - { |
|
| 286 | - return $this->pushHandler($handler); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Pushes a handler to the end of the stack. |
|
| 291 | - * |
|
| 292 | - * @param string|callable $handler |
|
| 293 | - * |
|
| 294 | - * @return static |
|
| 295 | - */ |
|
| 296 | - public function pushHandler($handler): static |
|
| 297 | - { |
|
| 298 | - $this->handlerStack[] = $this->resolveHandler($handler); |
|
| 299 | - |
|
| 300 | - return $this; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Create a CallbackHandler from callable and throw if handler is invalid. |
|
| 305 | - * |
|
| 306 | - * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
| 307 | - * |
|
| 308 | - * @return \Syscodes\Components\Contracts\Debug\Handler |
|
| 309 | - * |
|
| 310 | - * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Components\Contracts\Debug\Handler |
|
| 311 | - */ |
|
| 312 | - protected function resolveHandler($handler) |
|
| 313 | - { |
|
| 314 | - if (is_callable($handler)) { |
|
| 315 | - $handler = new CallbackHandler($handler); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if ( ! $handler instanceof MainHandler) { |
|
| 319 | - throw new InvalidArgumentException( |
|
| 320 | - "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
| 321 | - "Syscodes\Components\\Contracts\\Debug\\Handler" |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return $handler; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Returns an array with all handlers, in the order they were added to the stack. |
|
| 330 | - * |
|
| 331 | - * @return array |
|
| 332 | - */ |
|
| 333 | - public function getHandlers(): array |
|
| 334 | - { |
|
| 335 | - return $this->handlerStack; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Clears all handlers in the handlerStack, including the default PleasingPage handler. |
|
| 340 | - * |
|
| 341 | - * @return static |
|
| 342 | - */ |
|
| 343 | - public function clearHandlers(): static |
|
| 344 | - { |
|
| 345 | - $this->handlerStack = []; |
|
| 346 | - |
|
| 347 | - return $this; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Removes the last handler in the stack and returns it. |
|
| 352 | - * |
|
| 353 | - * @return array|null |
|
| 354 | - */ |
|
| 355 | - public function popHandler() |
|
| 356 | - { |
|
| 357 | - return array_pop($this->handlerStack); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Gets supervisor already specified. |
|
| 362 | - * |
|
| 363 | - * @param \Throwable $exception |
|
| 364 | - * |
|
| 365 | - * @return \Syscodes\Components\Debug\Engine\Supervisor |
|
| 366 | - */ |
|
| 367 | - protected function getSupervisor(Throwable $exception) |
|
| 368 | - { |
|
| 369 | - return new Supervisor($exception); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Unregisters all handlers registered by this Debug instance. |
|
| 374 | - * |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - public function off(): void |
|
| 378 | - { |
|
| 379 | - $this->system->restoreExceptionHandler(); |
|
| 380 | - $this->system->restoreErrorHandler(); |
|
| 381 | - } |
|
| 224 | + return $this; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Error handler |
|
| 229 | + * |
|
| 230 | + * This will catch the php native error and treat it as a exception which will |
|
| 231 | + * provide a full back trace on all errors. |
|
| 232 | + * |
|
| 233 | + * @param int $level |
|
| 234 | + * @param string $message |
|
| 235 | + * @param string|null $file |
|
| 236 | + * @param int|null $line |
|
| 237 | + * |
|
| 238 | + * @return bool |
|
| 239 | + * |
|
| 240 | + * @throws \ErrorException |
|
| 241 | + */ |
|
| 242 | + public function handleError( |
|
| 243 | + int $level, |
|
| 244 | + string $message, |
|
| 245 | + string $file = null, |
|
| 246 | + int $line = null |
|
| 247 | + ): bool { |
|
| 248 | + if ($level & $this->system->getErrorReportingLevel()) { |
|
| 249 | + $exception = new ErrorException($message, $level, $level, $file, $line); |
|
| 250 | + |
|
| 251 | + if ($this->throwExceptions) { |
|
| 252 | + throw $exception; |
|
| 253 | + } else { |
|
| 254 | + $this->handleException($exception); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return true; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return false; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Appends a handler to the end of the stack. |
|
| 265 | + * |
|
| 266 | + * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
| 267 | + * |
|
| 268 | + * @return static |
|
| 269 | + */ |
|
| 270 | + public function appendHandler($handler): static |
|
| 271 | + { |
|
| 272 | + array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
| 273 | + |
|
| 274 | + return $this; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Prepends a handler to the start of the stack. |
|
| 279 | + * |
|
| 280 | + * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
| 281 | + * |
|
| 282 | + * @return static |
|
| 283 | + */ |
|
| 284 | + public function prependHandler($handler): static |
|
| 285 | + { |
|
| 286 | + return $this->pushHandler($handler); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Pushes a handler to the end of the stack. |
|
| 291 | + * |
|
| 292 | + * @param string|callable $handler |
|
| 293 | + * |
|
| 294 | + * @return static |
|
| 295 | + */ |
|
| 296 | + public function pushHandler($handler): static |
|
| 297 | + { |
|
| 298 | + $this->handlerStack[] = $this->resolveHandler($handler); |
|
| 299 | + |
|
| 300 | + return $this; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Create a CallbackHandler from callable and throw if handler is invalid. |
|
| 305 | + * |
|
| 306 | + * @param \Callable|\Syscodes\Components\Contracts\Debug\Handler $handler |
|
| 307 | + * |
|
| 308 | + * @return \Syscodes\Components\Contracts\Debug\Handler |
|
| 309 | + * |
|
| 310 | + * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Components\Contracts\Debug\Handler |
|
| 311 | + */ |
|
| 312 | + protected function resolveHandler($handler) |
|
| 313 | + { |
|
| 314 | + if (is_callable($handler)) { |
|
| 315 | + $handler = new CallbackHandler($handler); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if ( ! $handler instanceof MainHandler) { |
|
| 319 | + throw new InvalidArgumentException( |
|
| 320 | + "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
| 321 | + "Syscodes\Components\\Contracts\\Debug\\Handler" |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return $handler; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Returns an array with all handlers, in the order they were added to the stack. |
|
| 330 | + * |
|
| 331 | + * @return array |
|
| 332 | + */ |
|
| 333 | + public function getHandlers(): array |
|
| 334 | + { |
|
| 335 | + return $this->handlerStack; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Clears all handlers in the handlerStack, including the default PleasingPage handler. |
|
| 340 | + * |
|
| 341 | + * @return static |
|
| 342 | + */ |
|
| 343 | + public function clearHandlers(): static |
|
| 344 | + { |
|
| 345 | + $this->handlerStack = []; |
|
| 346 | + |
|
| 347 | + return $this; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Removes the last handler in the stack and returns it. |
|
| 352 | + * |
|
| 353 | + * @return array|null |
|
| 354 | + */ |
|
| 355 | + public function popHandler() |
|
| 356 | + { |
|
| 357 | + return array_pop($this->handlerStack); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Gets supervisor already specified. |
|
| 362 | + * |
|
| 363 | + * @param \Throwable $exception |
|
| 364 | + * |
|
| 365 | + * @return \Syscodes\Components\Debug\Engine\Supervisor |
|
| 366 | + */ |
|
| 367 | + protected function getSupervisor(Throwable $exception) |
|
| 368 | + { |
|
| 369 | + return new Supervisor($exception); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Unregisters all handlers registered by this Debug instance. |
|
| 374 | + * |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + public function off(): void |
|
| 378 | + { |
|
| 379 | + $this->system->restoreExceptionHandler(); |
|
| 380 | + $this->system->restoreErrorHandler(); |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - /** |
|
| 384 | - * Registers this instance as an error handler. |
|
| 385 | - * |
|
| 386 | - * @return void |
|
| 387 | - */ |
|
| 388 | - public function on() : void |
|
| 389 | - { |
|
| 390 | - // Set the exception handler |
|
| 391 | - $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]); |
|
| 392 | - // Set the error handler |
|
| 393 | - $this->system->setErrorHandler([$this, self::ERROR_HANDLER]); |
|
| 394 | - // Set the handler for shutdown to catch Parse errors |
|
| 395 | - $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
| 400 | - * to use 502, 503, or another 5xx family code. |
|
| 401 | - * |
|
| 402 | - * @param bool|int $code |
|
| 403 | - * |
|
| 404 | - * @return int|false |
|
| 405 | - * |
|
| 406 | - * @throws \InvalidArgumentException |
|
| 407 | - */ |
|
| 408 | - public function sendHttpCode($code = null) |
|
| 409 | - { |
|
| 410 | - if (func_num_args() == 0) { |
|
| 411 | - return $this->sendHttpCode; |
|
| 412 | - } |
|
| 383 | + /** |
|
| 384 | + * Registers this instance as an error handler. |
|
| 385 | + * |
|
| 386 | + * @return void |
|
| 387 | + */ |
|
| 388 | + public function on() : void |
|
| 389 | + { |
|
| 390 | + // Set the exception handler |
|
| 391 | + $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]); |
|
| 392 | + // Set the error handler |
|
| 393 | + $this->system->setErrorHandler([$this, self::ERROR_HANDLER]); |
|
| 394 | + // Set the handler for shutdown to catch Parse errors |
|
| 395 | + $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
| 400 | + * to use 502, 503, or another 5xx family code. |
|
| 401 | + * |
|
| 402 | + * @param bool|int $code |
|
| 403 | + * |
|
| 404 | + * @return int|false |
|
| 405 | + * |
|
| 406 | + * @throws \InvalidArgumentException |
|
| 407 | + */ |
|
| 408 | + public function sendHttpCode($code = null) |
|
| 409 | + { |
|
| 410 | + if (func_num_args() == 0) { |
|
| 411 | + return $this->sendHttpCode; |
|
| 412 | + } |
|
| 413 | 413 | |
| 414 | - if ( ! $code) { |
|
| 415 | - return $this->sendHttpCode = false; |
|
| 416 | - } |
|
| 414 | + if ( ! $code) { |
|
| 415 | + return $this->sendHttpCode = false; |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - if ($code === true) { |
|
| 419 | - $code = 500; |
|
| 420 | - } |
|
| 418 | + if ($code === true) { |
|
| 419 | + $code = 500; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - if ($code < 400 || 600 <= $code) { |
|
| 423 | - throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx"); |
|
| 424 | - } |
|
| 422 | + if ($code < 400 || 600 <= $code) { |
|
| 423 | + throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx"); |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - return $this->sendHttpCode = $code; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * This will catch errors that are generated at the shutdown level of execution. |
|
| 431 | - * |
|
| 432 | - * @return void |
|
| 433 | - * |
|
| 434 | - * @throws \ErrorException |
|
| 435 | - */ |
|
| 436 | - public function handleShutdown() |
|
| 437 | - { |
|
| 438 | - $this->throwExceptions = false; |
|
| 439 | - |
|
| 440 | - $error = $this->system->getLastError(); |
|
| 441 | - |
|
| 442 | - // If we've got an error that hasn't been displayed, then convert |
|
| 443 | - // it to an Exception and use the Exception handler to display it |
|
| 444 | - // to the user |
|
| 445 | - if ($error && Misc::isFatalError($error['type'])) { |
|
| 446 | - $this->allowQuit = false; |
|
| 426 | + return $this->sendHttpCode = $code; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * This will catch errors that are generated at the shutdown level of execution. |
|
| 431 | + * |
|
| 432 | + * @return void |
|
| 433 | + * |
|
| 434 | + * @throws \ErrorException |
|
| 435 | + */ |
|
| 436 | + public function handleShutdown() |
|
| 437 | + { |
|
| 438 | + $this->throwExceptions = false; |
|
| 439 | + |
|
| 440 | + $error = $this->system->getLastError(); |
|
| 441 | + |
|
| 442 | + // If we've got an error that hasn't been displayed, then convert |
|
| 443 | + // it to an Exception and use the Exception handler to display it |
|
| 444 | + // to the user |
|
| 445 | + if ($error && Misc::isFatalError($error['type'])) { |
|
| 446 | + $this->allowQuit = false; |
|
| 447 | 447 | |
| 448 | - $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
|
| 449 | - } |
|
| 450 | - } |
|
| 448 | + $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | 451 | } |
| 452 | 452 | \ No newline at end of file |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | $replace = 0 === strcasecmp($name, 'Content-Type'); |
| 99 | 99 | |
| 100 | 100 | foreach ($values as $value) { |
| 101 | - header($name.': '. $value, $replace, $this->statusCode); |
|
| 101 | + header($name.': '.$value, $replace, $this->statusCode); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -34,199 +34,199 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Response |
| 36 | 36 | { |
| 37 | - use HttpResponse, |
|
| 37 | + use HttpResponse, |
|
| 38 | 38 | HttpStatusCode; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Sets up the response with a content and a status code. |
|
| 42 | - * |
|
| 43 | - * @param mixed $content The response content |
|
| 44 | - * @param int $status The response status |
|
| 45 | - * @param array $headers Array of HTTP headers for this response |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function __construct($content = '', int $status = 200, array $headers = []) |
|
| 50 | - { |
|
| 51 | - $this->headers = new ResponseHeaders($headers); |
|
| 40 | + /** |
|
| 41 | + * Sets up the response with a content and a status code. |
|
| 42 | + * |
|
| 43 | + * @param mixed $content The response content |
|
| 44 | + * @param int $status The response status |
|
| 45 | + * @param array $headers Array of HTTP headers for this response |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function __construct($content = '', int $status = 200, array $headers = []) |
|
| 50 | + { |
|
| 51 | + $this->headers = new ResponseHeaders($headers); |
|
| 52 | 52 | |
| 53 | - $this->setContent($content); |
|
| 54 | - $this->setStatusCode($status); |
|
| 55 | - $this->setProtocolVersion('1.0'); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Creates an instance of the same response class for rendering contents to the content, |
|
| 60 | - * status code and headers. |
|
| 61 | - * |
|
| 62 | - * @param mixed $content The response content |
|
| 63 | - * @param int $status The HTTP response status for this response |
|
| 64 | - * @param array $headers Array of HTTP headers for this response |
|
| 65 | - * |
|
| 66 | - * @return static |
|
| 67 | - */ |
|
| 68 | - public static function render($content = '', $status = 200, $headers = []): static |
|
| 69 | - { |
|
| 70 | - return new static($content, $status, $headers); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Gets the current response content. |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getContent(): string |
|
| 79 | - { |
|
| 80 | - return $this->content; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Sends the headers if they haven't already been sent. |
|
| 85 | - * Returns whether they were sent or not. |
|
| 86 | - * |
|
| 87 | - * @return static |
|
| 88 | - */ |
|
| 89 | - public function sendHeaders(): static |
|
| 90 | - { |
|
| 91 | - // Have the headers already been sent? |
|
| 92 | - if (headers_sent()) { |
|
| 93 | - return $this; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Headers |
|
| 97 | - foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) { |
|
| 98 | - $replace = 0 === strcasecmp($name, 'Content-Type'); |
|
| 99 | - |
|
| 100 | - foreach ($values as $value) { |
|
| 101 | - header($name.': '. $value, $replace, $this->statusCode); |
|
| 102 | - } |
|
| 103 | - } |
|
| 53 | + $this->setContent($content); |
|
| 54 | + $this->setStatusCode($status); |
|
| 55 | + $this->setProtocolVersion('1.0'); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Creates an instance of the same response class for rendering contents to the content, |
|
| 60 | + * status code and headers. |
|
| 61 | + * |
|
| 62 | + * @param mixed $content The response content |
|
| 63 | + * @param int $status The HTTP response status for this response |
|
| 64 | + * @param array $headers Array of HTTP headers for this response |
|
| 65 | + * |
|
| 66 | + * @return static |
|
| 67 | + */ |
|
| 68 | + public static function render($content = '', $status = 200, $headers = []): static |
|
| 69 | + { |
|
| 70 | + return new static($content, $status, $headers); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Gets the current response content. |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getContent(): string |
|
| 79 | + { |
|
| 80 | + return $this->content; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Sends the headers if they haven't already been sent. |
|
| 85 | + * Returns whether they were sent or not. |
|
| 86 | + * |
|
| 87 | + * @return static |
|
| 88 | + */ |
|
| 89 | + public function sendHeaders(): static |
|
| 90 | + { |
|
| 91 | + // Have the headers already been sent? |
|
| 92 | + if (headers_sent()) { |
|
| 93 | + return $this; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Headers |
|
| 97 | + foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) { |
|
| 98 | + $replace = 0 === strcasecmp($name, 'Content-Type'); |
|
| 99 | + |
|
| 100 | + foreach ($values as $value) { |
|
| 101 | + header($name.': '. $value, $replace, $this->statusCode); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - // Cookies |
|
| 106 | - foreach ($this->headers->getCookies() as $cookie) { |
|
| 107 | - header('Set-Cookie: '.$cookie, false, $this->statusCode); |
|
| 108 | - } |
|
| 105 | + // Cookies |
|
| 106 | + foreach ($this->headers->getCookies() as $cookie) { |
|
| 107 | + header('Set-Cookie: '.$cookie, false, $this->statusCode); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - // Status |
|
| 111 | - if ( ! empty($_SERVER['FCGI_SERVER_VERSION'])) { |
|
| 112 | - // Send the protocol/status line first, FCGI servers need different status header |
|
| 113 | - header(sprintf('Status: %s %s', $this->statusCode, $this->statusText)); |
|
| 114 | - } else { |
|
| 115 | - header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $this; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Sends content for the current web response. |
|
| 123 | - * |
|
| 124 | - * @return static |
|
| 125 | - */ |
|
| 126 | - public function sendContent(): static |
|
| 127 | - { |
|
| 128 | - echo $this->content; |
|
| 129 | - |
|
| 130 | - return $this; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Sends the response to the output buffer. Optionally, headers will be sent. |
|
| 135 | - * |
|
| 136 | - * @param bool $sendHeader Whether or not to send the defined HTTP headers |
|
| 137 | - * |
|
| 138 | - * @return static |
|
| 139 | - */ |
|
| 140 | - public function send($sendHeader = false): static |
|
| 141 | - { |
|
| 142 | - if ($sendHeader) { |
|
| 143 | - $this->sendHeaders(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if (null !== $this->content) { |
|
| 147 | - $this->sendContent(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $this; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Sends the content of the message to the browser. |
|
| 155 | - * |
|
| 156 | - * @param mixed $content The response content |
|
| 157 | - * |
|
| 158 | - * @return static |
|
| 159 | - */ |
|
| 160 | - public function setContent($content): static |
|
| 161 | - { |
|
| 162 | - if (null !== $content && ! is_string($content) && ! is_numeric($content) && |
|
| 163 | - ! is_bool($content) && ! is_object($content) && ! is_callable([$content, '__toString'])) { |
|
| 164 | - throw new UnexpectedValueException( |
|
| 165 | - sprintf('The Response content must be a string or object implementing __toString(), "%s" given', gettype($content) |
|
| 166 | - )); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if ($content instanceof JsonSerializable || is_array($content)) { |
|
| 170 | - $this->header('Content-Type', 'application/json'); |
|
| 171 | - |
|
| 172 | - $content = json_encode($content); |
|
| 173 | - } elseif ($content instanceof Renderable) { |
|
| 174 | - $content = $content->render(); |
|
| 175 | - } |
|
| 110 | + // Status |
|
| 111 | + if ( ! empty($_SERVER['FCGI_SERVER_VERSION'])) { |
|
| 112 | + // Send the protocol/status line first, FCGI servers need different status header |
|
| 113 | + header(sprintf('Status: %s %s', $this->statusCode, $this->statusText)); |
|
| 114 | + } else { |
|
| 115 | + header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $this; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Sends content for the current web response. |
|
| 123 | + * |
|
| 124 | + * @return static |
|
| 125 | + */ |
|
| 126 | + public function sendContent(): static |
|
| 127 | + { |
|
| 128 | + echo $this->content; |
|
| 129 | + |
|
| 130 | + return $this; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Sends the response to the output buffer. Optionally, headers will be sent. |
|
| 135 | + * |
|
| 136 | + * @param bool $sendHeader Whether or not to send the defined HTTP headers |
|
| 137 | + * |
|
| 138 | + * @return static |
|
| 139 | + */ |
|
| 140 | + public function send($sendHeader = false): static |
|
| 141 | + { |
|
| 142 | + if ($sendHeader) { |
|
| 143 | + $this->sendHeaders(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if (null !== $this->content) { |
|
| 147 | + $this->sendContent(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $this; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Sends the content of the message to the browser. |
|
| 155 | + * |
|
| 156 | + * @param mixed $content The response content |
|
| 157 | + * |
|
| 158 | + * @return static |
|
| 159 | + */ |
|
| 160 | + public function setContent($content): static |
|
| 161 | + { |
|
| 162 | + if (null !== $content && ! is_string($content) && ! is_numeric($content) && |
|
| 163 | + ! is_bool($content) && ! is_object($content) && ! is_callable([$content, '__toString'])) { |
|
| 164 | + throw new UnexpectedValueException( |
|
| 165 | + sprintf('The Response content must be a string or object implementing __toString(), "%s" given', gettype($content) |
|
| 166 | + )); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if ($content instanceof JsonSerializable || is_array($content)) { |
|
| 170 | + $this->header('Content-Type', 'application/json'); |
|
| 171 | + |
|
| 172 | + $content = json_encode($content); |
|
| 173 | + } elseif ($content instanceof Renderable) { |
|
| 174 | + $content = $content->render(); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - $this->content = $content ?? ''; |
|
| 178 | - |
|
| 179 | - return $this; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Prepares the Response before it is sent to the client. |
|
| 184 | - * |
|
| 185 | - * @param \Syscodes\Components\Http\Request $request |
|
| 186 | - * |
|
| 187 | - * @return static |
|
| 188 | - */ |
|
| 189 | - public function prepare($request): static |
|
| 190 | - { |
|
| 191 | - $headers = $this->headers; |
|
| 192 | - |
|
| 193 | - if ($this->isInformational() || $this->isEmpty()) { |
|
| 194 | - $this->setContent(null); |
|
| 195 | - $headers->remove('Content-Type'); |
|
| 196 | - $headers->remove('Content-Length'); |
|
| 197 | - } |
|
| 177 | + $this->content = $content ?? ''; |
|
| 178 | + |
|
| 179 | + return $this; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Prepares the Response before it is sent to the client. |
|
| 184 | + * |
|
| 185 | + * @param \Syscodes\Components\Http\Request $request |
|
| 186 | + * |
|
| 187 | + * @return static |
|
| 188 | + */ |
|
| 189 | + public function prepare($request): static |
|
| 190 | + { |
|
| 191 | + $headers = $this->headers; |
|
| 192 | + |
|
| 193 | + if ($this->isInformational() || $this->isEmpty()) { |
|
| 194 | + $this->setContent(null); |
|
| 195 | + $headers->remove('Content-Type'); |
|
| 196 | + $headers->remove('Content-Length'); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - // Fix protocol |
|
| 200 | - if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) { |
|
| 201 | - $this->setProtocolVersion('1.1'); |
|
| 202 | - } |
|
| 199 | + // Fix protocol |
|
| 200 | + if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) { |
|
| 201 | + $this->setProtocolVersion('1.1'); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $this; |
|
| 205 | - } |
|
| 204 | + return $this; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Magic method. |
|
| 209 | - * |
|
| 210 | - * Returns the Response as an HTTP string. |
|
| 211 | - * |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function __toString(): string |
|
| 215 | - { |
|
| 216 | - return sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n". |
|
| 217 | - $this->headers."\r\n". |
|
| 218 | - $this->getContent(); |
|
| 219 | - } |
|
| 207 | + /** |
|
| 208 | + * Magic method. |
|
| 209 | + * |
|
| 210 | + * Returns the Response as an HTTP string. |
|
| 211 | + * |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function __toString(): string |
|
| 215 | + { |
|
| 216 | + return sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n". |
|
| 217 | + $this->headers."\r\n". |
|
| 218 | + $this->getContent(); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Magic method. |
|
| 223 | - * |
|
| 224 | - * Clone the current Response instance. |
|
| 225 | - * |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function __clone() |
|
| 229 | - { |
|
| 230 | - $this->headers = clone $this->headers; |
|
| 231 | - } |
|
| 221 | + /** |
|
| 222 | + * Magic method. |
|
| 223 | + * |
|
| 224 | + * Clone the current Response instance. |
|
| 225 | + * |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function __clone() |
|
| 229 | + { |
|
| 230 | + $this->headers = clone $this->headers; |
|
| 231 | + } |
|
| 232 | 232 | } |
| 233 | 233 | \ No newline at end of file |