diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 1d7d3d7e01..f4ba66e926 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -11,7 +11,7 @@ use Backend\Classes\ControllerBehavior; use October\Rain\Support\Util; use October\Rain\Router\Helper as RouterHelper; -use System\Classes\ApplicationException; +use ApplicationException; use Exception; /** diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index 3b0379f0a9..f1ea15fd16 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -3,7 +3,7 @@ use Str; use Lang; use Event; -use System\Classes\SystemException; +use SystemException; use Backend\Classes\ControllerBehavior; use League\Csv\Writer; use SplTempFileObject; diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 55fdec7380..3a396a5bbc 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -5,7 +5,7 @@ use Event; use Form as FormHelper; use Backend\Classes\ControllerBehavior; -use System\Classes\ApplicationException; +use ApplicationException; use October\Rain\Database\Model; /** diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index 8eb29f12cf..e000b56f32 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -15,10 +15,10 @@ use BackendAuth; use Backend\Models\UserPreferences; use Backend\Models\BackendPreferences; -use System\Classes\SystemException; -use System\Classes\ApplicationException; +use SystemException; +use ApplicationException; use October\Rain\Extension\Extendable; -use October\Rain\Support\ValidationException; +use ValidationException; use Illuminate\Database\Eloquent\MassAssignmentException; use Illuminate\Http\RedirectResponse; diff --git a/modules/backend/classes/ControllerBehavior.php b/modules/backend/classes/ControllerBehavior.php index ddd4d8fd4b..b57abbce94 100644 --- a/modules/backend/classes/ControllerBehavior.php +++ b/modules/backend/classes/ControllerBehavior.php @@ -2,7 +2,7 @@ use Str; use Lang; -use System\Classes\ApplicationException; +use ApplicationException; use October\Rain\Extension\ExtensionBase; use System\Traits\ViewMaker; diff --git a/modules/backend/classes/WidgetManager.php b/modules/backend/classes/WidgetManager.php index 399c6df7eb..0d1537ced8 100644 --- a/modules/backend/classes/WidgetManager.php +++ b/modules/backend/classes/WidgetManager.php @@ -2,8 +2,8 @@ use Str; use File; +use Yaml; use Closure; -use October\Rain\Support\Yaml; use Illuminate\Container\Container; use System\Classes\PluginManager; diff --git a/modules/backend/controllers/AccessLogs.php b/modules/backend/controllers/AccessLogs.php index 1c1bd76172..9662e1f5b3 100644 --- a/modules/backend/controllers/AccessLogs.php +++ b/modules/backend/controllers/AccessLogs.php @@ -8,7 +8,7 @@ use Redirect; use BackendMenu; use Backend\Classes\Controller; -use System\Classes\ApplicationException; +use ApplicationException; use System\Classes\SettingsManager; use Exception; diff --git a/modules/backend/controllers/Auth.php b/modules/backend/controllers/Auth.php index 8ecba9c6ad..059a3bf7bf 100644 --- a/modules/backend/controllers/Auth.php +++ b/modules/backend/controllers/Auth.php @@ -11,8 +11,8 @@ use Backend\Models\AccessLog; use Backend\Classes\Controller; use System\Classes\UpdateManager; -use System\Classes\ApplicationException; -use October\Rain\Support\ValidationException; +use ApplicationException; +use ValidationException; use Exception; /** diff --git a/modules/backend/formwidgets/DataGrid.php b/modules/backend/formwidgets/DataGrid.php index 705eae1314..17ff471f8f 100644 --- a/modules/backend/formwidgets/DataGrid.php +++ b/modules/backend/formwidgets/DataGrid.php @@ -2,7 +2,7 @@ use Backend\Widgets\Grid; use Backend\Classes\FormWidgetBase; -use System\Classes\ApplicationException; +use ApplicationException; /** * Grid diff --git a/modules/backend/formwidgets/DataTable.php b/modules/backend/formwidgets/DataTable.php index 705620fae6..3f1d52d19f 100644 --- a/modules/backend/formwidgets/DataTable.php +++ b/modules/backend/formwidgets/DataTable.php @@ -3,7 +3,7 @@ use Lang; use Backend\Widgets\Table; use Backend\Classes\FormWidgetBase; -use System\Classes\ApplicationException; +use ApplicationException; /** * Data Table diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index 816f951449..a2e76c4681 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -4,10 +4,10 @@ use Input; use Validator; use System\Models\File; -use System\Classes\SystemException; +use SystemException; use Backend\Classes\FormField; use Backend\Classes\FormWidgetBase; -use October\Rain\Support\ValidationException; +use ValidationException; use Exception; /** diff --git a/modules/backend/formwidgets/RecordFinder.php b/modules/backend/formwidgets/RecordFinder.php index 9d4e840405..ca8de5f7ca 100644 --- a/modules/backend/formwidgets/RecordFinder.php +++ b/modules/backend/formwidgets/RecordFinder.php @@ -2,7 +2,7 @@ use Lang; use Backend\Classes\FormWidgetBase; -use System\Classes\SystemException; +use SystemException; /** * Record Finder diff --git a/modules/backend/formwidgets/Relation.php b/modules/backend/formwidgets/Relation.php index dec7687ebd..1e4ccbab76 100644 --- a/modules/backend/formwidgets/Relation.php +++ b/modules/backend/formwidgets/Relation.php @@ -2,7 +2,7 @@ use Lang; use Backend\Classes\FormWidgetBase; -use System\Classes\SystemException; +use SystemException; use Illuminate\Database\Eloquent\Relations\Relation as RelationBase; /** diff --git a/modules/backend/models/UserPreferences.php b/modules/backend/models/UserPreferences.php index 3e812deca2..703d0ed71e 100644 --- a/modules/backend/models/UserPreferences.php +++ b/modules/backend/models/UserPreferences.php @@ -3,7 +3,7 @@ use Exception; use BackendAuth; use October\Rain\Database\Model; -use System\Classes\SystemException; +use SystemException; use October\Rain\Auth\Models\Preferences as PreferencesBase; /** diff --git a/modules/backend/traits/CollapsableWidget.php b/modules/backend/traits/CollapsableWidget.php index 737ec4a13e..060c9bdac2 100644 --- a/modules/backend/traits/CollapsableWidget.php +++ b/modules/backend/traits/CollapsableWidget.php @@ -5,7 +5,7 @@ use Lang; use Input; use Block; -use System\Classes\SystemException; +use SystemException; /** * Collapsable Widget Trait diff --git a/modules/backend/traits/InspectableContainer.php b/modules/backend/traits/InspectableContainer.php index 0d1d8e2602..8649b93573 100644 --- a/modules/backend/traits/InspectableContainer.php +++ b/modules/backend/traits/InspectableContainer.php @@ -1,8 +1,8 @@ ['Str', 'studly'], 'trans' => ['Lang', 'get'], 'transchoice' => ['Lang', 'choice'], - 'md' => ['October\Rain\Support\Markdown', 'parse'], + 'md' => ['Markdown', 'parse'], ]); }); diff --git a/modules/system/aliases.php b/modules/system/aliases.php index ebeb294835..5cae440714 100644 --- a/modules/system/aliases.php +++ b/modules/system/aliases.php @@ -47,11 +47,13 @@ 'Flash' => 'October\Rain\Support\Facades\Flash', 'Http' => 'October\Rain\Support\Facades\Http', 'Str' => 'October\Rain\Support\Facades\Str', + 'Markdown' => 'October\Rain\Support\Facades\Markdown', + 'Yaml' => 'October\Rain\Support\Facades\Yaml', 'DbDongle' => 'October\Rain\Support\Facades\DbDongle', 'Backend' => 'Backend\Facades\Backend', 'BackendMenu' => 'Backend\Facades\BackendMenu', 'BackendAuth' => 'Backend\Facades\BackendAuth', - 'SystemException' => 'System\Classes\SystemException', - 'ApplicationException' => 'System\Classes\ApplicationException', - 'ValidationException' => 'October\Rain\Support\ValidationException', + 'SystemException' => 'October\Rain\Exception\SystemException', + 'ApplicationException' => 'October\Rain\Exception\ApplicationException', + 'ValidationException' => 'October\Rain\Exception\ValidationException', ]; diff --git a/modules/system/behaviors/SettingsModel.php b/modules/system/behaviors/SettingsModel.php index 095439126d..4e3742517d 100644 --- a/modules/system/behaviors/SettingsModel.php +++ b/modules/system/behaviors/SettingsModel.php @@ -3,7 +3,7 @@ use Cache; use DbDongle; use System\Classes\ModelBehavior; -use System\Classes\ApplicationException; +use ApplicationException; /** * Settings model extension diff --git a/modules/system/classes/ApplicationException.php b/modules/system/classes/ApplicationException.php deleted file mode 100644 index ff4f950a73..0000000000 --- a/modules/system/classes/ApplicationException.php +++ /dev/null @@ -1,12 +0,0 @@ -getMessage(), $httpCode); - } - - // Clear the output buffer - while (ob_get_level()) { - ob_end_clean(); - } - - // Friendly error pages are used - if (!Config::get('app.debug', false)) { - return $this->handleCustomError(); - } - - // If the exception is already our brand, use it. - if ($proposedException instanceof BaseException) { - $exception = $proposedException; - } - // If there is an active mask prepared, use that. - elseif (static::$activeMask !== null) { - $exception = static::$activeMask; - $exception->setMask($proposedException); - } - // Otherwise we should mask it with our own default scent. - else { - $exception = new ApplicationException($proposedException->getMessage(), 0); - $exception->setMask($proposedException); - } - - // Ensure System view path is registered - View::addNamespace('system', base_path().'/modules/system/views'); - - return View::make('system::exception', ['exception' => $exception]); - } - - /** - * Prepares a mask exception to be used when any exception fires. - * @param Exception $exception The mask exception. - * @return void - */ - public static function applyMask(\Exception $exception) - { - if (static::$activeMask !== null) { - array_push(static::$maskLayers, static::$activeMask); - } - - static::$activeMask = $exception; - } - - /** - * Destroys the prepared mask by applyMask() - * @return void - */ - public static function removeMask() - { - if (count(static::$maskLayers) > 0) { - static::$activeMask = array_pop(static::$maskLayers); - } - else { - static::$activeMask = null; - } - } - /** * Looks up an error page using the CMS route "/error". If the route does not * exist, this function will use the error view found in the Cms module. @@ -114,6 +22,9 @@ public static function removeMask() */ public function handleCustomError() { + if (Config::get('app.debug', false)) + return null; + $theme = Theme::getActiveTheme(); // Use the default view if no "/error" URL is found. @@ -126,4 +37,16 @@ public function handleCustomError() $controller = new Controller($theme); return $controller->run('/error'); } + + /** + * Displays the detailed system exception page. + * @return View Object containing the error page. + */ + public function handleDetailedError($exception) + { + // Ensure System view path is registered + View::addNamespace('system', base_path().'/modules/system/views'); + + return View::make('system::exception', ['exception' => $exception]); + } } diff --git a/modules/system/classes/ExceptionBase.php b/modules/system/classes/ExceptionBase.php deleted file mode 100644 index b25a3f8348..0000000000 --- a/modules/system/classes/ExceptionBase.php +++ /dev/null @@ -1,389 +0,0 @@ -className === null) { - $this->className = get_called_class(); - } - - if ($this->errorType === null) { - $this->errorType = 'Undefined'; - } - - parent::__construct($message, $code, $previous); - } - - /** - * Returns a more descriptive error message if application - * debug mode is turned on. - * @param Exception $exception - * @return string - */ - public static function getDetailedMessage($exception) - { - /* - * Application Exceptions never display a detailed error - */ - if (!($exception instanceof ApplicationException) && Config::get('app.debug', false)) { - return sprintf('"%s" on line %s of %s', - $exception->getMessage(), - $exception->getLine(), - $exception->getFile() - ); - } - else { - return $exception->getMessage(); - } - } - - /** - * Returns the class name of the called Exception. - * @return string - */ - public function getClassName() - { - return $this->className; - } - - /** - * Returns the error type derived from the error code used. - * @return string - */ - public function getErrorType() - { - return $this->errorType; - } - - /** - * Masks an exception with the called class. This should catch fatal and php errors. - * It should always be followed by the unmask() method to remove the mask. - * @param string $message Error message. - * @param int $code Error code. - * @return void - */ - public static function mask($message = null, $code = 0) - { - $calledClass = get_called_class(); - $exception = new $calledClass($message, $code); - ErrorHandler::applyMask($exception); - } - - /** - * Removes the active mask from the called class. - * @return void - */ - public static function unmask() - { - ErrorHandler::removeMask(); - } - - /** - * If this exception acts as a mask, sets the face for the foreign exception. - * @param Exception $exception Face for the mask, the underlying exception. - * @return void - */ - public function setMask(Exception $exception) - { - $this->mask = $exception; - $this->applyMask($exception); - } - - /** - * This method is used when applying the mask exception to the face exception. - * It can be used as an override for child classes who may use different masking logic. - * @param Exception $exception Face exception being masked. - * @return void - */ - public function applyMask(Exception $exception) - { - $this->file = $exception->getFile(); - $this->message = $exception->getMessage(); - $this->line = $exception->getLine(); - $this->className = get_class($exception); - } - - /** - * If this exception is acting as a mask, return the face exception. Otherwise return - * this exception as the true one. - * @return Exception The underlying exception, or this exception if no mask is applied. - */ - public function getTrueException() - { - if ($this->mask !== null) { - return $this->mask; - } - - return $this; - } - - /** - * Generates information used for highlighting the area of code in context of the exception line number. - * The highlighted block of code will be six (6) lines before and after the problem line number. - * @return array Highlight information as an array, the following keys are supplied: - * startLine - The starting line number, 6 lines before the error line. - * endLine - The ending line number, 6 lines after the error line. - * errorLine - The focused error line number. - * lines - An array of all the lines to be highlighted, each value is a line of code. - */ - public function getHighlight() - { - if ($this->highlight !== null) { - return $this->highlight; - } - - if (!$this->fileContent && File::exists($this->file) && is_readable($this->file)) { - $this->fileContent = @file($this->file); - } - - $errorLine = $this->line - 1; - $startLine = $errorLine - 6; - - if ($startLine < 0) { - $startLine = 0; - } - - $endLine = $startLine + 12; - $lineNum = count($this->fileContent); - if ($endLine > $lineNum-1) { - $endLine = $lineNum-1; - } - - $areaLines = array_slice($this->fileContent, $startLine, $endLine - $startLine + 1); - - $result = [ - 'startLine' => $startLine, - 'endLine' => $endLine, - 'errorLine' => $errorLine, - 'lines' => [] - ]; - - foreach ($areaLines as $index => $line) { - $result['lines'][$startLine + $index] = $line; - } - - return $this->highlight = (object)$result; - } - - /** - * Returns an array of line numbers used for highlighting the problem area of code. - * This will be six (6) lines before and after the error line number. - * @return array Array of code lines. - */ - public function getHighlightLines() - { - $lines = $this->getHighlight()->lines; - foreach ($lines as $index => $line) { - $lines[$index] = strlen(trim($line)) ? htmlentities($line) : ' '.PHP_EOL; - } - return $lines; - } - - /** - * Returns the call stack as an array of values containing a stack information object. - * @return Array with stack information, each value will be an object with these values: - * id - The stack ID number. - * code - The class and function name being called. - * args - The arguments passed to the code function above. - * file - Reference to the file containing the called code. - * line - Reference to the line number of the file. - */ - public function getCallStack() - { - $result = []; - $traceInfo = $this->filterCallStack($this->getTrueException()->getTrace()); - $lastIndex = count($traceInfo) - 1; - - foreach ($traceInfo as $index => $event) { - - $functionName = (isset($event['class']) && strlen($event['class'])) - ? $event['class'].$event['type'].$event['function'] - : $event['function']; - - $file = isset($event['file']) ? URL::to(str_replace(public_path(), '', $event['file'])) : null; - $line = isset($event['line']) ? $event['line'] : null; - - $args = null; - if (isset($event['args']) && count($event['args'])) { - $args = $this->formatStackArguments($event['args'], false); - } - - $result[] = (object)[ - 'id' => $lastIndex - $index + 1, - 'code' => $functionName, - 'args' => $args ? htmlentities($args) : '', - 'file' => $file, - 'line' => $line - ]; - } - - return $result; - } - - /** - * Removes the final steps of a call stack, which add no value for the user. - * The following exceptions and any trace information afterwards will be filtered: - * - Illuminate\Exception\Handler - * - * @param array $traceInfo The trace information from getTrace() or debug_backtrace(). - * @return array The filtered array containing the trace information. - */ - protected function filterCallStack($traceInfo) - { - /* - * Determine if filter should be used at all. - */ - $useFilter = false; - foreach ($traceInfo as $event) { - if ( - isset($event['class']) && - $event['class'] == 'Illuminate\Exception\Handler' && - $event['function'] == 'handleError' - ) { - $useFilter = true; - } - } - - if (!$useFilter) { - return $traceInfo; - } - - $filterResult = []; - $pruneResult = true; - foreach ($traceInfo as $index => $event) { - /* - * Prune the tail end of the trace from the framework exception handler. - */ - if ( - isset($event['class']) && - $event['class'] == 'Illuminate\Exception\Handler' && - $event['function'] == 'handleError' - ) { - $pruneResult = false; - continue; - } - - if ($pruneResult) { - continue; - } - - $filterResult[$index] = $event; - } - - return $filterResult; - } - - /** - * Prepares a function or method argument list for display in HTML or text format - * @param array arguments A list of the function or method arguments - * @return string - */ - protected function formatStackArguments($arguments) - { - $argsArray = array(); - foreach ($arguments as $argument) { - $arg = null; - - if (is_array($argument)) { - $items = array(); - - foreach ($argument as $index => $obj) { - if (is_array($obj)) { - $value = 'array('.count($obj).')'; - } - elseif (is_object($obj)) { - $value = 'object('.get_class($obj).')'; - } - elseif (is_integer($obj)) { - $value = $obj; - } - elseif ($obj === null) { - $value = "null"; - } - else { - $value = "'".$obj."'"; - } - - $items[] = $index . ' => ' . $value; - } - - if (count($items)) { - $arg = 'array(' . count($argument) . ') [' . implode(', ', $items) . ']'; - } - else { - $arg = 'array(0)'; - } - } - elseif (is_object($argument)) { - $arg = 'object('.get_class($argument).')'; - } - elseif ($argument === null) { - $arg = "null"; - } - elseif (is_integer($argument)) { - $arg = $argument; - } - else { - $arg = "'".$argument."'"; - } - - $argsArray[] = $arg; - } - - return implode(', ', $argsArray); - } -} diff --git a/modules/system/classes/MarkupManager.php b/modules/system/classes/MarkupManager.php index 19d5ceb7b5..4457c03892 100644 --- a/modules/system/classes/MarkupManager.php +++ b/modules/system/classes/MarkupManager.php @@ -4,7 +4,7 @@ use Twig_TokenParser; use Twig_SimpleFilter; use Twig_SimpleFunction; -use System\Classes\ApplicationException; +use ApplicationException; use System\Classes\PluginManager; /** diff --git a/modules/system/classes/ModelBehavior.php b/modules/system/classes/ModelBehavior.php index 60301b5bb1..2457df0e73 100644 --- a/modules/system/classes/ModelBehavior.php +++ b/modules/system/classes/ModelBehavior.php @@ -1,7 +1,7 @@