Trigger callback.

@param array|callable $callback  Callback to trigger.
@param array          $arguments Callback arguments.

@return mixed
175388
private function triggerCallback($callback, $arguments)
    {
        if (is_array($callback)) {
            $this->import($callback[0]);
            return call_user_func_array(array($this->{$callback[0]}, $callback[1]), $arguments);
        } elseif (is_callable($callback)) {
            return call_user_func_array($callback, $arguments);
        }

        return null;
    }
8638
public function setCallback(callable $callback, array $params = [])
    {
        if ($this->hasCallback()) {
            throw new ArchException('Callback already defined');
        }
        $this->callback = $callback;
        $this->callbackParams = $params;
        return $this;
    }
320982
public function triggerEvent($event, $args = [])
    {
        if (!is_string($event) && !$event instanceof Event) {
            throw new \InvalidArgumentException(sprintf(
                '%s::%s only allow Event object or string.',
                get_called_class(),
                __FUNCTION__
            ));
        }

        if (!($event instanceof Event)) {
            if (isset($this->events[$event])) {
                $event = $this->events[$event];
            } else {
                $event = new Event($event);
            }
        }

        $event->mergeArguments($args);

        $listeners = [];

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

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

                if (!is_callable($listener)) {
                    continue;
                }

                $listener($event);

                if ($this->debug) {
                    $listeners[] = $listener;
                }
            }
        }

        if ($this->debug) {
            $executedListeners = [];

            foreach ($listeners as $listener) {
                if ($listener instanceof \Closure) {
                    $ref = new \ReflectionFunction($listener);

                    $listener = ['{Closure}: ' . $ref->getFileName() . ' - Line: ' . $ref->getStartLine()];
                }

                if (is_object($listener[0])) {
                    $listener[0] = get_class($listener[0]);
                }

                $executedListeners[] = $listener;
            }

            $this->collector[] = [
                'event' => $event->getName(),
                'listeners' => $executedListeners,
            ];
        }

        return $event;
    }
322590
public function call($callback, array $parameters = array())
    {
        $this->events[] = $event = new CallbackEvent($this->mutex, $callback, $parameters);

        return $event;
    }
1089063
public function bindCallback($callback, $argument = null) {
        if ($callback instanceof Closure) {
            call_user_func_array($callback, [$this, $argument]);
        }

        return $this;
    }
493828
public function handle(callable $callBack = null)
    {
        $ip = $this->getIpAddress();

        $isAllowed = $this->listMerger->isAllowed($ip, $this->defaultState);

        if ($callBack !== null) {
            return call_user_func($callBack, array($this, $isAllowed));
        } else {
            return $isAllowed;
        }
    }
818229
private function executeMethod(array $arguments)
    {
        if ($this->reflection->isStatic()) {
            return $this->reflection->invokeArgs(null, $arguments);
        } elseif (is_object($this->callback[0])) {
            return $this->reflection->invokeArgs($this->callback[0], $arguments);
        }
        $instance = new $this->callback[0]();
        return $this->reflection->invokeArgs($instance, $arguments);
    }
503934
protected function getCallback($callback, array $parameters)
    {
        if ($callback instanceof Closure) {
            return $this->createCallableCallback($callback, $parameters);
        } elseif (is_string($callback)) {
            return $this->createStringCallback($callback, $parameters);
        } else {
            return;
        }
    }
183041
public function trigger(EventInterface $event, \Closure $callback = null)
    {
        if ($listeners = $this->getListeners($event->getName())) {
            foreach ($listeners as $listener) {
                if ($result = call_user_func($listener, $event)) {
                    if ($result instanceof EventInterface) {
                        // Was the queue halted early ?
                        if ($result->isQueueHaltedEarly()) {
                            return $this;
                        }

                        if ($callback !== null) {
                            call_user_func($callback, $result);
                        }

                        // Was the queue halted ?
                        if ($result->isQueueHalted()) {
                            return $this;
                        }
                    } else {
                        throw new \RuntimeException(
                            'Value returned from an Event Callback must be of type Proem\Signal\EventInterface'
                        );
                    }
                }
            }
        }

        return $this;
    }
47576
public static function callArgs($callback, array $args = [])
    {
        try {
            $callback = static::evaluateCallback($callback);

            return \call_user_func_array($callback, $args);
        } catch (\Exception $e) {
            $message = $e->getMessage();
        }

        if (\is_array($callback) && \is_object($callback[0])) {
            $callback[0] = \get_class($callback[0]);
        }

        throw new DcGeneralRuntimeException(
            \sprintf(
                'Execute callback %s failed - Exception message: %s',
                (\is_array($callback)
                    ? \implode('::', $callback)
                    : (\is_string($callback)
                        ? $callback
                        : \get_class(
                            $callback
                        ))),
                $message
            ),
            0,
            $e
        );
    }
580643
public function setCallback($callback)
    {
        if (!$callback instanceof Closure) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid parameter for callback: must be %s',
                Closure::class
            ));
        }

        return parent::setCallback($callback);
    }
785165
protected static function runCallback($callback, $args)
    {
        if (!is_array($args)) {
            $args = isset($args) ? array($args) : array();
        }
        return call_user_func_array($callback, $args);
    }
1115036
public static function trigger($name, array $args = array())
    {
        if ($name === 'error') {
            self::$state = 5;
        }

        if (empty(self::$events[$name])) {
            return null;
        }

        $listen = self::$events[$name];

        usort($listen, function ($a, $b) {
            return $b[1] >= $a[1];
        });

        foreach ($listen as $callback) {
            call_user_func_array($callback[0], $args);
        }

        $listen = null;
    }
76262
protected function createStringCallback($callback, array $parameters)
    {
        if (function_exists($callback)) {
            return $this->createCallableCallback($callback, $parameters);
        } else {
            return $this->createClassesCallback($callback, $parameters);
        }
    }
131552
public function on($names, $callback)
    {
        if (! is_array($names)) {
            $names = [$names];
        }

        $callable = $this->getCallable($callback);

        foreach ($names as $name) {
            $this->events[] = [
                'name' => $name,
                'callback' => $callable,
            ];
        }
    }
677014
public static function create($name, callable $callback, ...$arguments) {

        try {

            return  new RpcMethod($name, $callback, ...$arguments);

        } catch (Exception $e) {

            throw $e;

        }

    }
953948
protected function _bind(array $callback) {
		if (true === empty($callback)) {
			return false;
		}
		array_map(function ($cb) {
			parent::on($cb['event'], $cb['callback']);
		}, $callback);
	}