CoreFiles by mySites.guru
EventReturnAware.php53 lines, 1,261 bytes, from Joomla_5.0.0-beta3-Beta-Full_Package.zip
Raw History Compare with 5.0.0-beta2
md5
1420050db0a24e9678fc75e609cd3b30
sha1
7399a0e7ef9044ce403343fec2a7c108075f2bc1
sha256
c0bbd87bb4bd9b979e5c48837d8a30945425a78881f658cf99d9c592806242df
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  System.Webauthn
 *
 * @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\Plugin\System\Webauthn\PluginTraits;

use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\Event\Event;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Utility trait to facilitate returning data from event handlers.
 *
 * @since 4.2.0
 */
trait EventReturnAware
{
    /**
     * Adds a result value to an event
     *
     * @param   Event   $event  The event we were processing
     * @param   mixed   $value  The value to append to the event's results
     *
     * @return  void
     * @since   4.2.0
     */
    private function returnFromEvent(Event $event, $value = null): void
    {
        if ($event instanceof ResultAwareInterface) {
            $event->addResult($value);
            return;
        }

        $result = $event->getArgument('result') ?: [];

        if (!is_array($result)) {
            $result = [$result];
        }

        $result[] = $value;

        $event->setArgument('result', $result);
    }
}

The same content is in 4 releases, Joomla 5.0.0-alpha4 to 5.0.0-beta3. See them all, or every version of this file.