mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
EventService: call FireEvent with only one parameter (PSR14)
This commit is contained in:
@@ -24,16 +24,15 @@ class EventData
|
||||
* EventServiceData constructor.
|
||||
*
|
||||
* @param string $sEvent
|
||||
* @param mixed $mEventSource
|
||||
* @param string|array|null $mEventSource
|
||||
* @param array $aEventData
|
||||
* @param array $aCallbackData
|
||||
*/
|
||||
public function __construct(string $sEvent, $mEventSource, array $aEventData, array $aCallbackData)
|
||||
public function __construct(string $sEvent, $mEventSource = null, array $aEventData = [])
|
||||
{
|
||||
$this->sEvent = $sEvent;
|
||||
$this->aEventData = $aEventData;
|
||||
$this->mEventSource = $mEventSource;
|
||||
$this->aCallbackData = $aCallbackData;
|
||||
$this->aCallbackData = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +73,15 @@ class EventData
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @param array|null $aCallbackData
|
||||
*/
|
||||
public function SetCallbackData(?array $aCallbackData)
|
||||
{
|
||||
$this->aCallbackData = $aCallbackData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function GetCallbackData(): array
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ class EventService
|
||||
* @param string $sEvent corresponding event
|
||||
* @param callable $callback The callback to call
|
||||
* @param array|string|null $sEventSource event filtering depending on the source of the event
|
||||
* @param array $aCallbackData optional data given by the registrar to the callback
|
||||
* @param array|null $aCallbackData optional data given by the registrar to the callback
|
||||
* @param array|string|null $context context filter
|
||||
* @param float $fPriority optional priority for callback order
|
||||
*
|
||||
@@ -33,7 +33,7 @@ class EventService
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function Register(string $sEvent, callable $callback, $sEventSource = null, array $aCallbackData = [], $context = null, float $fPriority = 0.0): string
|
||||
public static function Register(string $sEvent, callable $callback, $sEventSource = null, ?array $aCallbackData = [], $context = null, float $fPriority = 0.0): string
|
||||
{
|
||||
is_callable($callback, false, $sName);
|
||||
|
||||
@@ -78,8 +78,10 @@ class EventService
|
||||
*
|
||||
* @throws \Exception from the callback
|
||||
*/
|
||||
public static function FireEvent(string $sEvent, $eventSource = null, array $aEventData = array())
|
||||
public static function FireEvent(EventData $oEventData)
|
||||
{
|
||||
$sEvent = $oEventData->GetEvent();
|
||||
$eventSource = $oEventData->GetEventSource();
|
||||
$oKPI = new ExecutionKPI();
|
||||
$sSource = isset($aEventData['debug_info']) ? " {$aEventData['debug_info']}" : '';
|
||||
$sEventName = "$sEvent:".self::GetSourcesAsString($eventSource);
|
||||
@@ -102,7 +104,8 @@ class EventService
|
||||
IssueLog::Debug("Fire event '$sEventName'$sSource calling '{$sName}'", LOG_EVENT_SERVICE_CHANNEL);
|
||||
try {
|
||||
if (is_callable($aEventCallback['callback'])) {
|
||||
call_user_func($aEventCallback['callback'], new EventData($sEvent, $eventSource, $aEventData, $aEventCallback['data']));
|
||||
$oEventData->SetCallbackData($aEventCallback['data']);
|
||||
call_user_func($aEventCallback['callback'], $oEventData);
|
||||
} else {
|
||||
IssueLog::Debug("Callback '{$sName}' not a callable anymore, unregister", LOG_EVENT_SERVICE_CHANNEL);
|
||||
self::UnRegisterCallback($aEventCallback['id']);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
use Combodo\iTop\Service\EventData;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
@@ -52,7 +53,7 @@ class CLIPage implements Page
|
||||
{
|
||||
$aData['debug_info'] = 'from: '.get_class($this).":[$this->s_title]";
|
||||
$aData['object'] = $this;
|
||||
EventService::FireEvent(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData);
|
||||
EventService::FireEvent(new EventData(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData));
|
||||
}
|
||||
|
||||
public function add($sText)
|
||||
|
||||
@@ -17,6 +17,7 @@ use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
|
||||
use Combodo\iTop\Service\EventData;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
@@ -1354,7 +1355,7 @@ JS;
|
||||
{
|
||||
$aData['debug_info'] = 'from: '.get_class($this).":[$this->s_title]";
|
||||
$aData['object'] = $this;
|
||||
EventService::FireEvent(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData);
|
||||
EventService::FireEvent(new EventData(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user