File manager - Edit - /home/opticamezl/www/newok/Result.tar
Back
ResultTypeIntegerAware.php 0000644 00000003373 15173321534 0011705 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of an Integer type. * * @since 4.2.0 */ trait ResultTypeIntegerAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Can the result attribute values also be boolean FALSE? * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * You should use nullable values or exceptions instead of returning boolean false results. */ protected $resultIsFalseable = false; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if ($this->resultIsFalseable && $data === false) { return; } if (!is_int($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts Integer results.', $this->getName())); } } } ResultTypeMixedAware.php 0000644 00000002225 15173321534 0011351 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of a any type. THIS IS A COP OUT! If you expect a nullable or union type it's best to implement * the typeCheckResult method yourself to check for the exact types you expect. * * @since 4.2.0 */ trait ResultTypeMixedAware { /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { // Intentionally left blank; no type check is performed. } } ResultTypeNumericAware.php 0000644 00000003376 15173321534 0011715 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of a Numeric type. * * @since 4.2.0 */ trait ResultTypeNumericAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Can the result attribute values also be boolean FALSE? * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * You should use nullable values or exceptions instead of returning boolean false results. */ protected $resultIsFalseable = false; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if ($this->resultIsFalseable && $data === false) { return; } if (!is_numeric($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts Numeric results.', $this->getName())); } } } ResultTypeFloatAware.php 0000644 00000003366 15173321534 0011357 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of a Float type. * * @since 4.2.0 */ trait ResultTypeFloatAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Can the result attribute values also be boolean FALSE? * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * You should use nullable values or exceptions instead of returning boolean false results. */ protected $resultIsFalseable = false; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if ($this->resultIsFalseable && $data === false) { return; } if (!is_float($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts Float results.', $this->getName())); } } } ResultTypeBooleanAware.php 0000644 00000002522 15173321534 0011662 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of a Boolean type. * * @since 4.2.0 */ trait ResultTypeBooleanAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if (!is_bool($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts Boolean results.', $this->getName())); } } } ResultTypeStringAware.php 0000644 00000003372 15173321534 0011555 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of a String type. * * @since 4.2.0 */ trait ResultTypeStringAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Can the result attribute values also be boolean FALSE? * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * You should use nullable values or exceptions instead of returning boolean false results. */ protected $resultIsFalseable = false; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if ($this->resultIsFalseable && $data === false) { return; } if (!is_string($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts String results.', $this->getName())); } } } ResultAwareInterface.php 0000644 00000003101 15173321534 0011333 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * Defines an Event which has an append-only array argument named 'result'. * * This is used for Events whose handlers are expected to return something when called, similar to * how many plugin events worked in earlier versions of Joomla. * * This interface is partially implemented by the ResultAware trait. The typeCheckResult method is * implemented by the various ResultType*Aware traits. Your event needs to use both the ResultAware * trait and one of the ResultType*Aware traits. For example, if your event returns boolean results * you need to use the ResultAware and ResultTypeBooleanAware traits in your event. * * @since 4.2.0 */ interface ResultAwareInterface { /** * Appends data to the result array of the event. * * @param mixed $data What to add to the result array. * * @return void * @since 4.2.0 */ public function addResult($data): void; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void; } ResultTypeArrayAware.php 0000644 00000003367 15173321534 0011371 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of an Array type. * * @since 4.2.0 */ trait ResultTypeArrayAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Can the result attribute values also be boolean FALSE? * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * You should use nullable values or exceptions instead of returning boolean false results. */ protected $resultIsFalseable = false; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if ($this->resultIsFalseable && $data === false) { return; } if (!is_array($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts Array results.', $this->getName())); } } } ResultTypeObjectAware.php 0000644 00000005021 15173321534 0011506 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for type checking. * * Events using this Trait (and the ResultAware trait) will expect event handlers to set results * of an object type. * * If you do not set a list of acceptable result classes any PHP object will satisfy this type check. * * @since 4.2.0 */ trait ResultTypeObjectAware { /** * Can the result attribute values also be NULL? * * @var boolean * @since 4.2.0 */ protected $resultIsNullable = false; /** * Can the result attribute values also be boolean FALSE? * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * You should use nullable values or exceptions instead of returning boolean false results. */ protected $resultIsFalseable = false; /** * Acceptable class names for result values. * * @var array * @since 4.2.0 */ protected $resultAcceptableClasses = []; /** * Checks the type of the data being appended to the result argument. * * @param mixed $data The data to type check * * @return void * @throws \InvalidArgumentException * * @internal * @since 4.2.0 */ public function typeCheckResult($data): void { if ($this->resultIsNullable && $data === null) { return; } if ($this->resultIsFalseable && $data === false) { return; } if (!is_object($data)) { throw new \InvalidArgumentException(sprintf('Event %s only accepts object results.', $this->getName())); } if (empty($this->resultAcceptableClasses)) { return; } foreach ($this->resultAcceptableClasses as $className) { if (is_a($data, $className)) { return; } } $acceptableTypes = implode(', ', $this->resultAcceptableClasses); $messageTemplate = 'Event %s only accepts object results which are instances of one of %s.'; throw new \InvalidArgumentException(sprintf($messageTemplate, $this->getName(), $acceptableTypes)); } } ResultAware.php 0000644 00000011334 15173321534 0007521 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Event\Result; use BadMethodCallException; use Joomla\Event\Event as BaseEvent; // phpcs:disable PSR1.Files.SideEffects \defined('JPATH_PLATFORM') or die; // phpcs:enable PSR1.Files.SideEffects /** * This Trait partially implements the ResultAwareInterface for mutable and immutable events. * * You must additionally implement the typeCheckResult method or use one of the ResultType*Aware * traits in your Event handler. * * @since 4.2.0 */ trait ResultAware { /** * Disallow setting the result argument directly with setArgument() instead of going through addResult(). * * You should set this to true ONLY for event names which did NOT exist before Joomla 4.2.0 * or if you are a third party developer introducing new event names for use only in your software. * * @var boolean * @since 4.2.0 * * @deprecated 4.3 will be removed in 6.0 * Using setResult() for the result argument will always be disallowed. */ protected $preventSetArgumentResult = false; /** * Appends data to the result array of the event. * * @param mixed $data What to add to the result array. * * @return void * @since 4.2.0 */ public function addResult($data): void { // Ensure this trait is applied to an Event object. if (!($this instanceof BaseEvent)) { throw new \LogicException(sprintf('Event class ā%sā must implement %s.', get_class($this), BaseEvent::class)); } // Ensure the Event object fully implements the ResultAwareInterface. if (!($this instanceof ResultAwareInterface)) { throw new \LogicException(sprintf('Event class ā%sā must implement %s.', get_class($this), ResultAwareInterface::class)); } // Make sure the data type is correct $this->typeCheckResult($data); // Append the result. We use the arguments property directly to allow this to work on immutable events. $this->arguments['result'] = $this->arguments['result'] ?? []; $this->arguments['result'][] = $data; } /** * Handle setting the result argument directly. * * This method serves a dual purpose: backwards compatibility and enforcing the use of addResult. * * When $this->preventSetArgumentResult is false it acts as a backwards compatibility shim for * event handlers expecting generic event classes instead of the concrete Events implemented in * this package. This allows the migration to concrete event classes throughout the lifetime of * Joomla 4.x. * * When $this->preventSetArgumentResult is false (which will always be the case on Joomla 5.0) * it will throw a BadMethodCallException if the developer tries to call setArgument('result', ...) * instead of going through the addResult() method. * * @param array $value The new result array. * * @return array * @since 4.2.0 * * @deprecated 4.4.0 will be removed in 6.0 * Use counterpart with onSet prefix */ protected function setResult(array $value) { if ($this->preventSetArgumentResult) { throw new \BadMethodCallException('You are not allowed to set the result argument directly. Use addResult() instead.'); } // Always assume that the last element of the array is the result the handler is trying to append. $latestValue = array_pop($value); $this->addResult($latestValue); return $this->arguments['result']; } /** * Handle setting the result argument directly. * * This method serves a dual purpose: backwards compatibility and enforcing the use of addResult. * * When $this->preventSetArgumentResult is false it acts as a backwards compatibility shim for * event handlers expecting generic event classes instead of the concrete Events implemented in * this package. This allows the migration to concrete event classes throughout the lifetime of * Joomla 4.x. * * When $this->preventSetArgumentResult is false (which will always be the case on Joomla 5.0) * it will throw a BadMethodCallException if the developer tries to call setArgument('result', ...) * instead of going through the addResult() method. * * @param array $value The new result array. * * @return array * @since 4.4.0 */ protected function onSetResult(array $value) { return $this->setResult($value); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings