[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/uri/src/ -> Uri.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Uri Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Uri;
  10  
  11  /**
  12   * Uri Class
  13   *
  14   * This class parses a URI and provides a common interface for the Joomla Framework to access and manipulate a URI.
  15   *
  16   * @since  1.0
  17   */
  18  class Uri extends AbstractUri
  19  {
  20      /**
  21       * Adds a query variable and value, replacing the value if it already exists and returning the old value
  22       *
  23       * @param   string  $name   Name of the query variable to set.
  24       * @param   string  $value  Value of the query variable.
  25       *
  26       * @return  string  Previous value for the query variable.
  27       *
  28       * @since   1.0
  29       */
  30  	public function setVar($name, $value)
  31      {
  32          $tmp = $this->vars[$name] ?? null;
  33  
  34          $this->vars[$name] = $value;
  35  
  36          // Empty the query
  37          $this->query = null;
  38  
  39          return $tmp;
  40      }
  41  
  42      /**
  43       * Removes an item from the query string variables if it exists
  44       *
  45       * @param   string  $name  Name of variable to remove.
  46       *
  47       * @return  void
  48       *
  49       * @since   1.0
  50       */
  51  	public function delVar($name)
  52      {
  53          if (array_key_exists($name, $this->vars))
  54          {
  55              unset($this->vars[$name]);
  56  
  57              // Empty the query
  58              $this->query = null;
  59          }
  60      }
  61  
  62      /**
  63       * Sets the query to a supplied string in format foo=bar&x=y
  64       *
  65       * @param   array|string  $query  The query string or array.
  66       *
  67       * @return  void
  68       *
  69       * @since   1.0
  70       */
  71  	public function setQuery($query)
  72      {
  73          if (\is_array($query))
  74          {
  75              $this->vars = $query;
  76          }
  77          else
  78          {
  79              if (strpos($query, '&amp;') !== false)
  80              {
  81                  $query = str_replace('&amp;', '&', $query);
  82              }
  83  
  84              parse_str($query, $this->vars);
  85          }
  86  
  87          // Empty the query
  88          $this->query = null;
  89      }
  90  
  91      /**
  92       * Set the URI scheme (protocol)
  93       *
  94       * @param   string  $scheme  The URI scheme.
  95       *
  96       * @return  Uri  This method supports chaining.
  97       *
  98       * @since   1.0
  99       */
 100  	public function setScheme($scheme)
 101      {
 102          $this->scheme = $scheme;
 103  
 104          return $this;
 105      }
 106  
 107      /**
 108       * Set the URI username
 109       *
 110       * @param   string  $user  The URI username.
 111       *
 112       * @return  Uri  This method supports chaining.
 113       *
 114       * @since   1.0
 115       */
 116  	public function setUser($user)
 117      {
 118          $this->user = $user;
 119  
 120          return $this;
 121      }
 122  
 123      /**
 124       * Set the URI password
 125       *
 126       * @param   string  $pass  The URI password.
 127       *
 128       * @return  Uri  This method supports chaining.
 129       *
 130       * @since   1.0
 131       */
 132  	public function setPass($pass)
 133      {
 134          $this->pass = $pass;
 135  
 136          return $this;
 137      }
 138  
 139      /**
 140       * Set the URI host
 141       *
 142       * @param   string  $host  The URI host.
 143       *
 144       * @return  Uri  This method supports chaining.
 145       *
 146       * @since   1.0
 147       */
 148  	public function setHost($host)
 149      {
 150          $this->host = $host;
 151  
 152          return $this;
 153      }
 154  
 155      /**
 156       * Set the URI port
 157       *
 158       * @param   integer  $port  The URI port number.
 159       *
 160       * @return  Uri  This method supports chaining.
 161       *
 162       * @since   1.0
 163       */
 164  	public function setPort($port)
 165      {
 166          $this->port = $port;
 167  
 168          return $this;
 169      }
 170  
 171      /**
 172       * Set the URI path string
 173       *
 174       * @param   string  $path  The URI path string.
 175       *
 176       * @return  Uri  This method supports chaining.
 177       *
 178       * @since   1.0
 179       */
 180  	public function setPath($path)
 181      {
 182          $this->path = $this->cleanPath($path);
 183  
 184          return $this;
 185      }
 186  
 187      /**
 188       * Set the URI anchor string
 189       *
 190       * @param   string  $anchor  The URI anchor string.
 191       *
 192       * @return  Uri  This method supports chaining.
 193       *
 194       * @since   1.0
 195       */
 196  	public function setFragment($anchor)
 197      {
 198          $this->fragment = $anchor;
 199  
 200          return $this;
 201      }
 202  }


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