[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/debug/src/ -> DataFormatter.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  System.Debug
   6   *
   7   * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Plugin\System\Debug;
  12  
  13  use DebugBar\DataFormatter\DataFormatter as DebugBarDataFormatter;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('_JEXEC') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * DataFormatter
  21   *
  22   * @since  4.0.0
  23   */
  24  class DataFormatter extends DebugBarDataFormatter
  25  {
  26      /**
  27       * Strip the root path.
  28       *
  29       * @param   string  $path         The path.
  30       * @param   string  $replacement  The replacement
  31       *
  32       * @return string
  33       *
  34       * @since 4.0.0
  35       */
  36      public function formatPath($path, $replacement = ''): string
  37      {
  38          return str_replace(JPATH_ROOT, $replacement, $path);
  39      }
  40  
  41      /**
  42       * Format a string from back trace.
  43       *
  44       * @param   array  $call  The array to format
  45       *
  46       * @return string
  47       *
  48       * @since 4.0.0
  49       */
  50      public function formatCallerInfo(array $call): string
  51      {
  52          $string = '';
  53  
  54          if (isset($call['class'])) {
  55              // If entry has Class/Method print it.
  56              $string .= htmlspecialchars($call['class'] . $call['type'] . $call['function']) . '()';
  57          } elseif (isset($call['args'][0]) && \is_array($call['args'][0])) {
  58              $string .= htmlspecialchars($call['function']) . ' (';
  59  
  60              foreach ($call['args'][0] as $arg) {
  61                  // Check if the arguments can be used as string
  62                  if (\is_object($arg) && !method_exists($arg, '__toString')) {
  63                      $arg = \get_class($arg);
  64                  }
  65  
  66                  // Keep only the size of array
  67                  if (\is_array($arg)) {
  68                      $arg = 'Array(count=' . \count($arg) . ')';
  69                  }
  70  
  71                  $string .= htmlspecialchars($arg) . ', ';
  72              }
  73  
  74              $string = rtrim($string, ', ') . ')';
  75          } elseif (isset($call['args'][0])) {
  76              $string .= htmlspecialchars($call['function']) . ' ' . $call['args'][0];
  77          } else {
  78              // It's a function.
  79              $string .= htmlspecialchars($call['function']) . '()';
  80          }
  81  
  82          return $string;
  83      }
  84  }


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