Allows to set listeners with standard Yii configuration system

@param array[] $listeners
@return $this
@throws InvalidConfigException
11419
public function setListeners(array $listeners = [])
    {
        foreach ($listeners as $listener) {
            if (!isset($listener['event']) || !isset($listener['listener'])) {
                throw new InvalidConfigException('Both "event" and "listener" properties are required to attach a listener.');
            }

            if (is_string($listener['listener'])) {
                $listener['listener'] = $this->listenerFromClassName($listener['listener']);
            }

            $this->addListener($listener['event'], $listener['listener'], $listener['priority'] ?? self::P_NORMAL);
        }

        return $this;
    }
1097194
protected static function loadListeners() {
		
		// default var
		$configDir = Config::getOption("configDir");
		
		// make sure the listener data exists
		if (file_exists($configDir."/listeners.json")) {
			
			// get listener list data
			$listenerList = json_decode(file_get_contents($configDir."/listeners.json"), true);
			
			// get the listener info
			foreach ($listenerList["listeners"] as $listenerName) {
				
				if ($listenerName[0] != "_") {
					$listener  = new $listenerName();
					$listeners = $listener->getListeners();
					foreach ($listeners as $event => $eventProps) {
						$eventPriority = (isset($eventProps["priority"])) ? $eventProps["priority"] : 0;
						self::$instance->addListener($event, array($listener, $eventProps["callable"]), $eventPriority);
					}
				}
				
			}
			
		}
		
	}
547294
public function registerListeners(DispatcherContract $events)
    {
        foreach ($this->listen as $event => $listeners) {
            foreach ($listeners as $listener) {
                $events->listen($event, $listener);
            }
        }
    }
1264412
protected function configureHandlers(array $handlers)
    {
        foreach ($handlers as $handlerId => $handlerOptions) {
            $handlerLoader = new HandlerLoader($handlerOptions, $this->formatters, $this->processors, $this->handlers);
            $this->handlers[$handlerId] = $handlerLoader->load();
        }
    }
394470
public function setButtons(array $buttons): self
    {
        $this->isValidArray($buttons, 1);

        $this->buttons = $buttons;

        return $this;
    }
456361
public function run(ProcessListener $listener, array $data)
    {
        try {
            if (empty($data)) {
                throw new Exception\InvalidArgumentException('Invalid method arguments.');
            }
            $validator = null;
            $values    = null;
            if (isset($data['cid'])) {
                $model     = MemoryTests::findOrNew($data['cid']);
                $params    = unserialize($model->value);
                $validator = new $params['validator'];
                $values    = !empty($params['controls']) ? $params['controls'] : array_get($params, 'data');
            }
            if (isset($data['validator'])) {
                $validator = new $data['validator'];
                $values    = $data;
            }
            $response = $validator($values)->getResponse();
            $return   = view('antares/tester::admin.partials._messages')->with(['response' => $response]);
        } catch (\Exception $e) {
            Log::emergency($e);
            $return = view('antares/tester::admin.partials._error')->with(['message' => $e->getMessage(), 'code' => $e->getCode()]);
        }

        return $listener->render($return);
    }
402905
public function update(SettingUpdateListener $listener, array $input)
    {
        $input = new Fluent($input);
        $driver = $this->getValue($input['email_driver'], 'mail.driver');

        $validation = $this->validator->on($driver)->with($input->toArray());

        if ($validation->fails()) {
            return $listener->settingFailedValidation($validation->getMessageBag());
        }

        $memory = $this->memory;

        $memory->put('site.name', $input['site_name']);
        $memory->put('site.description', $input['site_description']);
        $memory->put('site.registrable', ($input['site_registrable'] === 'yes'));
        $memory->put('email.driver', $driver);

        $memory->put('email.from', [
            'address' => $this->getValue($input['email_address'], 'mail.from.address'),
            'name' => $input['site_name'],
        ]);

        if ((empty($input['email_password']) && $input['enable_change_password'] === 'no')) {
            $input['email_password'] = $memory->secureGet('email.password');
        }

        if ((empty($input['email_secret']) && $input['enable_change_secret'] === 'no')) {
            $input['email_secret'] = $memory->secureGet('email.secret');
        }

        $memory->put('email.host', $this->getValue($input['email_host'], 'mail.host'));
        $memory->put('email.port', $this->getValue($input['email_port'], 'mail.port'));
        $memory->put('email.username', $this->getValue($input['email_username'], 'mail.username'));
        $memory->securePut('email.password', $this->getValue($input['email_password'], 'mail.password'));
        $memory->put('email.encryption', $this->getValue($input['email_encryption'], 'mail.encryption'));
        $memory->put('email.sendmail', $this->getValue($input['email_sendmail'], 'mail.sendmail'));
        $memory->put('email.queue', ($input['email_queue'] === 'yes'));
        $memory->securePut('email.key', $this->getValue($input['email_key'], "services.{$driver}.key"));
        $memory->securePut('email.secret', $this->getValue($input['email_secret'], "services.{$driver}.secret"));
        $memory->put('email.domain', $this->getValue($input['email_domain'], "services.{$driver}.domain"));
        $memory->put('email.region', $this->getValue($input['email_region'], "services.{$driver}.region"));

        Event::dispatch('orchestra.saved: settings', [$memory, $input]);

        return $listener->settingHasUpdated();
    }
791970
public function unregister(ListenerInterface $listener)
    {
        if (!isset($this->storage[$listener])) {
            throw new InvalidArgumentException('Listener is not registered.');
        }

        foreach ($this->storage[$listener] as $event => $EElistener) {
            $listener->removeListener($event, $EElistener);
        }

        $this->storage->detach($listener);

        return $this;
    }
867087
public function use_hook_listener( HookListenerInterface $listener ) {

		add_action(
			HookListenersRegistry::ACTION_REGISTER,
			function ( HookListenersRegistry $registry ) use ( $listener ) {

				$registry->register_listener( $listener );
			}
		);

		return $this;
	}
864866
public static function addListener($name, $listener)
    {
        if (!isset(static::$listeners[$name])) {
            static::$listeners[$name] = [];
        }
        if(!is_array($listener)){
            static::$listeners[$name][] = $listener;
        }else{
            static::$listeners[$name] = array_merge(static::$listeners[$name], $listener);
        }

    }
1225528
public function listen($events, $listener, $priority = 10, $acceptedArgs = 1)
    {
        foreach ((array) $events as $filter) {
            $this->listeners[$filter][] = $listener;

            unset($this->sorted[$filter]);

            if ( ! isset($this->registeredWpFilters[$filter])) {
                $this->registeredWpFilters[$filter] = true;

                add_filter(
                    $filter,
                    function () use ($filter) {
                        return $this->dispatch($filter, func_get_args());
                    },
                    $priority,
                    $acceptedArgs
                );
            }
        }
    }
114235
public function register_listener( HookListenerInterface $listener ) {

		$id = (string) $listener->id();

		array_key_exists( $id, $this->listeners ) or $this->listeners[ $id ] = $listener;

		return $this;
	}
110334
public function setWidgets(array $widgets)
    {
        foreach ($widgets as $widgetIdent => $widgetStruct) {
            if (!is_array($widgetStruct)) {
                throw new InvalidArgumentException(sprintf(
                    'The attachment widget "%s" must be an array of widget settings',
                    $widgetIdent
                ));
            }

            if (isset($widgetStruct['ident'])) {
                $widgetIdent = $widgetStruct['ident'];
                unset($widgetStruct['ident']);
            }

            if (!is_string($widgetIdent)) {
                throw new InvalidArgumentException(
                    'The attachment widget identifier must be a string'
                );
            }

            $this->widgets[$widgetIdent] = $widgetStruct;
        }

        return $this;
    }
1108738
public function on(string $event, $listener)
    {
        if (empty($this->_events[$event])) {

            $this->_events[$event] = [$listener];
        }
        else {

            $this->_events[$event][] = $listener;
        }

        return $this;
    }
332800
public function setButtons(array $buttons)
    {
        collect($buttons)->map(function ($button) {
            $this->setButton($button);
        });

        return $this;
    }
581323
public function attach(EventManagerInterface $events)
    {
        $options                     = $this->getOptions();
        $configListener              = $this->getConfigListener();

        // High priority, we assume module autoloading (for FooNamespace\Module classes) should be available before anything else
        $this->listeners[] = $events->attach(new ModuleLoaderListener($options));
        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener());
        // High priority, because most other loadModule listeners will assume the module's classes are available via autoloading
        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new AutoloaderListener($options), 9000);

        if ($options->getCheckDependencies()) {
            $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new ModuleDependencyCheckerListener(), 8000);
        }

        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, new InitTrigger($options));
        $this->listeners[] = $events->attach($configListener);

        // This process can be expensive and affect perf if enabled. So we have
        // the flexibility to skip it.
        //if ($options->routingEnabled) {
        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, array($this, 'routesTrigger'), 3000);
        //}

        // @todo - this could be moved to a ZF event, so no need to make this ourselves.
        $this->listeners[] = $events->attach(ModuleEvent::EVENT_LOAD_MODULE, array($this, 'getServicesTrigger'), 3000);

        return $this;
    }
442638
public function init()
	{
		parent::init();

		if (empty($this->statusAttribute)) {
			throw new InvalidConfigException('The "statusAttribute" configuration for the Behavior is required.');
		}

		// init source
		
		if (empty($this->source)) {
			throw new InvalidConfigException('The "source" configuration for the Behavior can\'t be empty.');
		} elseif (  ! Yii::$app->has($this->source)) {
			Yii::$app->set($this->source, ['class'=> self::DEFAULT_SOURCE_CLASS]);
		}
		$this->_wfSource = Yii::$app->get($this->source);

		// init Event Sequence
		
		if ( $this->eventSequence == null) {
			$this->_eventSequence = null;
		} elseif ( is_string($this->eventSequence)) {
			if (  ! Yii::$app->has($this->eventSequence)) {
				Yii::$app->set($this->eventSequence, ['class'=> self::DEFAULT_EVENT_SEQUENCE_CLASS]);
			}
			$this->_eventSequence = Yii::$app->get($this->eventSequence);
		} else {
			throw new InvalidConfigException('Invalid "eventSequence" value.');
		}
	}