<?php

namespace Application\Service\Extension\Event;

use Application\Service\Extension\BaseExtension;
use Application\Service\Extension\Laminas;

class Event extends BaseExtension
{
    /**
     * @return Event
     */
    public static function app(): Event
    {
        return parent::app(); // TODO: Change the autogenerated stub
    }

    public function attach(string $eventName, $callback, int $priority = 0)
    {
        if (is_callable($callback)) {
            Laminas::$app->getEventManager()->attach($eventName, $callback, $priority);
        } else if (is_array($callback)) {
            Laminas::$app->getEventManager()->attach($eventName, function () use ($callback) {
                call_user_func(...$callback);
            }, $priority);
        }
    }

    public function trigger(string $eventName, $target = null, $params = null): \Laminas\EventManager\ResponseCollection
    {
        return Laminas::$app->getEventManager()->trigger($eventName, $target, $params);
    }
}