o2system /
framework
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * This file is part of the O2System Framework package. |
||||
| 4 | * |
||||
| 5 | * For the full copyright and license information, please view the LICENSE |
||||
| 6 | * file that was distributed with this source code. |
||||
| 7 | * |
||||
| 8 | * @author Steeve Andrian Salim |
||||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
| 10 | */ |
||||
| 11 | |||||
| 12 | // ------------------------------------------------------------------------ |
||||
| 13 | |||||
| 14 | namespace O2System\Framework\Http; |
||||
| 15 | |||||
| 16 | // ------------------------------------------------------------------------ |
||||
| 17 | |||||
| 18 | use O2System\Gear\Trace; |
||||
|
0 ignored issues
–
show
|
|||||
| 19 | use O2System\Spl\Exceptions\Abstracts\AbstractException; |
||||
| 20 | use O2System\Spl\Exceptions\ErrorException; |
||||
| 21 | |||||
| 22 | /** |
||||
| 23 | * Class Output |
||||
| 24 | * @package O2System\Framework\Http |
||||
| 25 | */ |
||||
| 26 | class Output extends \O2System\Kernel\Http\Output |
||||
| 27 | { |
||||
| 28 | /** |
||||
| 29 | * Output::__construct |
||||
| 30 | */ |
||||
| 31 | public function __construct() |
||||
| 32 | { |
||||
| 33 | parent::__construct(); |
||||
| 34 | |||||
| 35 | if(services()->has('csrfProtection')) { |
||||
| 36 | $this->addHeader('X-CSRF-TOKEN', services()->get('csrfProtection')->getToken()); |
||||
| 37 | } |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | // ------------------------------------------------------------------------ |
||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * Output::shutdownHandler |
||||
| 44 | * |
||||
| 45 | * Kernel defined shutdown handler function. |
||||
| 46 | * |
||||
| 47 | * @return void |
||||
| 48 | * @throws \O2System\Spl\Exceptions\ErrorException |
||||
| 49 | */ |
||||
| 50 | public function shutdownHandler() |
||||
| 51 | { |
||||
| 52 | parent::shutdownHandler(); |
||||
| 53 | |||||
| 54 | // Execute Shutdown Service |
||||
| 55 | if (services()->has('shutdown')) { |
||||
| 56 | shutdown()->execute(); |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | } |
||||
| 60 | |||||
| 61 | // ------------------------------------------------------------------------ |
||||
| 62 | |||||
| 63 | /** |
||||
| 64 | * Output::getFilePath |
||||
| 65 | * |
||||
| 66 | * @param string $filename |
||||
| 67 | * |
||||
| 68 | * @return string |
||||
| 69 | */ |
||||
| 70 | public function getFilePath($filename) |
||||
| 71 | { |
||||
| 72 | if (modules()) { |
||||
| 73 | $filePaths = modules()->getDirs('Views'); |
||||
|
0 ignored issues
–
show
The method
getDirs() does not exist on O2System\Framework\Conta...s\DataStructures\Module. Did you maybe mean getDir()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 74 | } else { |
||||
| 75 | $filePaths = array_reverse($this->filePaths); |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | foreach ($filePaths as $filePath) { |
||||
| 79 | if (is_file($filePath . $filename . '.phtml')) { |
||||
| 80 | return $filePath . $filename . '.phtml'; |
||||
| 81 | break; |
||||
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other Loading history...
|
|||||
| 82 | } elseif (is_file($filePath . 'errors' . DIRECTORY_SEPARATOR . $filename . '.phtml')) { |
||||
| 83 | return $filePath . 'errors' . DIRECTORY_SEPARATOR . $filename . '.phtml'; |
||||
| 84 | break; |
||||
| 85 | } |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | |||||
| 89 | // ------------------------------------------------------------------------ |
||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * Output::errorHandler |
||||
| 93 | * |
||||
| 94 | * Kernel defined error handler function. |
||||
| 95 | * |
||||
| 96 | * @param int $errorSeverity The first parameter, errno, contains the level of the error raised, as an integer. |
||||
| 97 | * @param string $errorMessage The second parameter, errstr, contains the error message, as a string. |
||||
| 98 | * @param string $errorFile The third parameter is optional, errfile, which contains the filename that the error |
||||
| 99 | * was raised in, as a string. |
||||
| 100 | * @param string $errorLine The fourth parameter is optional, errline, which contains the line number the error |
||||
| 101 | * was raised at, as an integer. |
||||
| 102 | * @param array $errorContext The fifth parameter is optional, errcontext, which is an array that points to the |
||||
| 103 | * active symbol table at the point the error occurred. In other words, errcontext will |
||||
| 104 | * contain an array of every variable that existed in the scope the error was triggered |
||||
| 105 | * in. User error handler must not modify error context. |
||||
| 106 | * |
||||
| 107 | * @return bool If the function returns FALSE then the normal error handler continues. |
||||
| 108 | * @throws ErrorException |
||||
| 109 | */ |
||||
| 110 | public function errorHandler($errorSeverity, $errorMessage, $errorFile, $errorLine, $errorContext = []) |
||||
| 111 | { |
||||
| 112 | $isFatalError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errorSeverity) === $errorSeverity); |
||||
| 113 | |||||
| 114 | if (strpos($errorFile, 'parser') !== false) { |
||||
| 115 | if (function_exists('parser')) { |
||||
| 116 | if (services()->has('presenter')) { |
||||
| 117 | $vars = presenter()->getArrayCopy(); |
||||
| 118 | extract($vars); |
||||
| 119 | } |
||||
| 120 | |||||
| 121 | $errorFile = str_replace(PATH_ROOT, DIRECTORY_SEPARATOR, parser()->getSourceFilePath()); |
||||
|
0 ignored issues
–
show
|
|||||
| 122 | $error = new ErrorException($errorMessage, $errorSeverity, $errorFile, $errorLine, $errorContext); |
||||
|
0 ignored issues
–
show
$errorLine of type string is incompatible with the type integer expected by parameter $line of O2System\Spl\Exceptions\...xception::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 123 | |||||
| 124 | $filePath = $this->getFilePath('error'); |
||||
| 125 | |||||
| 126 | ob_start(); |
||||
| 127 | include $filePath; |
||||
| 128 | $htmlOutput = ob_get_contents(); |
||||
| 129 | ob_end_clean(); |
||||
| 130 | |||||
| 131 | echo $htmlOutput; |
||||
| 132 | |||||
| 133 | return true; |
||||
| 134 | } |
||||
| 135 | } |
||||
| 136 | |||||
| 137 | // When the error is fatal the Kernel will throw it as an exception. |
||||
| 138 | if ($isFatalError) { |
||||
| 139 | throw new ErrorException($errorMessage, $errorSeverity, $errorLine, $errorLine, $errorContext); |
||||
| 140 | } |
||||
| 141 | |||||
| 142 | // Should we ignore the error? We'll get the current error_reporting |
||||
| 143 | // level and add its bits with the severity bits to find out. |
||||
| 144 | if (($errorSeverity & error_reporting()) !== $errorSeverity) { |
||||
| 145 | return false; |
||||
| 146 | } |
||||
| 147 | |||||
| 148 | $error = new ErrorException($errorMessage, $errorSeverity, $errorFile, $errorLine, $errorContext); |
||||
| 149 | |||||
| 150 | // Logged the error |
||||
| 151 | if(services()->has('logger')) { |
||||
| 152 | logger()->error( |
||||
| 153 | implode( |
||||
| 154 | ' ', |
||||
| 155 | [ |
||||
| 156 | '[ ' . $error->getStringSeverity() . ' ] ', |
||||
| 157 | $error->getMessage(), |
||||
| 158 | $error->getFile() . ':' . $error->getLine(), |
||||
| 159 | ] |
||||
| 160 | ) |
||||
| 161 | ); |
||||
| 162 | } |
||||
| 163 | |||||
| 164 | // Should we display the error? |
||||
| 165 | if (str_ireplace(['off', 'none', 'no', 'false', 'null'], 0, ini_get('display_errors')) == 1) { |
||||
| 166 | if (is_ajax()) { |
||||
| 167 | $this->setContentType('application/json'); |
||||
| 168 | $this->statusCode = 500; |
||||
| 169 | $this->reasonPhrase = 'Internal Server Error'; |
||||
| 170 | |||||
| 171 | $this->send(implode( |
||||
| 172 | ' ', |
||||
| 173 | [ |
||||
| 174 | '[ ' . $error->getStringSeverity() . ' ] ', |
||||
| 175 | $error->getMessage(), |
||||
| 176 | $error->getFile() . ':' . $error->getLine(), |
||||
| 177 | ] |
||||
| 178 | )); |
||||
| 179 | exit(EXIT_ERROR); |
||||
|
0 ignored issues
–
show
|
|||||
| 180 | } |
||||
| 181 | |||||
| 182 | if (services()->has('presenter')) { |
||||
| 183 | if (presenter()->theme) { |
||||
| 184 | presenter()->theme->load(); |
||||
| 185 | } |
||||
| 186 | |||||
| 187 | $vars = presenter()->getArrayCopy(); |
||||
| 188 | extract($vars); |
||||
| 189 | } |
||||
| 190 | |||||
| 191 | $filePath = $this->getFilePath('error'); |
||||
| 192 | |||||
| 193 | ob_start(); |
||||
| 194 | include $filePath; |
||||
| 195 | $htmlOutput = ob_get_contents(); |
||||
| 196 | ob_end_clean(); |
||||
| 197 | |||||
| 198 | if (services()->has('presenter')) { |
||||
| 199 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||||
| 200 | } |
||||
| 201 | |||||
| 202 | echo $htmlOutput; |
||||
| 203 | exit(EXIT_ERROR); |
||||
|
0 ignored issues
–
show
|
|||||
| 204 | } |
||||
| 205 | } |
||||
| 206 | |||||
| 207 | // ------------------------------------------------------------------------ |
||||
| 208 | |||||
| 209 | /** |
||||
| 210 | * Output::sendError |
||||
| 211 | * |
||||
| 212 | * @param int $code |
||||
| 213 | * @param null|array|string $vars |
||||
| 214 | * @param array $headers |
||||
| 215 | */ |
||||
| 216 | public function sendError($code = 204, $vars = null, $headers = []) |
||||
| 217 | { |
||||
| 218 | $languageKey = $code . '_' . error_code_string($code); |
||||
| 219 | |||||
| 220 | $error = [ |
||||
| 221 | 'code' => $code, |
||||
| 222 | 'title' => language()->getLine($languageKey . '_TITLE'), |
||||
| 223 | 'message' => language()->getLine($languageKey . '_MESSAGE'), |
||||
| 224 | ]; |
||||
| 225 | |||||
| 226 | $this->statusCode = $code; |
||||
| 227 | $this->reasonPhrase = $error[ 'title' ]; |
||||
| 228 | |||||
| 229 | if (is_string($vars)) { |
||||
| 230 | $vars = ['message' => $vars]; |
||||
| 231 | } elseif (is_array($vars) and empty($vars[ 'message' ])) { |
||||
| 232 | $vars[ 'message' ] = $error[ 'message' ]; |
||||
| 233 | } |
||||
| 234 | |||||
| 235 | if (isset($vars[ 'message' ])) { |
||||
| 236 | $error[ 'message' ] = $vars[ 'message' ]; |
||||
| 237 | } |
||||
| 238 | |||||
| 239 | if (is_ajax() or $this->mimeType !== 'text/html') { |
||||
| 240 | $this->statusCode = $code; |
||||
| 241 | $this->reasonPhrase = $error[ 'title' ]; |
||||
| 242 | $this->send($vars); |
||||
| 243 | |||||
| 244 | exit(EXIT_ERROR); |
||||
|
0 ignored issues
–
show
|
|||||
| 245 | } |
||||
| 246 | |||||
| 247 | $this->sendHeaders($headers); |
||||
| 248 | |||||
| 249 | if (services()->has('presenter')) { |
||||
| 250 | presenter()->initialize(); |
||||
| 251 | |||||
| 252 | if (presenter()->theme) { |
||||
| 253 | presenter()->theme->load(); |
||||
| 254 | } |
||||
| 255 | |||||
| 256 | $vars = presenter()->getArrayCopy(); |
||||
| 257 | extract($vars); |
||||
| 258 | } |
||||
| 259 | |||||
| 260 | extract($error); |
||||
| 261 | |||||
| 262 | ob_start(); |
||||
| 263 | include $this->getFilePath('error-code'); |
||||
| 264 | $htmlOutput = ob_get_contents(); |
||||
| 265 | ob_end_clean(); |
||||
| 266 | |||||
| 267 | if (services()->has('presenter')) { |
||||
| 268 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||||
| 269 | } |
||||
| 270 | |||||
| 271 | echo $htmlOutput; |
||||
| 272 | exit(EXIT_ERROR); |
||||
|
0 ignored issues
–
show
|
|||||
| 273 | } |
||||
| 274 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths