[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Component/Router/ -> RouterLegacy.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Component\Router;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Default routing class for missing or legacy component routers
  18   *
  19   * @since  3.3
  20   */
  21  class RouterLegacy implements RouterInterface
  22  {
  23      /**
  24       * Name of the component
  25       *
  26       * @var    string
  27       * @since  3.3
  28       */
  29      protected $component;
  30  
  31      /**
  32       * Constructor
  33       *
  34       * @param   string  $component  Component name without the com_ prefix this router should react upon
  35       *
  36       * @since   3.3
  37       */
  38      public function __construct($component)
  39      {
  40          $this->component = $component;
  41      }
  42  
  43      /**
  44       * Generic preprocess function for missing or legacy component router
  45       *
  46       * @param   array  $query  An associative array of URL arguments
  47       *
  48       * @return  array  The URL arguments to use to assemble the subsequent URL.
  49       *
  50       * @since   3.3
  51       */
  52      public function preprocess($query)
  53      {
  54          return $query;
  55      }
  56  
  57      /**
  58       * Generic build function for missing or legacy component router
  59       *
  60       * @param   array  &$query  An array of URL arguments
  61       *
  62       * @return  array  The URL arguments to use to assemble the subsequent URL.
  63       *
  64       * @since   3.3
  65       */
  66      public function build(&$query)
  67      {
  68          $function = $this->component . 'BuildRoute';
  69  
  70          if (\function_exists($function)) {
  71              $segments = $function($query);
  72              $total    = \count($segments);
  73  
  74              for ($i = 0; $i < $total; $i++) {
  75                  $segments[$i] = str_replace(':', '-', $segments[$i]);
  76              }
  77  
  78              return $segments;
  79          }
  80  
  81          return array();
  82      }
  83  
  84      /**
  85       * Generic parse function for missing or legacy component router
  86       *
  87       * @param   array  &$segments  The segments of the URL to parse.
  88       *
  89       * @return  array  The URL attributes to be used by the application.
  90       *
  91       * @since   3.3
  92       */
  93      public function parse(&$segments)
  94      {
  95          $function = $this->component . 'ParseRoute';
  96  
  97          if (\function_exists($function)) {
  98              $total = \count($segments);
  99  
 100              for ($i = 0; $i < $total; $i++) {
 101                  $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1);
 102              }
 103  
 104              return $function($segments);
 105          }
 106  
 107          return array();
 108      }
 109  }


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