CoreFiles by mySites.guru
TaskOptions.php75 lines, 1,722 bytes, from Joomla_4.1.4-Stable-Full_Package.zip
Raw History Compare with 4.1.3
md5
b461ef8f92d2656e8fa4a56e82080d02
sha1
8b84d00a8a0561abdbc8a3df02758a1f2b6d9530
sha256
5cd7638e1c1fcb7c0e3d386a709561e03b039683c457dfbe840d25041b4272db
<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_scheduler
 *
 * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Scheduler\Administrator\Task;

// Restrict direct access
\defined('_JEXEC') or die;

/**
 * The TaskOptions class.
 * Used as the subject argument for the `onTaskOptionsList` event, plugins that support tasks must add them to the
 * object through the addOptions() method.
 *
 * @since  4.1.0
 */
class TaskOptions
{
	/**
	 * An array of TaskOptions
	 *
	 * @var TaskOption[]
	 * @since  4.1.0
	 */
	public $options = [];

	/**
	 * A plugin can support several task routines
	 * This method is used by a plugin's onTaskOptionsList subscriber to advertise supported routines.
	 *
	 * @param   array  $taskRoutines  An associative array of {@var TaskOption} constructor argument pairs:
	 *                                [ 'routineId' => 'languageConstantPrefix', ... ]
	 *
	 * @return void
	 *
	 * @since  4.1.0
	 */
	public function addOptions(array $taskRoutines): void
	{
		foreach ($taskRoutines as $routineId => $langConstPrefix)
		{
			$this->options[] = new TaskOption($routineId, $langConstPrefix);
		}
	}

	/**
	 * @param   ?string  $routineId  A unique identifier for a plugin task routine
	 *
	 * @return  ?TaskOption  A matching TaskOption if available, null otherwise
	 *
	 * @since  4.1.0
	 */
	public function findOption(?string $routineId): ?TaskOption
	{
		if ($routineId === null)
		{
			return null;
		}

		foreach ($this->options as $option)
		{
			if ($option->id === $routineId)
			{
				return $option;
			}
		}

		return null;
	}
}

The same content is in 16 releases, Joomla 4.1.1-rc1 to 4.2.0-beta2. See them all, or every version of this file.