o2system /
spl
| 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\Spl\Exceptions\Abstracts; |
||
| 15 | |||
| 16 | // ------------------------------------------------------------------------ |
||
| 17 | |||
| 18 | use O2System\Spl\Info\SplClassInfo; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Class Exception |
||
| 22 | * |
||
| 23 | * @package O2System\Kernel |
||
| 24 | */ |
||
| 25 | abstract class AbstractException extends \Exception |
||
| 26 | {
|
||
| 27 | /** |
||
| 28 | * Exception Header |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $header; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Exception Description |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $description; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Exception View |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $view = 'exception'; |
||
| 47 | |||
| 48 | // ------------------------------------------------------------------------ |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Exception::__construct |
||
| 52 | * |
||
| 53 | * @param string $message |
||
| 54 | * @param int $code |
||
| 55 | * @param array $context |
||
| 56 | * @param \Exception|NULL $previous |
||
| 57 | */ |
||
| 58 | public function __construct($message, $code = 0, array $context = [], \Exception $previous = null) |
||
| 59 | {
|
||
| 60 | if (class_exists('O2System\Kernel', false)) {
|
||
| 61 | $classInfo = new SplClassInfo($this); |
||
| 62 | $classNameParts = explode('\\', $classInfo->getClass());
|
||
| 63 | $classParameter = strtolower(end($classNameParts)); |
||
| 64 | $classLanguageDirectory = dirname($classInfo->getFileInfo()->getRealPath()) . DIRECTORY_SEPARATOR . 'Languages' . DIRECTORY_SEPARATOR; |
||
| 65 | |||
| 66 | if (false !== ($exceptionKey = array_search('Exception', $classNameParts)) OR
|
||
| 67 | false !== ($exceptionKey = array_search('Exceptions', $classNameParts))
|
||
| 68 | ) {
|
||
| 69 | if (isset($classNameParts[ $exceptionKey - 1 ])) {
|
||
| 70 | $classParameter = $classNameParts[ $exceptionKey - 1 ]; |
||
| 71 | |||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $this->view = strtolower($classParameter . '_' . $this->view); |
||
| 76 | $languageFilename = strtolower($classParameter) . '_' . language()->getDefault() . '.ini'; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 77 | $languageKey = strtoupper($classParameter . '_exception'); |
||
| 78 | language()->loadFile($classLanguageDirectory . $languageFilename); |
||
| 79 | |||
| 80 | $this->header = language()->getLine('E_HEADER_' . $languageKey);
|
||
| 81 | $this->description = language()->getLine('E_DESCRIPTION_' . $languageKey);
|
||
| 82 | $message = language()->getLine($message, $context); |
||
| 83 | } |
||
| 84 | |||
| 85 | parent::__construct($message, $code, $previous); |
||
| 86 | } |
||
| 87 | |||
| 88 | // ------------------------------------------------------------------------ |
||
| 89 | |||
| 90 | /** |
||
| 91 | * AbstractException::getHeader |
||
| 92 | * |
||
| 93 | * Gets exception header. |
||
| 94 | * |
||
| 95 | * @return string |
||
| 96 | */ |
||
| 97 | public function getHeader() |
||
| 98 | {
|
||
| 99 | return $this->header; |
||
| 100 | } |
||
| 101 | |||
| 102 | // ------------------------------------------------------------------------ |
||
| 103 | |||
| 104 | /** |
||
| 105 | * AbstractException::getDescription |
||
| 106 | * |
||
| 107 | * Gets exception description. |
||
| 108 | * |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | public function getDescription() |
||
| 112 | {
|
||
| 113 | return $this->description; |
||
| 114 | } |
||
| 115 | |||
| 116 | // ------------------------------------------------------------------------ |
||
| 117 | |||
| 118 | /** |
||
| 119 | * AbstractException::getChronology |
||
| 120 | * |
||
| 121 | * @return array |
||
| 122 | */ |
||
| 123 | public function getChronology() |
||
| 124 | {
|
||
| 125 | if (class_exists('O2System\Gear\Trace')) {
|
||
| 126 | return (new \O2System\Gear\Trace($this->getTrace()))->getChronology(); |
||
|
0 ignored issues
–
show
The type
O2System\Gear\Trace was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 127 | } |
||
| 128 | |||
| 129 | return $this->getTrace(); |
||
| 130 | } |
||
| 131 | |||
| 132 | // ------------------------------------------------------------------------ |
||
| 133 | |||
| 134 | /** |
||
| 135 | * AbstractException::getView |
||
| 136 | * |
||
| 137 | * @return string |
||
| 138 | */ |
||
| 139 | public function getView() |
||
| 140 | {
|
||
| 141 | return $this->view; |
||
| 142 | } |
||
| 143 | } |