Source for file pathway.php

Documentation is available at pathway.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Pathway
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Class to maintain a pathway.
  14.  *
  15.  * The user's navigated path within the application.
  16.  *
  17.  * @package     Joomla.Libraries
  18.  * @subpackage  Pathway
  19.  * @since       1.5
  20.  */
  21. class JPathway
  22. {
  23.     /**
  24.      * @var    array  Array to hold the pathway item objects
  25.      * @since  1.5
  26.      * @deprecated  4.0  Will convert to $pathway
  27.      */
  28.     protected $_pathway = array();
  29.  
  30.     /**
  31.      * @var    integer  Integer number of items in the pathway
  32.      * @since  1.5
  33.      * @deprecated  4.0  Will convert to $count
  34.      */
  35.     protected $_count = 0;
  36.  
  37.     /**
  38.      * @var    array  JPathway instances container.
  39.      * @since  1.7
  40.      */
  41.     protected static $instances array();
  42.  
  43.     /**
  44.      * Class constructor
  45.      *
  46.      * @param   array  $options  The class options.
  47.      *
  48.      * @since   1.5
  49.      */
  50.     public function __construct($options array())
  51.     {
  52.     }
  53.  
  54.     /**
  55.      * Returns a JPathway object
  56.      *
  57.      * @param   string  $client   The name of the client
  58.      * @param   array   $options  An associative array of options
  59.      *
  60.      * @return  JPathway  A JPathway object.
  61.      *
  62.      * @since   1.5
  63.      * @throws  RuntimeException
  64.      */
  65.     public static function getInstance($client$options array())
  66.     {
  67.         if (empty(self::$instances[$client]))
  68.         {
  69.             // Create a JPathway object
  70.             $classname 'JPathway' ucfirst($client);
  71.  
  72.             if (!class_exists($classname))
  73.             {
  74.                 // @deprecated 4.0 Everything in this block is deprecated but the warning is only logged after the file_exists
  75.                 // Load the pathway object
  76.                 $info JApplicationHelper::getClientInfo($clienttrue);
  77.  
  78.                 if (is_object($info))
  79.                 {
  80.                     $path $info->path '/includes/pathway.php';
  81.  
  82.                     if (file_exists($path))
  83.                     {
  84.                         JLog::add('Non-autoloadable JPathway subclasses are deprecated, support will be removed in 4.0.'JLog::WARNING'deprecated');
  85.                         include_once $path;
  86.                     }
  87.                 }
  88.             }
  89.  
  90.             if (class_exists($classname))
  91.             {
  92.                 self::$instances[$clientnew $classname($options);
  93.             }
  94.             else
  95.             {
  96.                 throw new RuntimeException(JText::sprintf('JLIB_APPLICATION_ERROR_PATHWAY_LOAD'$client)500);
  97.             }
  98.         }
  99.  
  100.         return self::$instances[$client];
  101.     }
  102.  
  103.     /**
  104.      * Return the JPathway items array
  105.      *
  106.      * @return  array  Array of pathway items
  107.      *
  108.      * @since   1.5
  109.      */
  110.     public function getPathway()
  111.     {
  112.         $pw $this->_pathway;
  113.  
  114.         // Use array_values to reset the array keys numerically
  115.         return array_values($pw);
  116.     }
  117.  
  118.     /**
  119.      * Set the JPathway items array.
  120.      *
  121.      * @param   array  $pathway  An array of pathway objects.
  122.      *
  123.      * @return  array  The previous pathway data.
  124.      *
  125.      * @since   1.5
  126.      */
  127.     public function setPathway($pathway)
  128.     {
  129.         $oldPathway $this->_pathway;
  130.  
  131.         // Set the new pathway.
  132.         $this->_pathway = array_values((array) $pathway);
  133.  
  134.         return array_values($oldPathway);
  135.     }
  136.  
  137.     /**
  138.      * Create and return an array of the pathway names.
  139.      *
  140.      * @return  array  Array of names of pathway items
  141.      *
  142.      * @since   1.5
  143.      */
  144.     public function getPathwayNames()
  145.     {
  146.         $names array();
  147.  
  148.         // Build the names array using just the names of each pathway item
  149.         foreach ($this->_pathway as $item)
  150.         {
  151.             $names[$item->name;
  152.         }
  153.  
  154.         // Use array_values to reset the array keys numerically
  155.         return array_values($names);
  156.     }
  157.  
  158.     /**
  159.      * Create and add an item to the pathway.
  160.      *
  161.      * @param   string  $name  The name of the item.
  162.      * @param   string  $link  The link to the item.
  163.      *
  164.      * @return  boolean  True on success
  165.      *
  166.      * @since   1.5
  167.      */
  168.     public function addItem($name$link '')
  169.     {
  170.         $ret false;
  171.  
  172.         if ($this->_pathway[$this->makeItem($name$link))
  173.         {
  174.             $ret true;
  175.             $this->_count++;
  176.         }
  177.  
  178.         return $ret;
  179.     }
  180.  
  181.     /**
  182.      * Set item name.
  183.      *
  184.      * @param   integer  $id    The id of the item on which to set the name.
  185.      * @param   string   $name  The name to set.
  186.      *
  187.      * @return  boolean  True on success
  188.      *
  189.      * @since   1.5
  190.      */
  191.     public function setItemName($id$name)
  192.     {
  193.         $ret false;
  194.  
  195.         if (isset($this->_pathway[$id]))
  196.         {
  197.             $this->_pathway[$id]->name $name;
  198.             $ret true;
  199.         }
  200.  
  201.         return $ret;
  202.     }
  203.  
  204.     /**
  205.      * Create and return a new pathway object.
  206.      *
  207.      * @param   string  $name  Name of the item
  208.      * @param   string  $link  Link to the item
  209.      *
  210.      * @return  JPathway  Pathway item object
  211.      *
  212.      * @since   1.5
  213.      * @deprecated  4.0  Use makeItem() instead
  214.      */
  215.     protected function _makeItem($name$link)
  216.     {
  217.         return $this->makeItem($name$link);
  218.     }
  219.  
  220.     /**
  221.      * Create and return a new pathway object.
  222.      *
  223.      * @param   string  $name  Name of the item
  224.      * @param   string  $link  Link to the item
  225.      *
  226.      * @return  JPathway  Pathway item object
  227.      *
  228.      * @since   3.1
  229.      */
  230.     protected function makeItem($name$link)
  231.     {
  232.         $item new stdClass;
  233.         $item->name html_entity_decode($nameENT_COMPAT'UTF-8');
  234.         $item->link $link;
  235.  
  236.         return $item;
  237.     }
  238. }

Documentation generated on Tue, 19 Nov 2013 15:10:23 +0100 by phpDocumentor 1.4.3