[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Event/Table/ -> BeforePublishEvent.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  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * Event class for JTable's onBeforePublish event
  20   *
  21   * @since  4.0.0
  22   */
  23  class BeforePublishEvent extends AbstractEvent
  24  {
  25      /**
  26       * Constructor.
  27       *
  28       * Mandatory arguments:
  29       * subject      JTableInterface The table we are operating on
  30       * pks          mixed           An optional array of primary key values to update.
  31       * state        int             The publishing state. eg. [0 = unpublished, 1 = published]
  32       * userId       int             The user id of the user performing the operation.
  33       *
  34       * @param   string  $name       The event name.
  35       * @param   array   $arguments  The event arguments.
  36       *
  37       * @throws  BadMethodCallException
  38       */
  39      public function __construct($name, array $arguments = array())
  40      {
  41          if (!\array_key_exists('pks', $arguments)) {
  42              throw new BadMethodCallException("Argument 'pks' is required for event $name");
  43          }
  44  
  45          if (!\array_key_exists('state', $arguments)) {
  46              throw new BadMethodCallException("Argument 'state' is required for event $name");
  47          }
  48  
  49          if (!\array_key_exists('userId', $arguments)) {
  50              throw new BadMethodCallException("Argument 'userId' is required for event $name");
  51          }
  52  
  53          parent::__construct($name, $arguments);
  54      }
  55  
  56      /**
  57       * Setter for the pks argument
  58       *
  59       * @param   array|null  $value  The value to set
  60       *
  61       * @return  mixed
  62       *
  63       * @throws  BadMethodCallException  if the argument is not of the expected type
  64       */
  65      protected function setQuery($value)
  66      {
  67          if (!empty($value) && !\is_array($value)) {
  68              throw new BadMethodCallException("Argument 'pks' of event {$this->name} must be empty or an array");
  69          }
  70  
  71          return $value;
  72      }
  73  
  74      /**
  75       * Setter for the state argument
  76       *
  77       * @param   int  $value  The value to set
  78       *
  79       * @return  integer
  80       *
  81       * @throws  BadMethodCallException  if the argument is not of the expected type
  82       */
  83      protected function setState($value)
  84      {
  85          if (!is_numeric($value)) {
  86              throw new BadMethodCallException("Argument 'state' of event {$this->name} must be an integer");
  87          }
  88  
  89          return (int) $value;
  90      }
  91  
  92      /**
  93       * Setter for the userId argument
  94       *
  95       * @param   int  $value  The value to set
  96       *
  97       * @return  integer
  98       *
  99       * @throws  BadMethodCallException  if the argument is not of the expected type
 100       */
 101      protected function setUserId($value)
 102      {
 103          if (!is_numeric($value)) {
 104              throw new BadMethodCallException("Argument 'userId' of event {$this->name} must be an integer");
 105          }
 106  
 107          return (int) $value;
 108      }
 109  }


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