[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Event/Table/ -> BeforeCheckoutEvent.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 onBeforeCheckout event
  20   *
  21   * @since  4.0.0
  22   */
  23  class BeforeCheckoutEvent extends AbstractEvent
  24  {
  25      /**
  26       * Constructor.
  27       *
  28       * Mandatory arguments:
  29       * subject      JTableInterface The table we are operating on
  30       * userId       integer         The Id of the user checking out the row.
  31       * pk           mixed           An optional primary key value to check out.
  32       *
  33       * @param   string  $name       The event name.
  34       * @param   array   $arguments  The event arguments.
  35       *
  36       * @throws  BadMethodCallException
  37       */
  38      public function __construct($name, array $arguments = array())
  39      {
  40          if (!\array_key_exists('userId', $arguments)) {
  41              throw new BadMethodCallException("Argument 'userId' is required for event $name");
  42          }
  43  
  44          if (!\array_key_exists('pk', $arguments)) {
  45              throw new BadMethodCallException("Argument 'pk' is required for event $name");
  46          }
  47  
  48          parent::__construct($name, $arguments);
  49      }
  50  
  51      /**
  52       * Setter for the userId argument
  53       *
  54       * @param   mixed  $value  The value to set
  55       *
  56       * @return  mixed
  57       *
  58       * @throws  BadMethodCallException  if the argument is not of the expected type
  59       */
  60      protected function setUserId($value)
  61      {
  62          if (!is_numeric($value) || empty($value)) {
  63              throw new BadMethodCallException("Argument 'userId' of event {$this->name} must be an integer");
  64          }
  65  
  66          return (int) $value;
  67      }
  68  }


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