[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Error/Renderer/ -> HtmlRenderer.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  namespace Joomla\CMS\Error\Renderer;
  11  
  12  use Joomla\CMS\Error\AbstractRenderer;
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Text;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('JPATH_PLATFORM') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * HTML error page renderer
  22   *
  23   * @since  4.0.0
  24   * @todo   Change this renderer to use JDocumentHtml instead of JDocumentError, the latter is only used for B/C at this time
  25   */
  26  class HtmlRenderer extends AbstractRenderer
  27  {
  28      /**
  29       * The format (type) of the error page
  30       *
  31       * @var    string
  32       * @since  4.0.0
  33       */
  34      protected $type = 'error';
  35  
  36      /**
  37       * Render the error page for the given object
  38       *
  39       * @param   \Throwable  $error  The error object to be rendered
  40       *
  41       * @return  string
  42       *
  43       * @since   4.0.0
  44       */
  45      public function render(\Throwable $error): string
  46      {
  47          $app = Factory::getApplication();
  48  
  49          // Get the current template from the application
  50          $template = $app->getTemplate(true);
  51  
  52          // Push the error object into the document
  53          $this->getDocument()->setError($error);
  54  
  55          // Add registry file for the template asset
  56          $wa = $this->getDocument()->getWebAssetManager()->getRegistry();
  57  
  58          $wa->addTemplateRegistryFile($template->template, $app->getClientId());
  59  
  60          if (!empty($template->parent)) {
  61              $wa->addTemplateRegistryFile($template->parent, $app->getClientId());
  62          }
  63  
  64          if (ob_get_contents()) {
  65              ob_end_clean();
  66          }
  67  
  68          $this->getDocument()->setTitle(Text::_('Error') . ': ' . $error->getCode());
  69  
  70          return $this->getDocument()->render(
  71              false,
  72              [
  73                  'template'         => $template->template,
  74                  'directory'        => JPATH_THEMES,
  75                  'debug'            => JDEBUG,
  76                  'csp_nonce'        => $app->get('csp_nonce'),
  77                  'templateInherits' => $template->parent,
  78                  'params'           => $template->params,
  79              ]
  80          );
  81      }
  82  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer