[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Pathway/ -> Pathway.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.txt
   8   */
   9  
  10  namespace Joomla\CMS\Pathway;
  11  
  12  use Joomla\CMS\Factory;
  13  use Joomla\CMS\Language\Text;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Class to maintain a pathway.
  21   *
  22   * The user's navigated path within the application.
  23   *
  24   * @since  1.5
  25   */
  26  class Pathway
  27  {
  28      /**
  29       * Array to hold the pathway item objects
  30       *
  31       * @var    array
  32       * @since  4.0.0
  33       */
  34      protected $pathway = array();
  35  
  36      /**
  37       * Integer number of items in the pathway
  38       *
  39       * @var    integer
  40       * @since  4.0.0
  41       */
  42      protected $count = 0;
  43  
  44      /**
  45       * Pathway instances container.
  46       *
  47       * @var    Pathway[]
  48       * @since  1.7
  49       */
  50      protected static $instances = array();
  51  
  52      /**
  53       * Returns a Pathway object
  54       *
  55       * @param   string  $client  The name of the client
  56       *
  57       * @return  Pathway  A Pathway object.
  58       *
  59       * @since       1.5
  60       * @throws      \RuntimeException
  61       * @deprecated  5.0 Get the instance from the application, eg. $application->getPathway()
  62       */
  63      public static function getInstance($client)
  64      {
  65          if (empty(self::$instances[$client])) {
  66              // Create a Pathway object
  67              $name = ucfirst($client) . 'Pathway';
  68  
  69              if (!Factory::getContainer()->has($name)) {
  70                  throw new \RuntimeException(Text::sprintf('JLIB_APPLICATION_ERROR_PATHWAY_LOAD', $client), 500);
  71              }
  72  
  73              self::$instances[$client] = Factory::getContainer()->get($name);
  74          }
  75  
  76          return self::$instances[$client];
  77      }
  78  
  79      /**
  80       * Return the Pathway items array
  81       *
  82       * @return  array  Array of pathway items
  83       *
  84       * @since   1.5
  85       */
  86      public function getPathway()
  87      {
  88          // Use array_values to reset the array keys numerically
  89          return array_values($this->pathway);
  90      }
  91  
  92      /**
  93       * Set the Pathway items array.
  94       *
  95       * @param   array  $pathway  An array of pathway objects.
  96       *
  97       * @return  array  The previous pathway data.
  98       *
  99       * @since   1.5
 100       */
 101      public function setPathway($pathway)
 102      {
 103          $oldPathway = $this->pathway;
 104  
 105          // Set the new pathway.
 106          $this->pathway = array_values((array) $pathway);
 107  
 108          return array_values($oldPathway);
 109      }
 110  
 111      /**
 112       * Create and return an array of the pathway names.
 113       *
 114       * @return  array  Array of names of pathway items
 115       *
 116       * @since   1.5
 117       */
 118      public function getPathwayNames()
 119      {
 120          $names = array();
 121  
 122          // Build the names array using just the names of each pathway item
 123          foreach ($this->pathway as $item) {
 124              $names[] = $item->name;
 125          }
 126  
 127          // Use array_values to reset the array keys numerically
 128          return array_values($names);
 129      }
 130  
 131      /**
 132       * Create and add an item to the pathway.
 133       *
 134       * @param   string  $name  The name of the item.
 135       * @param   string  $link  The link to the item.
 136       *
 137       * @return  boolean  True on success
 138       *
 139       * @since   1.5
 140       */
 141      public function addItem($name, $link = '')
 142      {
 143          $ret = false;
 144  
 145          if ($this->pathway[] = $this->makeItem($name, $link)) {
 146              $ret = true;
 147              $this->count++;
 148          }
 149  
 150          return $ret;
 151      }
 152  
 153      /**
 154       * Set item name.
 155       *
 156       * @param   integer  $id    The id of the item on which to set the name.
 157       * @param   string   $name  The name to set.
 158       *
 159       * @return  boolean  True on success
 160       *
 161       * @since   1.5
 162       */
 163      public function setItemName($id, $name)
 164      {
 165          $ret = false;
 166  
 167          if (isset($this->pathway[$id])) {
 168              $this->pathway[$id]->name = $name;
 169              $ret = true;
 170          }
 171  
 172          return $ret;
 173      }
 174  
 175      /**
 176       * Create and return a new pathway object.
 177       *
 178       * @param   string  $name  Name of the item
 179       * @param   string  $link  Link to the item
 180       *
 181       * @return  \stdClass  Pathway item object
 182       *
 183       * @since   3.1
 184       */
 185      protected function makeItem($name, $link)
 186      {
 187          $item = new \stdClass();
 188          $item->name = html_entity_decode($name, ENT_COMPAT, 'UTF-8');
 189          $item->link = $link;
 190  
 191          return $item;
 192      }
 193  }


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