From 61423c20285d213e6ca426f4792ce3d7db792c80 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 25 Feb 2025 11:02:39 -0800 Subject: [PATCH] Use setData --- app/code/core/Mage/Core/Model/App.php | 35 +++++++++++++++++++++++++-- lib/Varien/Event.php | 35 +-------------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php index 586c37831..5f0acf105 100644 --- a/app/code/core/Mage/Core/Model/App.php +++ b/app/code/core/Mage/Core/Model/App.php @@ -1360,6 +1360,38 @@ public function addEventArea($area) } /** + * Dispatch event to observers + * + * Default arguments can be defined in `config.xml` using the `` node. These are merged with the $args parameter. + * + * For example, this defines `is_ajax=1` for the `controller_action_predispatch` event: + * ```xml + * + * + * + * + * + * Company_Name_Model_Observer + * process + * + * 1 + * + * + * + * + * + * + * ``` + * + * In the observer method, `Company_Name_Model_Observer->process()`, access the args with: + * ```php + * public function process(Varien_Event_Observer $observer): void + * { + * $isAjax = (bool) $observer->getIsAjax(); + * // ... + * } + * ``` + * * @param string $eventName * @param array $args * @return $this @@ -1400,8 +1432,7 @@ public function dispatchEvent($eventName, $args) } foreach ($events[$eventName]['observers'] as $obsName => $obs) { - $event->args = $obs['args']; - $observer->setData(['event' => $event]); + $observer->setData([...$obs['args'], 'event' => $event]); Varien_Profiler::start('OBSERVER: ' . $obsName); switch ($obs['type']) { case 'disabled': diff --git a/lib/Varien/Event.php b/lib/Varien/Event.php index c223055a3..c23929268 100644 --- a/lib/Varien/Event.php +++ b/lib/Varien/Event.php @@ -6,7 +6,7 @@ * @package Varien_Event * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) - * @copyright Copyright (c) 2024-2025 Maho (https://mahocommerce.com) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -24,39 +24,6 @@ class Varien_Event extends Varien_Object */ protected $_observers; - /** - * Array containing arguments from `config.xml`, or an empty array if the `` node is missing or empty. - * - * This example defines an arg `is_ajax=1` for the `controller_action_predispatch` event: - * ```xml - * - * - * - * - * - * Company_Name_Model_Observer - * process - * - * 1 - * - * - * - * - * - * - * ``` - * - * In the observer method, `Company_Name_Model_Observer->process()`, access the args with: - * ```php - * public function process(Varien_Event_Observer $observer): void - * { - * $isAjax = (bool) ($observer->getEvent()->args['is_ajax'] ?? null); - * // ... - * } - * ``` - */ - public array $args; - /** * Constructor *