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/magento/framework/Event/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/framework/Event/Collection.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * Collection of events
 *
 * @author      Magento Core Team <[email protected]>
 */
namespace Magento\Framework\Event;

use Magento\Framework\Event;

class Collection
{
    /**
     * Array of events in the collection
     *
     * @var array
     */
    protected $events;

    /**
     * Global observers
     *
     * For example regex observers will watch all events that
     *
     * @var Observer\Collection
     */
    protected $globalObservers;

    /**
     * Initializes global observers collection
     *
     * @param array $events
     * @param Observer\Collection $observerCollection
     */
    public function __construct(array $events = [], Observer\Collection $observerCollection = null)
    {
        $this->events = $events;
        $this->globalObservers = !$observerCollection ? new Observer\Collection() : $observerCollection;
    }

    /**
     * Returns all registered events in collection
     *
     * @return array
     */
    public function getAllEvents()
    {
        return $this->events;
    }

    /**
     * Returns all registered global observers for the collection of events
     *
     * @return Observer\Collection
     */
    public function getGlobalObservers()
    {
        return $this->globalObservers;
    }

    /**
     * Returns event by its name
     *
     * If event doesn't exist creates new one and returns it
     *
     * @param string $eventName
     * @return Event
     */
    public function getEventByName($eventName)
    {
        if (!isset($this->events[$eventName])) {
            $this->addEvent(new Event(['name' => $eventName]));
        }
        return $this->events[$eventName];
    }

    /**
     * Register an event for this collection
     *
     * @param Event $event
     * @return $this
     */
    public function addEvent(Event $event)
    {
        $this->events[$event->getName()] = $event;
        return $this;
    }

    /**
     * Register an observer
     *
     * If observer has event_name property it will be registered for this specific event.
     * If not it will be registered as global observer
     *
     * @param Observer $observer
     * @return $this
     */
    public function addObserver(Observer $observer)
    {
        $eventName = $observer->getEventName();
        if ($eventName) {
            $this->getEventByName($eventName)->addObserver($observer);
        } else {
            $this->getGlobalObservers()->addObserver($observer);
        }
        return $this;
    }

    /**
     * Dispatch event name with optional data
     *
     * Will dispatch specific event and will try all global observers
     *
     * @param string $eventName
     * @param array $data
     * @return $this
     */
    public function dispatch($eventName, array $data = [])
    {
        $event = $this->getEventByName($eventName);
        $event->addData($data)->dispatch();
        $this->getGlobalObservers()->dispatch($event);
        return $this;
    }
}

Spamworldpro Mini