__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?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;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* A Trait to reshape arguments maintaining b/c with legacy plugin events.
*
* Old plugin event handlers expect positional arguments, not named arguments, since they are simple
* PHP methods, e.g.
* public onExample($foo, $bar, $baz).
* Concrete Event classes, however, use named arguments which can be passed in any order. The
* following two examples are equivalent:
* $event1 = new ConcreteEventClass('onExample', ['foo' => 1, 'bar' => 2, 'baz' => 3];
* $event2 = new ConcreteEventClass('onExample', ['bar' => 2, 'baz' => 3, 'foo' => 1,];
* However, this means that the internal $arguments property of the event object holds the named
* arguments in a **different** order in each case.
*
* When the event handler is aware of the ConcreteEventClass it can retrieve named arguments and
* all is good in the world. However, when you have a legacy plugin listener registered through
* CMSPlugin::registerLegacyListener you have a major problem! The legacy listener is passing the
* arguments **positionally**, in the order they were added to the Event object.
*
* In the previous example, $event1 would work as expected because the foo, bar, and baz arguments
* were given in the same order legacy listeners expected them. On the other hand, $event2 would
* fail miserably because the call order would be $bar, $baz, $foo which is NOT what the legacy
* listener expected.
*
* The only way to fix that is to *reshape the argument* in the concrete event's constructor so that
* the order of arguments is guaranteed to be the same as expected by legacy listeners. Moreover,
* since Joomla is passing all arguments (except the 'result' argument) blindly to the legacy
* listener we must ensure that a. all necessary arguments are set and b. any other named arguments
* do NOT exist. Otherwise our legacy listeners would receive the wrong number of positional
* arguments and break.
*
* All this is achieved by the reshapeArguments() method in this trait which has to be called in the
* constructor of the concrete event class.
*
* This trait is marked as deprecated with a removal target of 7.0 because in Joomla 7 we will only
* be using concrete event classes with named arguments, removing legacy listeners and their
* positional arguments headaches.
*
* @since 4.2.0
*
* @deprecated 4.3 will be removed in 7.0
* Will be removed without replacement
*/
trait ReshapeArgumentsAware
{
/**
* Reshape the arguments array to preserve b/c with legacy listeners
*
* @param array $arguments The named arguments array passed to the constructor.
* @param array $argumentNames The allowed argument names (mandatory AND optional).
* @param array $defaults Default values for optional arguments.
*
* @return array The reshaped arguments.
*
* @since 4.2.0
*/
protected function reshapeArguments(array $arguments, array $argumentNames, array $defaults = [])
{
$reconstructed = [];
// Check when the source is non-associative, example [$context, $item, $isNew, $data]
if (key($arguments) === 0) {
foreach ($argumentNames as $i => $name) {
$reconstructed[$name] = $arguments[$i] ?? $defaults[$name] ?? null;
}
// Return the reconstructed arguments array
return $reconstructed;
}
// Reconstruct the arguments in the order specified in $argumentNames
foreach ($argumentNames as $key) {
$reconstructed[$key] = $arguments[$key] ?? $defaults[$key] ?? null;
}
// Return the reconstructed arguments array
return $reconstructed;
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| ActionLog | Folder | 0775 |
|
|
| Application | Folder | 0775 |
|
|
| Cache | Folder | 0775 |
|
|
| Captcha | Folder | 0775 |
|
|
| Checkin | Folder | 0775 |
|
|
| Contact | Folder | 0775 |
|
|
| Content | Folder | 0775 |
|
|
| CustomFields | Folder | 0775 |
|
|
| Editor | Folder | 0775 |
|
|
| Extension | Folder | 0775 |
|
|
| Finder | Folder | 0775 |
|
|
| Installer | Folder | 0775 |
|
|
| Folder | 0775 |
|
||
| Menu | Folder | 0775 |
|
|
| Model | Folder | 0775 |
|
|
| Module | Folder | 0775 |
|
|
| MultiFactor | Folder | 0775 |
|
|
| PageCache | Folder | 0775 |
|
|
| Plugin | Folder | 0775 |
|
|
| Privacy | Folder | 0775 |
|
|
| QuickIcon | Folder | 0775 |
|
|
| Result | Folder | 0775 |
|
|
| SampleData | Folder | 0775 |
|
|
| Table | Folder | 0775 |
|
|
| User | Folder | 0775 |
|
|
| View | Folder | 0775 |
|
|
| WebAsset | Folder | 0775 |
|
|
| Workflow | Folder | 0775 |
|
|
| AbstractEvent.php | File | 8.52 KB | 0664 |
|
| AbstractImmutableEvent.php | File | 2.66 KB | 0664 |
|
| AfterExtensionBootEvent.php | File | 1.2 KB | 0664 |
|
| BeforeExtensionBootEvent.php | File | 1.2 KB | 0664 |
|
| CoreEventAware.php | File | 12.84 KB | 0664 |
|
| ErrorEvent.php | File | 1.25 KB | 0664 |
|
| GenericEvent.php | File | 535 B | 0664 |
|
| ReshapeArgumentsAware.php | File | 3.96 KB | 0664 |
|