Executes the action and outputs the result.

@param ActionContext $actionContext The context in which the result is executed.
The context information includes information about the action that was executed and request information.

@return void
8655
public function execute($actionContext) {
        // make json and exit
        if (($result = json_encode($this->data, $this->options, $this->depth)) === false) {
            throw new \ErrorException('JSON encode error #' . json_last_error() . ': ' . json_last_error_msg());
        }

        $response = $actionContext->getHttpContext()->getResponse();
        $response->addHeader('Content-Type', 'application/json');
        $response->write($result);
        $response->end();
    }
413294
public function run($context)
    {
        foreach ($this->actions as $step) {
            /** @var $step Action  **/
            codecept_debug("- $step");
            try {
                call_user_func_array([$context, $step->getAction()], $step->getArguments());
            } catch (\Exception $e) {
                $class = get_class($e); // rethrow exception for a specific action
                throw new $class($e->getMessage() . "\nat $step");
            }
        }
    }
1267401
protected function _actionEdit(ControllerContext $context)
    {
        $entities = $context->entity;

        if(count($entities))
        {
            foreach($entities as $entity) {
                $entity->setProperties($context->request->data->toArray());
            }

            //Only set the reset content status if the action explicitly succeeded
            if($entities->save() === true) {
                $context->response->setStatus(HttpResponse::RESET_CONTENT);
            }
        }
        else throw new ControllerExceptionResourceNotFound('Resource could not be found');

        return $entities;
    }
1199919
public void execute(JobExecutionContext context) throws JobExecutionException {

    JobDataMap dataMap = context.getJobDetail().getJobDataMap();
    OutputInvoker outputInvoker = (OutputInvoker)dataMap.get(OutputQuartzHelper.OUTPUT_JOB_NAME);

    if (outputInvoker != null) {
      // execute MP's output method
      outputInvoker.invokeOutput();
    } else {
      logger.warn("outputInvoker is NULL");
    }
  }
1060367
public function execute(Context $context)
    {
        if ($this->evaluate($context) && isset($this->action)) {
            if (!is_callable($this->action)) {
                throw new \LogicException('Rule actions must be callable.');
            }

            call_user_func($this->action);
        }
    }
700842
protected function _actionEdit(AnCommandContext $context)
    {
        $result = parent::_actionEdit($context);
        $this->registerCallback('after.edit', array($this, 'redirect'));
    }
8588
private static function makeActionState($actionContext) {
        $arguments = array();
        $modelState = new ModelState();
        $modelState->annotations = $actionContext->getModelState()->annotations;
        $hasModel = false;
        $request = $actionContext->getHttpContext()->getRequest();

        // route
        $route = $actionContext->getRoute();
        $segments = $route->getSegments(true);

        // params of get http
        // TODO: подумать о возможности управлять этим
        $get = $request->get();

        // change case of keys
        $get = array_change_key_case($get, CASE_LOWER);

        // post
        $isPost = $request->isPost();

        // get params of action method
        $r = new \ReflectionMethod(get_class($actionContext->getController()), $actionContext->getActionName());

        $methodParams = $r->getParameters();

        // search for the necessary parameters
        foreach ($methodParams as $param) {
            $name = strtolower($param->getName());

            if (isset($route->values[$name])) {
                $modelState[$name] = new ModelStateEntry($name, $arguments[$name] = $route->values[$name]);
            }
            elseif (isset($get[$name])) {
                $modelState[$name] = new ModelStateEntry($name, $arguments[$name] = $get[$name]);
            }
            else {
                // parameter not found
                if ($isPost && !$hasModel && !isset($get[$name]) && !isset($segments[$name])) {
                    $postData = $request->post();
                    $paramTypeName = '\stdClass';
                    $post = null;

                    if (isset($postData) && isset($postData['__requestVerificationToken'])) {
                        unset($postData['__requestVerificationToken']);
                    }

                    if (method_exists($param, 'hasType') && $param->hasType()) {
                        if ($param->getType()->isBuiltin()) {
                            $arguments[$name] = ($param->isOptional() ? $param->getDefaultValue() : null);
                            continue;
                        }

                        if (($paramTypeName = $param->getClass()) !== null) {
                            $paramTypeName = $paramTypeName->getName();
                        }
                    }
                    else {
                        if (($paramTypeName = $param->getClass()) !== null) {
                            $paramTypeName = $paramTypeName->getName();
                        }
                    }

                    if (!empty($postData)) {
                        InternalHelper::arrayToObject($postData, $post, $paramTypeName);
                    }
                    
                    if (empty($post)) {
                        $contentType = $request->contentType();
            
                        if (strrpos($contentType, '/json') !== false) {
                            $requestBody = file_get_contents('php://input');
                            InternalHelper::arrayToObject(json_decode($requestBody, true), $post, $paramTypeName);
                        }
                        else {
                            // TODO...
                        }
                    }

                    // post method and model not yet received
                    if ($post == null) {
                        throw new \Exception('"' . $name . ' is required.');
                    }

                    $arguments[$name] = $post;

                    // parse post data
                    self::parseObjectToModelState($modelState, $post);

                    $hasModel = true;
                    continue;
                }

                if ($param->isOptional()) {
                    // is optional parameter, skip it
                    $arguments[$name] = $param->getDefaultValue();
                    continue;  
                }

                // required parameter
                // TODO: config
                // throw new \ErrorException('"'.$name.'" is required.');
                // at the moment, just add null to args
                // and skip for model state
                $arguments[$name] = null;
            }
        }

        InternalHelper::setPropertyValue($actionContext, 'arguments', $arguments);
        InternalHelper::setPropertyValue($actionContext, 'modelState', $modelState);
    }
340592
public function run(MigrationContext $context)
	{
		$this->setContext($context);
		$this->createMigrationsTable();

		$all_migrations = $this->getAllMigrations();
		$executed_migrations = $this->getExecutedMigrations();

		$migrations_to_execute = array_diff($all_migrations, $executed_migrations);
		$this->executeMigrations($migrations_to_execute);

		$migrations_to_delete = array_diff($executed_migrations, $all_migrations);
		$this->deleteMigrations($migrations_to_delete);
	}
614091
protected function _actionAdd(ControllerContext $context)
    {
        $entity = $context->entity;

        //Only throw an error if the action explicitly failed.
        if($entity->save() === false)
        {
            $error = $entity->getStatusMessage();
            throw new ControllerExceptionActionFailed($error ? $error : 'Add Action Failed');
        }
        else
        {
            if ($entity instanceof ModelEntityInterface)
            {
                $url = clone $context->request->getUrl();

                if ($this->getModel()->getState()->isUnique())
                {
                    $states = $this->getModel()->getState()->getValues(true);

                    foreach ($states as $key => $value) {
                        $url->query[$key] = $entity->getProperty($key);
                    }
                }
                else $url->query[$entity->getIdentityKey()] = $entity->getProperty($entity->getIdentityKey());

                $context->response->headers->set('Location', (string) $url);
                $context->response->setStatus(HttpResponse::CREATED);
            }
        }

        return $entity;
    }
534934
public function startAction($actionName)
    {
        $startStopwatch = $this->stopwatch && empty($this->actionStack);

        $this->actionStack[] = ['name' => $actionName, 'time' => microtime(true), 'subtrahend' => 0];
        $this->lastActionIndex++;
        if ($startStopwatch) {
            $this->stopwatch->start($this->getStopwatchName(), $this->sectionName);
        }
    }
200338
protected function _actionRender(AnCommandContext $context)
    {
        if ($context->request->getFormat() == 'html' && AnRequest::type() == 'HTTP') {
            $this->_setPageTitle();
        }

        return parent::_actionRender($context);
    }
874162
private static function filters($actionContext) {
        $allFilters = InternalHelper::getStaticPropertyValue('\\PhpMvc\\Filter', 'filters');
        $allFiltersInstance = array();

        foreach ($allFilters as $actionName => $filters) {
            foreach ($filters as $filterName) {
                $className = $filterName;

                if (!class_exists($className)) {
                    $className = '\\' . PHPMVC_APP_NAMESPACE . '\\Filters\\' . $className;

                    if (!class_exists($className)) {
                        throw new \Exception('Filter "' . $filterName . '" not found.');
                    }
                }

                $filterClass = new \ReflectionClass($className);

                if (!$filterClass->isSubclassOf('\\PhpMvc\\ActionFilter')) {
                    throw new \Exception('The filter type must be the base of "\PhpMvc\ActionFilter".');
                }

                if ($filterClass->getConstructor() != null) {
                    $filterInstance = $filterClass->newInstance();
                }
                else {
                    $filterInstance = $filterClass->newInstanceWithoutConstructor();
                }

                $allFiltersInstance[] = $filterInstance;
            }
        }

        InternalHelper::setPropertyValue($actionContext, 'filters', $allFiltersInstance);
    }
580406
public <R> R doInContext(SearchContext context, Supplier<R> action) {
        R result;
        if (context == null) {
            result = action.get();
        } else {
            // store current context (without triggering exception if it was stale)
            SearchContext currentSearchContext = currentContext;
            boolean contextIsStale = currentContextIsStale;

            setCurrentContext(context);
            try {
                result = action.get();
            } finally {
                // make original current context active again
                currentContext = currentSearchContext;
                currentContextIsStale = contextIsStale;
            }
        }
        return result;
    }
861346
protected function _fetchEntity(ControllerContext $context)
    {
        if(!$context->result instanceof ModelEntityInterface)
        {
            switch($context->action)
            {
                case 'add'   :
                    $context->setEntity($this->getModel()->create($context->request->data->toArray()));
                    break;

                case 'edit'  :
                case 'delete':
                    $context->setEntity($this->getModel()->fetch());
                    break;

            }

        }
        else $context->setEntity($context->result);
    }
221051
private static function setViewContext($parentActionViewContext, $viewContext) {
        InternalHelper::setStaticPropertyValue('\\PhpMvc\\View', 'viewContext', $viewContext);
        InternalHelper::setStaticPropertyValue('\\PhpMvc\\Html', 'viewContext', $viewContext);
        InternalHelper::setStaticPropertyValue('\\PhpMvc\\Html', 'parentActionViewContext', $parentActionViewContext);
    }
223562
public function handleAction(ActionEvent $event)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        if ('clear-clipboard' === ($actionName = $event->getAction()->getName())) {
            $this->clearClipboard($event);
        }

        if (false === $this->checkPermission($event)) {
            $this->clearClipboard($event, false);

            $event->stopPropagation();

            return;
        }

        if ('create' === $actionName
            || 'cut' === $actionName
            || 'copy' === $actionName
            || 'deepcopy' === $actionName
        ) {
            $this->addToClipboard($event);
        }
    }
384184
protected function _actionDispatch(DispatcherContext $context)
    {
        $controller = $this->getController();

        if(!$controller instanceof ControllerViewable && !$controller instanceof ControllerModellable)
        {
            $action = strtolower($context->request->query->get('_action', 'alpha'));

            //Throw exception if no action could be determined from the request
            if(!$action) {
                throw new ControllerExceptionRequestInvalid('Action not found');
            }

            $controller->execute($action, $controller->getContext($context));
        }
        else $this->execute(strtolower($context->request->getMethod()), $context);

        //Set the result in the response
        if($context->result && !$context->response->isRedirect())
        {
            $result = $context->result;

            if ($result instanceof ObjectConfigFormat) {
                $context->response->setContentType($result->getMediaType());
            }

            if (is_string($result) || (is_object($result) && method_exists($result, '__toString'))) {
                $context->response->setContent($result);
            }
        }

        //Send the response
        if (!$this->isForwarded()) {
            $this->send($context);
        }
    }