Proxy all Joomla events

@param   array  &$args  Arguments
@return  mixed  Routine return value
506072
protected function _proxyEvent($event, $args = array())
    {
        //Publish the event
        if (class_exists('Koowa')) {
            KObjectManager::getInstance()->getObject('event.publisher')->publishEvent($event, $args, JFactory::getApplication());
        }
    }
330308
protected function prepareEvent($command, array $args)
    {
        if (is_null($this->eventDispatcher)) {
            return null;
        }

        $event = new CassandraEvent();
        $event->setCommand($command)
              ->setKeyspace($this->getKeyspace())
              ->setArguments($args)
              ->setExecutionStart();

        return $event;
    }
1152755
public function forcemergeAll($args = [])
    {
        $endpoint = new ForceMerge();
        $endpoint->setParams($args);

        return $this->requestEndpoint($endpoint);
    }
437001
public static function dispatch(string $event, array $args = [], bool $return = false)
    {
        // is there some registered $listeners ?
        if (isset(Event::$listeners[$event]) && count(Event::$listeners[$event]) > 0) {

            // Get all listeners for given event.
            $listeners = Event::$listeners[$event];

            // Sort by priority
            krsort($listeners);

            // Loop through $listeners array
            foreach ($listeners as $listener) {

                // Loop through $_listener array
                foreach ($listener as $_listener) {

                    // Return or Render specific $_listener results ?
                    if ($return) {
                        return call_user_func_array($_listener['function'], (isset($args) ? $args : $_listener['args']));
                    } else {
                        call_user_func_array($_listener['function'], (isset($args) ? $args : $_listener['args']));
                    }
                }
            }
        }
    }
945496
public function main(array $args = array()) {
        $publicMethods = $this->getPublicMethods();
        if (!array_key_exists(0, $args)) {
            if (in_array('help', $publicMethods)) {
                $args[0] = 'help';
            } else {
                Garp_Cli::errorOut(
                    "No method selected. Available methods: \n " .
                    implode("\n ", $publicMethods)
                );
                return false;
            }
        }

        $methodName = $args[0];
        if (!in_array($methodName, $publicMethods)) {
            Garp_Cli::errorOut('Unknown command \'' . $methodName . '\'');
            return false;
        }
        unset($args[0]);
        $args = $this->_remapArguments($args);
        if (!$this->_validateArguments($methodName, $args)) {
            // Note, _validateArguments also provides the CLI feedback
            return false;
        }
        $result = call_user_func_array(array($this, $methodName), array($args));
        return $result;
    }
639320
public function run(array $args)
    {
        $command = 'help';

        if(isset($args[1])) {
            $command = $args[1];
        }

        //cradle author/vendor action
        if(strpos($command, '/') !== false) {
            $command = 'package';
            array_splice($args, 1, 0, array($command));
        }

        $class = '\\Cradle\\CommandLine\\'.ucwords($command);

        if(!class_exists($class)) {
            //by default it's an event
            $class = '\\Cradle\\CommandLine\\Event';
            array_splice($args, 1, 0, array('event'));
        }

        array_shift($args);
        $runner = new $class($this->cwd);

        $results = $runner->run($args);

        print PHP_EOL;

        return $results;
    }
1147960
public function run(array $args)
    {
        $command = 'help';

        if (isset($args[1])) {
            $command = $args[1];
        }

        //cradle author/vendor action
        if (strpos($command, '/') !== false) {
            $command = 'package';
            array_splice($args, 1, 0, array($command));
        }

        //if command is package
        if ($command === 'package'
            && (//and no package was defined
                !isset($args[2])
                || strpos($args[2], '/') === false
            )
        ) {
            $command = 'event';
            array_splice($args, 1, 0, ['event']);
        }

        $class = sprintf(self::COMMAND_CLASS, ucwords($command));

        if (!class_exists($class)) {
            //by default it's an event
            $class = sprintf(self::COMMAND_CLASS, 'Event');
            array_splice($args, 1, 0, array('event'));
        }

        array_shift($args);
        $runner = new $class($this->cwd);

        $results = $runner->run($args);

        self::output(PHP_EOL);

        return $results;
    }
402476
public function trigger($event, $args = null)
    {
        if ($args === null) {
            $args = [];
        }

        settype($args, 'array');

        $prefix = XTAINJoomlaBundle::STOPWATCH_PREFIX;
        $eventUnderscore = Inflector::tableize($event);

        $beforeEvent = new BeforeEvent($args);
        self::$eventDispatcher->dispatch(self::PREFIX_BEFORE . $eventUnderscore, $beforeEvent);

        if (self::$stopwatch !== null) {
            self::$stopwatch->start($prefix . '.event.' . $eventUnderscore);
        }

        $return = parent::trigger($event, $beforeEvent->getArguments());

        if (self::$stopwatch !== null) {
            self::$stopwatch->stop($prefix . '.event.' . $eventUnderscore);
        }

        $afterEvent = new AfterEvent($args, $return);
        self::$eventDispatcher->dispatch(self::PREFIX_AFTER . $eventUnderscore, $afterEvent);

        return $afterEvent->getResult();
    }
1147922
private function dispatchEvent($event, $args = null)
    {
        return $this->onEventEmitterEnabled(function ($emitter) use($event, $args) {
            return $emitter->emit($event, ! is_array($args) ? [$args] : $args);
        });
    }
814787
public function generateProcessProxy($arguments = array())
    {
        if (!$this->isProxyLoaded()) {
            $this->loadProxyClass();
        }

        $reflect = new ReflectionClass($this->proxyClass);

        return $reflect->newInstanceArgs($arguments);
    }
287901
public function invokeCallbacks($event, $arg)
    {
        $this->checkEventType($event);
        foreach ($this->events[$event] as $callback) {
            call_user_func($callback, $arg);
        }
    }
888566
protected function callback($args) {
		$checkReg = '/[^a-zA-Z0-9;._-]/';
		$node = (isset($args['node']) && !preg_match($checkReg, $args['node']))? $args['node'] : '';
		$json = (isset($args['json']) && @json_decode($args['json']))? $args['json'] : '{}';
		$bind  = (isset($args['bind']) && !preg_match($checkReg, $args['bind']))? $args['bind'] : '';
		$done = (!empty($args['done']));
		
		while( ob_get_level() ) {
			if (! ob_end_clean()) {
				break;
			}
		}
		
		if ($done || ! $this->callbackWindowURL) {
			$script = '';
			if ($node) {
				$script .= '
					var w = window.opener || weindow.parent || window
					var elf = w.document.getElementById(\''.$node.'\').elfinder;
					if (elf) {
						var data = '.$json.';
						data.warning && elf.error(data.warning);
						data.removed && data.removed.length && elf.remove(data);
						data.added   && data.added.length   && elf.add(data);
						data.changed && data.changed.length && elf.change(data);';
				if ($bind) {
					$script .= '
						elf.trigger(\''.$bind.'\', data);';
				}
				$script .= '
						data.sync && elf.sync();
					}';
			}
			$script .= 'window.close();';
			
			$out = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script>'.$script.'</script></head><body><a href="#" onlick="window.close();return false;">Close this window</a></body></html>';
			
			header('Content-Type: text/html; charset=utf-8');
			header('Content-Length: '.strlen($out));
			header('Cache-Control: private');
			header('Pragma: no-cache');
			
			echo $out;
			
		} else {
			$url = $this->callbackWindowURL;
			$url .= ((strpos($url, '?') === false)? '?' : '&')
				 . '&node=' . rawurlencode($node)
				 . (($json !== '{}')? ('&json=' . rawurlencode($json)) : '')
				 . ($bind? ('&bind=' .  rawurlencode($bind)) : '')
				 . '&done=1';
			
			header('Location: ' . $url);
			
		}
		exit();
	}
761095
protected function callAllListeners($args = [])
    {
        $args = (array) $args;
        array_map(function ($event) use ($args) {
            $this->callListeners($event, $args);
        }, array_keys($this->listeners));
    }
284131
public function event($event, ...$args){
        if($this->eventManager !== null){
            return $this->eventManager->trigger($event, $args);
        }

        return false;
    }
85787
public function triggerEvent($event, $args = [])
    {
        if (!($event instanceof EventInterface)) {
            if (isset($this->events[$event])) {
                $event = $this->events[$event];
            } else {
                $event = new Event($event);
            }
        }

        $event->mergeArguments($args);

        if (isset($this->listeners[$event->getName()])) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                if ($event->isStopped()) {
                    return $event;
                }

                if (is_callable($listener)) {
                    call_user_func($listener, $event);
                } else {
                    call_user_func([$listener, $event->getName()], $event);
                }
            }
        }

        return $event;
    }
909819
public static function fireEvent($event, $args = array(), $resultAsString = false)
    {
        $results = array();
        
        if (isset(self::$events[$event])) {
            $keys = array_keys(self::$events[$event]); 
            sort($keys);
            foreach ($keys as $key) {
                $callback = self::$events[$event][$key];
                $results[$key] = call_user_func_array($callback, $args);
            }
        }
        
        if ($resultAsString) {
            return implode('', $results);
        }
        return $results;
    }
667618
public function trigger($event, $args = array())
	{
		if (!($event instanceof Event))
		{
			if (isset($this->events[$event]))
			{
				$event = $this->events[$event];
			}
			else
			{
				$event = new Event($event);
			}
		}

		// If a listener group was specified
		// lazy load the listeners.
		if ($group = $event->getGroup())
		{
			$this->addListeners($group);
		}

		// Attach any incoming aruments
		foreach ((array) $args as $name => $arg)
		{
			$event->addArgument($name, $arg);
		}

		// Are there any listeners for this event?
		if (isset($this->listeners[$event->getName()]))
		{
			foreach ($this->listeners[$event->getName()] as $listener)
			{
				// Call the event listener
				if ($listener instanceof Closure)
				{
					$response = call_user_func($listener, $event);
				}
				else
				{
					$response = call_user_func(array($listener, $event->getName()), $event);
				}

				// Attach response
				if (!is_null($response))
				{
					$event->addResponse($response);
				}

				// Is propagation stopped?
				if ($event->isStopped())
				{
					break;
				}
			}
		}

		return $event->getResponse();
	}