[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Joomla! Content Management System
   4   *
   5   * @copyright  (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
   6   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  namespace Joomla\CMS\Component\Router;
  10  
  11  \defined('JPATH_PLATFORM') or die;
  12  
  13  /**
  14   * View-configuration class for the view-based component router
  15   *
  16   * @since  3.5
  17   */
  18  class RouterViewConfiguration
  19  {
  20      /**
  21       * Name of the view
  22       *
  23       * @var    string
  24       * @since  3.5
  25       */
  26      public $name;
  27  
  28      /**
  29       * Key of the view
  30       *
  31       * @var    string
  32       * @since  3.5
  33       */
  34      public $key = false;
  35  
  36      /**
  37       * Parentview of this one
  38       *
  39       * @var    RouterViewConfiguration
  40       * @since  3.5
  41       */
  42      public $parent = false;
  43  
  44      /**
  45       * Key of the parent view
  46       *
  47       * @var    string
  48       * @since  3.5
  49       */
  50      public $parent_key = false;
  51  
  52      /**
  53       * Is this view nestable?
  54       *
  55       * @var    bool
  56       * @since  3.5
  57       */
  58      public $nestable = false;
  59  
  60      /**
  61       * Layouts that are supported by this view
  62       *
  63       * @var    array
  64       * @since  3.5
  65       */
  66      public $layouts = array('default');
  67  
  68      /**
  69       * Child-views of this view
  70       *
  71       * @var    RouterViewConfiguration[]
  72       * @since  3.5
  73       */
  74      public $children = array();
  75  
  76      /**
  77       * Keys used for this parent view by the child views
  78       *
  79       * @var    array
  80       * @since  3.5
  81       */
  82      public $child_keys = array();
  83  
  84      /**
  85       * Path of views from this one to the root view
  86       *
  87       * @var    array
  88       * @since  3.5
  89       */
  90      public $path = array();
  91  
  92      /**
  93       * Constructor for the View-configuration class
  94       *
  95       * @param   string  $name  Name of the view
  96       *
  97       * @since   3.5
  98       */
  99  	public function __construct($name)
 100      {
 101          $this->name   = $name;
 102          $this->path[] = $name;
 103      }
 104  
 105      /**
 106       * Set the name of the view
 107       *
 108       * @param   string  $name  Name of the view
 109       *
 110       * @return  RouterViewConfiguration  This object for chaining
 111       *
 112       * @since   3.5
 113       */
 114  	public function setName($name)
 115      {
 116          $this->name = $name;
 117  
 118          array_pop($this->path);
 119          $this->path[] = $name;
 120  
 121          return $this;
 122      }
 123  
 124      /**
 125       * Set the key-identifier for the view
 126       *
 127       * @param   string  $key  Key of the view
 128       *
 129       * @return  RouterViewConfiguration  This object for chaining
 130       *
 131       * @since   3.5
 132       */
 133  	public function setKey($key)
 134      {
 135          $this->key = $key;
 136  
 137          return $this;
 138      }
 139  
 140      /**
 141       * Set the parent view of this view
 142       *
 143       * @param   RouterViewConfiguration  $parent     Parent view object
 144       * @param   string                   $parentKey  Key of the parent view in this context
 145       *
 146       * @return  RouterViewConfiguration  This object for chaining
 147       *
 148       * @since   3.5
 149       */
 150  	public function setParent(RouterViewConfiguration $parent, $parentKey = null)
 151      {
 152          if ($this->parent)
 153          {
 154              $key = array_search($this, $this->parent->children);
 155  
 156              if ($key !== false)
 157              {
 158                  unset($this->parent->children[$key]);
 159              }
 160  
 161              if ($this->parent_key)
 162              {
 163                  $child_key = array_search($this->parent_key, $this->parent->child_keys);
 164                  unset($this->parent->child_keys[$child_key]);
 165              }
 166          }
 167  
 168          $this->parent       = $parent;
 169          $parent->children[] = $this;
 170  
 171          $this->path   = $parent->path;
 172          $this->path[] = $this->name;
 173  
 174          $this->parent_key = $parentKey ?? false;
 175  
 176          if ($parentKey)
 177          {
 178              $parent->child_keys[] = $parentKey;
 179          }
 180  
 181          return $this;
 182      }
 183  
 184      /**
 185       * Set if this view is nestable or not
 186       *
 187       * @param   bool  $isNestable  If set to true, the view is nestable
 188       *
 189       * @return  RouterViewConfiguration  This object for chaining
 190       *
 191       * @since   3.5
 192       */
 193  	public function setNestable($isNestable = true)
 194      {
 195          $this->nestable = (bool) $isNestable;
 196  
 197          return $this;
 198      }
 199  
 200      /**
 201       * Add a layout to this view
 202       *
 203       * @param   string  $layout  Layouts that this view supports
 204       *
 205       * @return  RouterViewConfiguration  This object for chaining
 206       *
 207       * @since   3.5
 208       */
 209  	public function addLayout($layout)
 210      {
 211          $this->layouts[] = $layout;
 212          $this->layouts   = array_unique($this->layouts);
 213  
 214          return $this;
 215      }
 216  
 217      /**
 218       * Remove a layout from this view
 219       *
 220       * @param   string  $layout  Layouts that this view supports
 221       *
 222       * @return  RouterViewConfiguration  This object for chaining
 223       *
 224       * @since   3.5
 225       */
 226  	public function removeLayout($layout)
 227      {
 228          $key = array_search($layout, $this->layouts);
 229  
 230          if ($key !== false)
 231          {
 232              unset($this->layouts[$key]);
 233          }
 234  
 235          return $this;
 236      }
 237  }


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