- md5
- 73d66cb03dc3a55a9e6657fab1497fe1
- sha1
- 387e4a2b6a9766401d47e720bd6e6cf87d586323
- sha256
- 67455934c4f505b2663e7c2d8f7b74a0c1f120ab32c16a27c482a563404ec907
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Pathway;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
/**
* Class to maintain a pathway.
*
* The user's navigated path within the application.
*
* @since 1.5
*/
class Pathway
{
/**
* Array to hold the pathway item objects
*
* @var array
* @since 4.0.0
*/
protected $pathway = array();
/**
* Integer number of items in the pathway
*
* @var integer
* @since 4.0.0
*/
protected $count = 0;
/**
* Pathway instances container.
*
* @var Pathway[]
* @since 1.7
*/
protected static $instances = array();
/**
* Returns a Pathway object
*
* @param string $client The name of the client
*
* @return Pathway A Pathway object.
*
* @since 1.5
* @throws \RuntimeException
* @deprecated 5.0 Get the instance from the application, eg. $application->getPathway()
*/
public static function getInstance($client)
{
if (empty(self::$instances[$client])) {
// Create a Pathway object
$name = ucfirst($client) . 'Pathway';
if (!Factory::getContainer()->has($name)) {
throw new \RuntimeException(Text::sprintf('JLIB_APPLICATION_ERROR_PATHWAY_LOAD', $client), 500);
}
self::$instances[$client] = Factory::getContainer()->get($name);
}
return self::$instances[$client];
}
/**
* Return the Pathway items array
*
* @return array Array of pathway items
*
* @since 1.5
*/
public function getPathway()
{
// Use array_values to reset the array keys numerically
return array_values($this->pathway);
}
/**
* Set the Pathway items array.
*
* @param array $pathway An array of pathway objects.
*
* @return array The previous pathway data.
*
* @since 1.5
*/
public function setPathway($pathway)
{
$oldPathway = $this->pathway;
// Set the new pathway.
$this->pathway = array_values((array) $pathway);
return array_values($oldPathway);
}
/**
* Create and return an array of the pathway names.
*
* @return array Array of names of pathway items
*
* @since 1.5
*/
public function getPathwayNames()
{
$names = array();
// Build the names array using just the names of each pathway item
foreach ($this->pathway as $item) {
$names[] = $item->name;
}
// Use array_values to reset the array keys numerically
return array_values($names);
}
/**
* Create and add an item to the pathway.
*
* @param string $name The name of the item.
* @param string $link The link to the item.
*
* @return boolean True on success
*
* @since 1.5
*/
public function addItem($name, $link = '')
{
$ret = false;
if ($this->pathway[] = $this->makeItem($name, $link)) {
$ret = true;
$this->count++;
}
return $ret;
}
/**
* Set item name.
*
* @param integer $id The id of the item on which to set the name.
* @param string $name The name to set.
*
* @return boolean True on success
*
* @since 1.5
*/
public function setItemName($id, $name)
{
$ret = false;
if (isset($this->pathway[$id])) {
$this->pathway[$id]->name = $name;
$ret = true;
}
return $ret;
}
/**
* Create and return a new pathway object.
*
* @param string $name Name of the item
* @param string $link Link to the item
*
* @return \stdClass Pathway item object
*
* @since 3.1
*/
protected function makeItem($name, $link)
{
$item = new \stdClass();
$item->name = html_entity_decode($name, ENT_COMPAT, 'UTF-8');
$item->link = $link;
return $item;
}
}
The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.