Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/captainhook/captainhook/src/Event/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/captainhook/captainhook/src/Event/Dispatcher.php
<?php

/**
 * This file is part of CaptainHook.
 *
 * (c) Sebastian Feldmann <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CaptainHook\App\Event;

use CaptainHook\App\Config;
use CaptainHook\App\Console\IO;
use SebastianFeldmann\Git\Repository;

/**
 * Event Dispatcher
 *
 * This allows the user to hook into the Cap'n on a deeper level. For example execute code if the hook execution fails.
 *
 * @package CaptainHook
 * @author  Sebastian Feldmann <[email protected]>
 * @link    https://github.com/captainhookphp/captainhook
 * @since   Class available since Release 5.11.0
 */
class Dispatcher
{
    /**
     * List of all registered handlers
     *
     * @var array<string, array<int, \CaptainHook\App\Event\Handler>>
     */
    private $config = [];

    /**
     * Event factory to create all necessary events
     *
     * @var \CaptainHook\App\Event\Factory
     */
    private $factory;

    /**
     * Event Dispatcher
     *
     * @param \CaptainHook\App\Console\IO       $io
     * @param \CaptainHook\App\Config           $config
     * @param \SebastianFeldmann\Git\Repository $repository
     */
    public function __construct(IO $io, Config $config, Repository $repository)
    {
        $this->factory = new Factory($io, $config, $repository);
    }

    /**
     * Register handlers received from a Listener to the dispatcher
     *
     * @param  array<string, array<int, \CaptainHook\App\Event\Handler>> $eventConfig
     * @return void
     */
    public function subscribeHandlers(array $eventConfig): void
    {
        foreach ($eventConfig as $event => $handlers) {
            foreach ($handlers as $handler) {
                $this->subscribeHandlerToEvent($handler, $event);
            }
        }
    }

    /**
     * Register a single event handler to an event
     *
     * @param  \CaptainHook\App\Event\Handler $handler
     * @param  string                         $event
     * @return void
     */
    public function subscribeHandlerToEvent(Handler $handler, string $event): void
    {
        $this->config[$event][] = $handler;
    }

    /**
     * Trigger all event handlers registered for a given event
     *
     * @param  string $eventName
     * @throws \Exception
     * @return void
     */
    public function dispatch(string $eventName): void
    {
        $event = $this->factory->createEvent($eventName);

        foreach ($this->handlersFor($event->name()) as $handler) {
            $handler->handle($event);
        }
    }

    /**
     * Return a list of handlers for a given event
     *
     * @param  string $event
     * @return \CaptainHook\App\Event\Handler[];
     */
    private function handlersFor(string $event): array
    {
        return $this->config[$event] ?? [];
    }
}

Spamworldpro Mini