@@ -29,105 +29,105 @@ |
||
29 | 29 | */ |
30 | 30 | class RouteGroup |
31 | 31 | { |
32 | - /** |
|
33 | - * Merge the given group attributes. |
|
34 | - * |
|
35 | - * @param array $new |
|
36 | - * @param array $old |
|
37 | - * @param bool $existsPrefix |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public static function mergeGroup($new, $old, $existsPrefix = true): array |
|
42 | - { |
|
43 | - if (isset($new['domain'])) { |
|
44 | - unset($old['domain']); |
|
45 | - } |
|
32 | + /** |
|
33 | + * Merge the given group attributes. |
|
34 | + * |
|
35 | + * @param array $new |
|
36 | + * @param array $old |
|
37 | + * @param bool $existsPrefix |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public static function mergeGroup($new, $old, $existsPrefix = true): array |
|
42 | + { |
|
43 | + if (isset($new['domain'])) { |
|
44 | + unset($old['domain']); |
|
45 | + } |
|
46 | 46 | |
47 | - if (isset($new['controller'])) { |
|
48 | - unset($old['controller']); |
|
49 | - } |
|
47 | + if (isset($new['controller'])) { |
|
48 | + unset($old['controller']); |
|
49 | + } |
|
50 | 50 | |
51 | - $new = array_merge(static::formatUseAs($new, $old), [ |
|
52 | - 'namespace' => static::formatUseNamespace($new, $old), |
|
53 | - 'prefix' => static::formatUsePrefix($new, $old, $existsPrefix), |
|
54 | - 'where' => static::formatUseWhere($new, $old) |
|
55 | - ]); |
|
51 | + $new = array_merge(static::formatUseAs($new, $old), [ |
|
52 | + 'namespace' => static::formatUseNamespace($new, $old), |
|
53 | + 'prefix' => static::formatUsePrefix($new, $old, $existsPrefix), |
|
54 | + 'where' => static::formatUseWhere($new, $old) |
|
55 | + ]); |
|
56 | 56 | |
57 | - return array_merge_recursive( |
|
58 | - Arr::except($old, array('namespace', 'prefix', 'where', 'as')), $new |
|
59 | - ); |
|
60 | - } |
|
57 | + return array_merge_recursive( |
|
58 | + Arr::except($old, array('namespace', 'prefix', 'where', 'as')), $new |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Format the uses namespace for the new group attributes. |
|
64 | - * |
|
65 | - * @param array $new |
|
66 | - * @param array $old |
|
67 | - * |
|
68 | - * @return string|null |
|
69 | - */ |
|
70 | - protected static function formatUseNamespace($new, $old): ?string |
|
71 | - { |
|
72 | - if (isset($new['namespace'])) { |
|
73 | - return isset($old['namespace']) |
|
74 | - ? trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\') |
|
75 | - : trim($new['namespace'], '\\'); |
|
76 | - } |
|
62 | + /** |
|
63 | + * Format the uses namespace for the new group attributes. |
|
64 | + * |
|
65 | + * @param array $new |
|
66 | + * @param array $old |
|
67 | + * |
|
68 | + * @return string|null |
|
69 | + */ |
|
70 | + protected static function formatUseNamespace($new, $old): ?string |
|
71 | + { |
|
72 | + if (isset($new['namespace'])) { |
|
73 | + return isset($old['namespace']) |
|
74 | + ? trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\') |
|
75 | + : trim($new['namespace'], '\\'); |
|
76 | + } |
|
77 | 77 | |
78 | - return $old['namespace'] ?? null; |
|
79 | - } |
|
78 | + return $old['namespace'] ?? null; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Format the prefix for the new group attributes. |
|
83 | - * |
|
84 | - * @param array $new |
|
85 | - * @param array $old |
|
86 | - * @param bool $existPrefix |
|
87 | - * |
|
88 | - * @return string|null |
|
89 | - */ |
|
90 | - protected static function formatUsePrefix($new, $old, bool $existsPrefix = true): ?string |
|
91 | - { |
|
92 | - $old = $old['prefix'] ?? null; |
|
81 | + /** |
|
82 | + * Format the prefix for the new group attributes. |
|
83 | + * |
|
84 | + * @param array $new |
|
85 | + * @param array $old |
|
86 | + * @param bool $existPrefix |
|
87 | + * |
|
88 | + * @return string|null |
|
89 | + */ |
|
90 | + protected static function formatUsePrefix($new, $old, bool $existsPrefix = true): ?string |
|
91 | + { |
|
92 | + $old = $old['prefix'] ?? null; |
|
93 | 93 | |
94 | - if ($existsPrefix) { |
|
95 | - return trim(isset($new['prefix']) ? trim($old, '/').'/'.trim($new['prefix'], '/') : $old, '/'); |
|
96 | - } else { |
|
97 | - return trim(isset($new['prefix']) ? trim($new['prefix'], '/').'/'.trim($old, '/') : $old, '/'); |
|
98 | - } |
|
99 | - } |
|
94 | + if ($existsPrefix) { |
|
95 | + return trim(isset($new['prefix']) ? trim($old, '/').'/'.trim($new['prefix'], '/') : $old, '/'); |
|
96 | + } else { |
|
97 | + return trim(isset($new['prefix']) ? trim($new['prefix'], '/').'/'.trim($old, '/') : $old, '/'); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Format the "wheres" for the new group attributes. |
|
103 | - * |
|
104 | - * @param array $new |
|
105 | - * @param array $old |
|
106 | - * |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - protected static function formatUseWhere($new, $old): array |
|
110 | - { |
|
111 | - return array_merge( |
|
112 | - $old['where'] ?? [], |
|
113 | - $new['where'] ?? [] |
|
114 | - ); |
|
115 | - } |
|
101 | + /** |
|
102 | + * Format the "wheres" for the new group attributes. |
|
103 | + * |
|
104 | + * @param array $new |
|
105 | + * @param array $old |
|
106 | + * |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + protected static function formatUseWhere($new, $old): array |
|
110 | + { |
|
111 | + return array_merge( |
|
112 | + $old['where'] ?? [], |
|
113 | + $new['where'] ?? [] |
|
114 | + ); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Format the "as" clause of the new group attributes. |
|
119 | - * |
|
120 | - * @param array $new |
|
121 | - * @param array $old |
|
122 | - * |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - protected static function formatUseAs($new, $old): array |
|
126 | - { |
|
127 | - if (isset($old['as'])) { |
|
128 | - $new['as'] = $old['as'].($new['as'] ?? ''); |
|
129 | - } |
|
117 | + /** |
|
118 | + * Format the "as" clause of the new group attributes. |
|
119 | + * |
|
120 | + * @param array $new |
|
121 | + * @param array $old |
|
122 | + * |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + protected static function formatUseAs($new, $old): array |
|
126 | + { |
|
127 | + if (isset($old['as'])) { |
|
128 | + $new['as'] = $old['as'].($new['as'] ?? ''); |
|
129 | + } |
|
130 | 130 | |
131 | - return $new; |
|
132 | - } |
|
131 | + return $new; |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | \ No newline at end of file |
@@ -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 | /** |
@@ -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', '#B5B5B5'); |
|
169 | - ini_set('highlight.default', '#E5E5E5'); |
|
170 | - ini_set('highlight.html', '#06B'); |
|
171 | - ini_set('highlight.keyword', '#FF9361'); |
|
172 | - ini_set('highlight.string', '#61ABFF'); |
|
173 | - } |
|
165 | + // Set our highlight colors: |
|
166 | + if (function_exists('ini_set')) { |
|
167 | + ini_set('highlight.bg', '#000'); |
|
168 | + ini_set('highlight.comment', '#B5B5B5'); |
|
169 | + ini_set('highlight.default', '#E5E5E5'); |
|
170 | + ini_set('highlight.html', '#06B'); |
|
171 | + ini_set('highlight.keyword', '#FF9361'); |
|
172 | + ini_set('highlight.string', '#61ABFF'); |
|
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 |
@@ -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); |
@@ -31,156 +31,156 @@ |
||
31 | 31 | */ |
32 | 32 | class Supervisor |
33 | 33 | { |
34 | - /** |
|
35 | - * Get exception. |
|
36 | - * |
|
37 | - * @var \Throwable $exception |
|
38 | - */ |
|
39 | - protected $exception; |
|
40 | - |
|
41 | - /** |
|
42 | - * The frame execute errors. |
|
43 | - * |
|
44 | - * @var string $frames |
|
45 | - */ |
|
46 | - protected $frames; |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor. The Supervisor class instance. |
|
50 | - * |
|
51 | - * @param \Throwable $exception |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function __construct($exception) |
|
56 | - { |
|
57 | - $this->exception = $exception; |
|
58 | - } |
|
34 | + /** |
|
35 | + * Get exception. |
|
36 | + * |
|
37 | + * @var \Throwable $exception |
|
38 | + */ |
|
39 | + protected $exception; |
|
40 | + |
|
41 | + /** |
|
42 | + * The frame execute errors. |
|
43 | + * |
|
44 | + * @var string $frames |
|
45 | + */ |
|
46 | + protected $frames; |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor. The Supervisor class instance. |
|
50 | + * |
|
51 | + * @param \Throwable $exception |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function __construct($exception) |
|
56 | + { |
|
57 | + $this->exception = $exception; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Returns an iterator for the inspected exception's frames. |
|
62 | - * |
|
63 | - * @param \Throwable $exception |
|
64 | - * |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function getFrames() |
|
68 | - { |
|
69 | - if ($this->frames === null) { |
|
70 | - $frames = $this->getTrace($this->exception); |
|
71 | - |
|
72 | - // Fill empty line/file info for call_user_func_array usages |
|
73 | - foreach ($frames as $k => $frame) { |
|
74 | - if (empty($frame['file'])) { |
|
75 | - // Default values when file and line are missing |
|
76 | - $file = '[PHP internal Code]'; |
|
77 | - $line = 0; |
|
78 | - $next_frame = ! empty($frames[$k + 1]) ? $frames[$k + 1] : []; |
|
79 | - $frames[$k]['file'] = $file; |
|
80 | - $frames[$k]['line'] = $line; |
|
81 | - } |
|
82 | - } |
|
60 | + /** |
|
61 | + * Returns an iterator for the inspected exception's frames. |
|
62 | + * |
|
63 | + * @param \Throwable $exception |
|
64 | + * |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function getFrames() |
|
68 | + { |
|
69 | + if ($this->frames === null) { |
|
70 | + $frames = $this->getTrace($this->exception); |
|
71 | + |
|
72 | + // Fill empty line/file info for call_user_func_array usages |
|
73 | + foreach ($frames as $k => $frame) { |
|
74 | + if (empty($frame['file'])) { |
|
75 | + // Default values when file and line are missing |
|
76 | + $file = '[PHP internal Code]'; |
|
77 | + $line = 0; |
|
78 | + $next_frame = ! empty($frames[$k + 1]) ? $frames[$k + 1] : []; |
|
79 | + $frames[$k]['file'] = $file; |
|
80 | + $frames[$k]['line'] = $line; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - // Find latest non-error handling frame index ($i) used to remove error handling frames |
|
85 | - $i = 0; |
|
86 | - |
|
87 | - foreach ($frames as $k => $frame) { |
|
88 | - if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) { |
|
89 | - $i = $k; |
|
90 | - } |
|
91 | - } |
|
92 | - // Remove error handling frames |
|
93 | - if ($i > 0) { |
|
94 | - array_splice($frames, 0, $i); |
|
95 | - } |
|
84 | + // Find latest non-error handling frame index ($i) used to remove error handling frames |
|
85 | + $i = 0; |
|
86 | + |
|
87 | + foreach ($frames as $k => $frame) { |
|
88 | + if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) { |
|
89 | + $i = $k; |
|
90 | + } |
|
91 | + } |
|
92 | + // Remove error handling frames |
|
93 | + if ($i > 0) { |
|
94 | + array_splice($frames, 0, $i); |
|
95 | + } |
|
96 | 96 | |
97 | - $firstFrame = $this->getFrameFromException($this->exception); |
|
98 | - array_unshift($frames, $firstFrame); |
|
99 | - |
|
100 | - $this->frames = new Collection($frames); |
|
101 | - } |
|
102 | - |
|
103 | - return $this->frames; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Given an exception, generates an array in the format generated by Exception::getTrace(). |
|
108 | - * |
|
109 | - * @param \Throwable $exception |
|
110 | - * |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - protected function getFrameFromException(Throwable $exception): array |
|
114 | - { |
|
115 | - return [ |
|
116 | - 'file' => $exception->getFile(), |
|
117 | - 'line' => $exception->getLine(), |
|
118 | - 'class' => get_class($exception), |
|
119 | - 'code' => $exception->getCode(), |
|
120 | - 'args' => [ |
|
121 | - $exception->getMessage(), |
|
122 | - ], |
|
123 | - ]; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Gets exception already specified. |
|
128 | - * |
|
129 | - * @return \Throwable |
|
130 | - */ |
|
131 | - public function getException() |
|
132 | - { |
|
133 | - return $this->exception; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Gets the message of exception. |
|
138 | - * |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function getExceptionMessage(): string |
|
142 | - { |
|
143 | - return $this->exception->getMessage(); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets the class name of exception. |
|
148 | - * |
|
149 | - * @return mixed |
|
150 | - */ |
|
151 | - public function getExceptionName() |
|
152 | - { |
|
153 | - return getClass($this->exception); |
|
154 | - } |
|
97 | + $firstFrame = $this->getFrameFromException($this->exception); |
|
98 | + array_unshift($frames, $firstFrame); |
|
99 | + |
|
100 | + $this->frames = new Collection($frames); |
|
101 | + } |
|
102 | + |
|
103 | + return $this->frames; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Given an exception, generates an array in the format generated by Exception::getTrace(). |
|
108 | + * |
|
109 | + * @param \Throwable $exception |
|
110 | + * |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + protected function getFrameFromException(Throwable $exception): array |
|
114 | + { |
|
115 | + return [ |
|
116 | + 'file' => $exception->getFile(), |
|
117 | + 'line' => $exception->getLine(), |
|
118 | + 'class' => get_class($exception), |
|
119 | + 'code' => $exception->getCode(), |
|
120 | + 'args' => [ |
|
121 | + $exception->getMessage(), |
|
122 | + ], |
|
123 | + ]; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Gets exception already specified. |
|
128 | + * |
|
129 | + * @return \Throwable |
|
130 | + */ |
|
131 | + public function getException() |
|
132 | + { |
|
133 | + return $this->exception; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Gets the message of exception. |
|
138 | + * |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getExceptionMessage(): string |
|
142 | + { |
|
143 | + return $this->exception->getMessage(); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets the class name of exception. |
|
148 | + * |
|
149 | + * @return mixed |
|
150 | + */ |
|
151 | + public function getExceptionName() |
|
152 | + { |
|
153 | + return getClass($this->exception); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Gets the backtrace from an exception. |
|
158 | - * |
|
159 | - * @param \Throwable $exception |
|
160 | - * |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - protected function getTrace($exception): array |
|
164 | - { |
|
165 | - $traces = $exception->getTrace(); |
|
166 | - |
|
167 | - if ( ! $exception instanceof ErrorException) { |
|
168 | - return $traces; |
|
169 | - } |
|
170 | - |
|
171 | - if ( ! Misc::isFatalError($exception->getSeverity())) { |
|
172 | - return $traces; |
|
173 | - } |
|
174 | - |
|
175 | - if ( ! extension_loaded('xdebug') || ! function_exists('xdebug_is_enabled') || ! xdebug_is_enabled()) { |
|
176 | - return $traces; |
|
177 | - } |
|
156 | + /** |
|
157 | + * Gets the backtrace from an exception. |
|
158 | + * |
|
159 | + * @param \Throwable $exception |
|
160 | + * |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + protected function getTrace($exception): array |
|
164 | + { |
|
165 | + $traces = $exception->getTrace(); |
|
166 | + |
|
167 | + if ( ! $exception instanceof ErrorException) { |
|
168 | + return $traces; |
|
169 | + } |
|
170 | + |
|
171 | + if ( ! Misc::isFatalError($exception->getSeverity())) { |
|
172 | + return $traces; |
|
173 | + } |
|
174 | + |
|
175 | + if ( ! extension_loaded('xdebug') || ! function_exists('xdebug_is_enabled') || ! xdebug_is_enabled()) { |
|
176 | + return $traces; |
|
177 | + } |
|
178 | 178 | |
179 | - // Use xdebug to get the full stack trace and remove the shutdown handler stack trace |
|
180 | - $stack = array_reverse(xdebug_get_function_stack()); |
|
181 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
182 | - $traces = array_diff_key($stack, $trace); |
|
179 | + // Use xdebug to get the full stack trace and remove the shutdown handler stack trace |
|
180 | + $stack = array_reverse(xdebug_get_function_stack()); |
|
181 | + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
182 | + $traces = array_diff_key($stack, $trace); |
|
183 | 183 | |
184 | - return $traces; |
|
185 | - } |
|
184 | + return $traces; |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | \ 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; |