[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/database/src/Query/ -> QueryElement.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Database Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Database\Query;
  10  
  11  /**
  12   * Query Element Class.
  13   *
  14   * @since  1.0
  15   */
  16  class QueryElement
  17  {
  18      /**
  19       * The name of the element.
  20       *
  21       * @var    string
  22       * @since  1.0
  23       */
  24      protected $name;
  25  
  26      /**
  27       * An array of elements.
  28       *
  29       * @var    string[]
  30       * @since  1.0
  31       */
  32      protected $elements = [];
  33  
  34      /**
  35       * Glue piece.
  36       *
  37       * @var    string
  38       * @since  1.0
  39       */
  40      protected $glue;
  41  
  42      /**
  43       * Constructor.
  44       *
  45       * @param   string           $name      The name of the element.
  46       * @param   string[]|string  $elements  String or array.
  47       * @param   string           $glue      The glue for elements.
  48       *
  49       * @since   1.0
  50       */
  51  	public function __construct($name, $elements, $glue = ',')
  52      {
  53          $this->name = $name;
  54          $this->glue = $glue;
  55  
  56          $this->append($elements);
  57      }
  58  
  59      /**
  60       * Magic function to convert the query element to a string.
  61       *
  62       * @return  string
  63       *
  64       * @since   1.0
  65       */
  66  	public function __toString()
  67      {
  68          if (substr($this->name, -2) === '()')
  69          {
  70              return \PHP_EOL . substr($this->name, 0, -2) . '(' . implode($this->glue, $this->elements) . ')';
  71          }
  72  
  73          return \PHP_EOL . $this->name . ' ' . implode($this->glue, $this->elements);
  74      }
  75  
  76      /**
  77       * Appends element parts to the internal list.
  78       *
  79       * @param   string[]|string  $elements  String or array.
  80       *
  81       * @return  void
  82       *
  83       * @since   1.0
  84       */
  85  	public function append($elements)
  86      {
  87          if (\is_array($elements))
  88          {
  89              $this->elements = array_merge($this->elements, $elements);
  90          }
  91          else
  92          {
  93              $this->elements = array_merge($this->elements, [$elements]);
  94          }
  95      }
  96  
  97      /**
  98       * Gets the elements of this element.
  99       *
 100       * @return  string[]
 101       *
 102       * @since   1.0
 103       */
 104  	public function getElements()
 105      {
 106          return $this->elements;
 107      }
 108  
 109      /**
 110       * Gets the glue of this element.
 111       *
 112       * @return  string  Glue of the element.
 113       *
 114       * @since   2.0.0
 115       */
 116  	public function getGlue()
 117      {
 118          return $this->glue;
 119      }
 120  
 121      /**
 122       * Gets the name of this element.
 123       *
 124       * @return  string  Name of the element.
 125       *
 126       * @since   1.7.0
 127       */
 128  	public function getName()
 129      {
 130          return $this->name;
 131      }
 132  
 133      /**
 134       * Sets the name of this element.
 135       *
 136       * @param   string  $name  Name of the element.
 137       *
 138       * @return  $this
 139       *
 140       * @since   1.3.0
 141       */
 142  	public function setName($name)
 143      {
 144          $this->name = $name;
 145  
 146          return $this;
 147      }
 148  
 149      /**
 150       * Method to provide basic copy support.
 151       *
 152       * Any object pushed into the data of this class should have its own __clone() implementation.
 153       * This method does not support copying objects in a multidimensional array.
 154       *
 155       * @return  void
 156       *
 157       * @since   1.0
 158       */
 159  	public function __clone()
 160      {
 161          foreach ($this as $k => $v)
 162          {
 163              if (\is_object($v))
 164              {
 165                  $this->{$k} = clone $v;
 166              }
 167              elseif (\is_array($v))
 168              {
 169                  foreach ($v as $i => $element)
 170                  {
 171                      if (\is_object($element))
 172                      {
 173                          $this->{$k}[$i] = clone $element;
 174                      }
 175                  }
 176              }
 177          }
 178      }
 179  }


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