[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_scheduler/src/Event/ -> ExecuteTaskEvent.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_scheduler
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Scheduler\Administrator\Event;
  12  
  13  use Joomla\CMS\Event\AbstractEvent;
  14  use Joomla\Component\Scheduler\Administrator\Task\Task;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('_JEXEC') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Event class for onExecuteTask event.
  22   *
  23   * @since  4.1.0
  24   */
  25  class ExecuteTaskEvent extends AbstractEvent
  26  {
  27      /**
  28       * Constructor.
  29       *
  30       * @param   string  $name       The event name.
  31       * @param   array   $arguments  The event arguments.
  32       *
  33       * @since  4.1.0
  34       * @throws  \BadMethodCallException
  35       */
  36      public function __construct($name, array $arguments = array())
  37      {
  38          parent::__construct($name, $arguments);
  39  
  40          $arguments['resultSnapshot'] = null;
  41  
  42          if (!($arguments['subject'] ?? null) instanceof Task) {
  43              throw new \BadMethodCallException("The subject given for $name event must be an instance of " . Task::class);
  44          }
  45      }
  46  
  47      /**
  48       * Sets the task result snapshot and stops event propagation.
  49       *
  50       * @param   array  $snapshot  The task snapshot.
  51       *
  52       * @return  void
  53       *
  54       * @since  4.1.0
  55       */
  56      public function setResult(array $snapshot = []): void
  57      {
  58          $this->arguments['resultSnapshot'] = $snapshot;
  59  
  60          if (!empty($snapshot)) {
  61              $this->stopPropagation();
  62          }
  63      }
  64  
  65      /**
  66       * @return integer  The task's taskId.
  67       *
  68       * @since  4.1.0
  69       */
  70      public function getTaskId(): int
  71      {
  72          return $this->arguments['subject']->get('id');
  73      }
  74  
  75      /**
  76       * @return  string  The task's 'type'.
  77       *
  78       * @since  4.1.0
  79       */
  80      public function getRoutineId(): string
  81      {
  82          return $this->arguments['subject']->get('type');
  83      }
  84  
  85      /**
  86       * Returns the snapshot of the triggered task if available, else an empty array
  87       *
  88       * @return  array  The task snapshot if available, else null
  89       *
  90       * @since  4.1.0
  91       */
  92      public function getResultSnapshot(): array
  93      {
  94          return $this->arguments['resultSnapshot'] ?? [];
  95      }
  96  }


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