Returns event function to handling the command.

@param \Closure $action

@return \Closure
345201
protected static function getEvent(Closure $action)
    {
        return function (Update $update) use ($action) {
            $message = $update->getMessage();
            if (!$message) {
                return true;
            }

            preg_match(self::REGEXP, $message->getText(), $matches);

            if (isset($matches[3]) && !empty($matches[3])) {
                $parameters = str_getcsv($matches[3], chr(32));
            } else {
                $parameters = [];
            }

            array_unshift($parameters, $message);

            $action = new ReflectionFunction($action);

            if (count($parameters) >= $action->getNumberOfRequiredParameters()) {
                $action->invokeArgs($parameters);
            }

            return false;
        };
    }
566985
public function invokeMethod($action, array $vars = array()) {
        Factory::timer()->record('controller start');
		$this->action = $action;
		if (!$this->hasMethod($action)) {
			return $this->throwErrorMethod($action);
		}
		if (true !==
            ($arg = $this->canInvoke($action))) {
			return $arg;
		}
		if (array_key_exists($action, $this->actions())) {
			return $this->runClassMethod($action);
		}
		$this->prepare();
		$result = $this->runActionMethod($this->getActionName($action), $vars);
		$this->finalize();
        Factory::timer()->record('controller end');
		return $result;
	}
1242067
public function callAction($action, $defaultAction = 'request') {
		if (method_exists($this, $action)) return $this->{$action}();
		else return $this->{$defaultAction}();
	}
798759
public function actions($actions)
    {
        if ($actions instanceof Closure) {
            $this->actionsCallback = $actions;
        }

        if (is_string($actions) && is_subclass_of($actions, Displayers\Actions::class)) {
            $this->actionsClass = $actions;
        }

        return $this;
    }
642968
private function triggerAction($action): Response
    {
        if (is_callable($action)) {
            return $this->returnResponse(
                $this->container->call($action)
            );
        } elseif (is_array($action)) {
            return $this->returnResponse(
                $this->container->call(
                    [
                        $action['controller'],
                        $action['method'],
                    ],
                    $action['arguments']
                )
            );
        }

        throw new \InvalidArgumentException('Route\'s action could not be handled.');
    }
1247881
private function executeAction(string $action)
    {
        list($controller, $method) = explode('@', $action);

        $class = '\App\Controllers\\'.ucfirst($controller).'Controller';

        if (!class_exists($class)) {
            throw new ExceptionHandler('Class "'.$class.'" not found.');
        }

        $controllerInstantiate = new $class();

        if (!method_exists($controllerInstantiate, $method)) {
            throw new ExceptionHandler('Method "'.$method.'" not found in '.$class.'.');
        }

        return call_user_func_array([new $controllerInstantiate, $method], []);
    }
300949
public function action(string $action, string $controller)
    {
        $this->options['actions'][strtolower($action)] = $controller;

        return $this;
    }
402077
public function setAction($name, Closure $action) {
    if (!array_key_exists($name, $this->actions)) {
      throw new \InvalidArgumentException($name.' ist keine bekannte action: '.implode(',',array_keys($this->actions)));
    }
    
    $this->actions[$name] = $action;
    return $this;
  }
821589
public function setAction($action)
    {
        foreach ($this->routes as $route)
            $route->setAction($action);
        return $this;
    }
1202662
public function Link($action = '')
    {
        $link = Controller::join_links(
            Director::baseURL(),
            Config::inst()->get('DocumentationViewer', 'link_base'),
            $this->getLanguage(),
            $action,
            '/'
        );

        return $link;
    }
105141
protected function handleAction($request, $action)
    {
        foreach ($request->latestParams() as $k => $v) {
            if ($v || !isset($this->urlParams[$k])) {
                $this->urlParams[$k] = $v;
            }
        }

        $this->action = $action;
        $this->requestParams = $request->requestVars();

        if ($this->hasMethod($action)) {
            $result = parent::handleAction($request, $action);

            // If the action returns an array, customise with it before rendering the template.
            if (is_array($result)) {
                return $this->getViewer($action)->process($this->customise($result));
            } else {
                return $result;
            }
        }

        // Fall back to index action with before/after handlers
        $beforeResult = $this->extend('beforeCallActionHandler', $request, $action);
        if ($beforeResult) {
            return reset($beforeResult);
        }

        $result = $this->getViewer($action)->process($this);

        $afterResult = $this->extend('afterCallActionHandler', $request, $action, $result);
        if ($afterResult) {
            return reset($afterResult);
        }

        return $result;
    }
1038604
public function setAction($action)
    {
        $context = $this->_context;

        $context->action = lcfirst(Text::camelize($action));

        return $this;
    }
1306666
private function handleEditAllAction(EnvironmentInterface $environment, Action $action)
    {
        $this->clearClipboard($environment);
        $this->handleGlobalCommands($environment);
        $this->handleSessionOverrideEditAll(
            $this->getModelIds($environment, $action, $this->getSubmitAction($environment)),
            'properties',
            $environment
        );

        return  $this->callAction($environment, 'editAll', ['mode' => 'edit']);
    }
416390
private function getControllerActionAnnotations($controller, $action)
    {
        if ($controller instanceof \Closure) {
            return $this->annotation->readFunction($controller);
        }

        return $this->annotation->readMethod($controller, $action . 'Action');
    }
1118354
function customHTTPAction( $http, $action )
    {
        $eventType = $this->eventType();
        $eventType->customWorkflowEventHTTPAction( $http, $action, $this );
    }
159769
protected function _event($action, $data = [])
    {
        $_event = new Event('Controller.PostTypes.' . $this->type['name'] . '.' . $action, $this, $data);
        $this->eventManager()->dispatch($_event);
    }
325454
public function dispatchAction($action = false)
    {
        $action = Dispatcher::formatActionName($action);
        return $this->callAction($action);
    }