Skip to content

Commit

Permalink
Move JErrorPage to namespace (#14231)
Browse files Browse the repository at this point in the history
* Move JErrorPage to namespace

* Doc block comment should be inline with the rest

* Move class to Joomla\Cms\Exception\ExceptionHandler

* Correct class name
  • Loading branch information
laoneo authored and wilsonge committed Mar 27, 2017
1 parent 8bc7329 commit 612ba99
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions libraries/classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@
JLoader::registerAlias('JLanguageAssociations', '\\Joomla\\Cms\\Language\\Associations', '4.0');
JLoader::registerAlias('JLanguageMultilang', '\\Joomla\\Cms\\Language\\Multilanguage', '4.0');

JLoader::registerAlias('JErrorPage', '\\Joomla\\Cms\\Exception\\ExceptionHandler', '4.0');
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
<?php
/**
* @package Joomla.Libraries
* @subpackage Error
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Cms\Exception;

defined('JPATH_PLATFORM') or die;

/**
* Displays the custom error page when an uncaught exception occurs.
*
* @since 3.0
*/
class JErrorPage
class ExceptionHandler
{
/**
* Render the error page based on an exception.
*
* @param Exception|Throwable $error An Exception or Throwable (PHP 7+) object for which to render the error page.
* @param \Exception|\Throwable $error An Exception or Throwable (PHP 7+) object for which to render the error page.
*
* @return void
*
* @since 3.0
*/
public static function render($error)
{
$expectedClass = PHP_MAJOR_VERSION >= 7 ? 'Throwable' : 'Exception';
$expectedClass = PHP_MAJOR_VERSION >= 7 ? '\Throwable' : '\Exception';
$isException = $error instanceof $expectedClass;

// In PHP 5, the $error object should be an instance of Exception; PHP 7 should be a Throwable implementation
// In PHP 5, the $error object should be an instance of \Exception; PHP 7 should be a Throwable implementation
if ($isException)
{
try
{
// Try to log the error, but don't let the logging cause a fatal error
try
{
JLog::add(
\JLog::add(
sprintf(
'Uncaught %1$s of type %2$s thrown. Stack trace: %3$s',
$expectedClass,
get_class($error),
$error->getTraceAsString()
),
JLog::CRITICAL,
\JLog::CRITICAL,
'error'
);
}
catch (Throwable $e)
catch (\Throwable $e)
{
// Logging failed, don't make a stink about it though
}
catch (Exception $e)
catch (\Exception $e)
{
// Logging failed, don't make a stink about it though
}

$app = JFactory::getApplication();
$app = \JFactory::getApplication();

// If site is offline and it's a 404 error, just go to index (to see offline message, instead of 404)
if ($error->getCode() == '404' && $app->get('offline') == 1)
Expand All @@ -74,14 +75,14 @@ public static function render($error)
'direction' => 'ltr',
);

// If there is a JLanguage instance in JFactory then let's pull the language and direction from its metadata
if (JFactory::$language)
// If there is a \JLanguage instance in \JFactory then let's pull the language and direction from its metadata
if (\JFactory::$language)
{
$attributes['language'] = JFactory::getLanguage()->getTag();
$attributes['direction'] = JFactory::getLanguage()->isRtl() ? 'rtl' : 'ltr';
$attributes['language'] = \JFactory::getLanguage()->getTag();
$attributes['direction'] = \JFactory::getLanguage()->isRtl() ? 'rtl' : 'ltr';
}

$document = JDocument::getInstance('error', $attributes);
$document = \JDocument::getInstance('error', $attributes);

if (!$document)
{
Expand All @@ -100,7 +101,7 @@ public static function render($error)
ob_end_clean();
}

$document->setTitle(JText::_('ERROR') . ': ' . $error->getCode());
$document->setTitle(\JText::_('ERROR') . ': ' . $error->getCode());

$data = $document->render(
false,
Expand Down Expand Up @@ -129,11 +130,11 @@ public static function render($error)
// This return is needed to ensure the test suite does not trigger the non-Exception handling below
return;
}
catch (Throwable $e)
catch (\Throwable $e)
{
// Pass the error down
}
catch (Exception $e)
catch (\Exception $e)
{
// Pass the error down
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Joomla/Cms/View/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Cms\View;
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Joomla/Cms/View/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Cms\View;
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Joomla/Cms/View/CategoryFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Cms\View;
Expand Down

0 comments on commit 612ba99

Please sign in to comment.