[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Event/Table/ -> BeforeMoveEvent.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  namespace Joomla\CMS\Event\Table;
  11  
  12  use BadMethodCallException;
  13  use Joomla\Database\DatabaseQuery;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Event class for JTable's onBeforeMove event
  21   *
  22   * @since  4.0.0
  23   */
  24  class BeforeMoveEvent extends AbstractEvent
  25  {
  26      /**
  27       * Constructor.
  28       *
  29       * Mandatory arguments:
  30       * subject      JTableInterface The table we are operating on
  31       * query        DatabaseQuery   The query to get the primary keys and ordering values for the selection.
  32       * delta        int             The direction and magnitude to move the row in the ordering sequence.
  33       * where        string          WHERE clause to use for limiting the selection of rows to compact the ordering values.
  34       *
  35       * @param   string  $name       The event name.
  36       * @param   array   $arguments  The event arguments.
  37       *
  38       * @throws  BadMethodCallException
  39       */
  40      public function __construct($name, array $arguments = array())
  41      {
  42          if (!\array_key_exists('query', $arguments)) {
  43              throw new BadMethodCallException("Argument 'query' is required for event $name");
  44          }
  45  
  46          if (!\array_key_exists('delta', $arguments)) {
  47              throw new BadMethodCallException("Argument 'delta' is required for event $name");
  48          }
  49  
  50          if (!\array_key_exists('where', $arguments)) {
  51              throw new BadMethodCallException("Argument 'where' is required for event $name");
  52          }
  53  
  54          parent::__construct($name, $arguments);
  55      }
  56  
  57      /**
  58       * Setter for the query argument
  59       *
  60       * @param   DatabaseQuery  $value  The value to set
  61       *
  62       * @return  mixed
  63       *
  64       * @throws  BadMethodCallException  if the argument is not of the expected type
  65       */
  66      protected function setQuery($value)
  67      {
  68          if (!($value instanceof DatabaseQuery)) {
  69              throw new BadMethodCallException("Argument 'query' of event {$this->name} must be of DatabaseQuery type");
  70          }
  71  
  72          return $value;
  73      }
  74  
  75      /**
  76       * Setter for the delta argument
  77       *
  78       * @param   int  $value  The value to set
  79       *
  80       * @return  integer
  81       *
  82       * @throws  BadMethodCallException  if the argument is not of the expected type
  83       */
  84      protected function setDelta($value)
  85      {
  86          if (!is_numeric($value)) {
  87              throw new BadMethodCallException("Argument 'delta' of event {$this->name} must be an integer");
  88          }
  89  
  90          return (int) $value;
  91      }
  92  
  93      /**
  94       * Setter for the where argument
  95       *
  96       * @param   string|null  $value  The value to set
  97       *
  98       * @return  mixed
  99       *
 100       * @throws  BadMethodCallException  if the argument is not of the expected type
 101       */
 102      protected function setWhere($value)
 103      {
 104          if (!empty($value) && !\is_string($value)) {
 105              throw new BadMethodCallException("Argument 'where' of event {$this->name} must be empty or string");
 106          }
 107  
 108          return $value;
 109      }
 110  }


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