[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_banners/src/Service/ -> Router.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_banners
   6   *
   7   * @copyright   (C) 2006 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\Component\Banners\Site\Service;
  12  
  13  use Joomla\CMS\Component\Router\RouterBase;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('_JEXEC') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Routing class from com_banners
  21   *
  22   * @since  3.3
  23   */
  24  class Router extends RouterBase
  25  {
  26      /**
  27       * Build the route for the com_banners component
  28       *
  29       * @param   array  $query  An array of URL arguments
  30       *
  31       * @return  array  The URL arguments to use to assemble the subsequent URL.
  32       *
  33       * @since   3.3
  34       */
  35      public function build(&$query)
  36      {
  37          $segments = array();
  38  
  39          if (isset($query['task'])) {
  40              $segments[] = $query['task'];
  41              unset($query['task']);
  42          }
  43  
  44          if (isset($query['id'])) {
  45              $segments[] = $query['id'];
  46              unset($query['id']);
  47          }
  48  
  49          $total = \count($segments);
  50  
  51          for ($i = 0; $i < $total; $i++) {
  52              $segments[$i] = str_replace(':', '-', $segments[$i]);
  53          }
  54  
  55          return $segments;
  56      }
  57  
  58      /**
  59       * Parse the segments of a URL.
  60       *
  61       * @param   array  $segments  The segments of the URL to parse.
  62       *
  63       * @return  array  The URL attributes to be used by the application.
  64       *
  65       * @since   3.3
  66       */
  67      public function parse(&$segments)
  68      {
  69          $total = \count($segments);
  70          $vars = array();
  71  
  72          for ($i = 0; $i < $total; $i++) {
  73              $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1);
  74          }
  75  
  76          // View is always the first element of the array
  77          $count = \count($segments);
  78  
  79          if ($count) {
  80              $count--;
  81              $segment = array_shift($segments);
  82  
  83              if (\is_numeric($segment)) {
  84                  $vars['id'] = $segment;
  85              } else {
  86                  $vars['task'] = $segment;
  87              }
  88          }
  89  
  90          if ($count) {
  91              $segment = array_shift($segments);
  92  
  93              if (\is_numeric($segment)) {
  94                  $vars['id'] = $segment;
  95              }
  96          }
  97  
  98          return $vars;
  99      }
 100  }


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