Executes an action on a collection of resources.

@EXT\Route("/collection/{action}", name="claro_resource_collection_action")

@param string  $action
@param Request $request

@return JsonResponse

@throws NotFoundHttpException
356045
public function executeCollectionAction($action, Request $request)
    {
        $ids = $request->query->get('ids');

        /** @var ResourceNode[] $resourceNodes */
        $resourceNodes = $this->om->findList(ResourceNode::class, 'uuid', $ids);
        $responses = [];

        // read request and get user query
        $parameters = $request->query->all();
        $content = null;

        if (!empty($request->getContent())) {
            $content = json_decode($request->getContent(), true);
        }
        $files = $request->files->all();

        $this->om->startFlushSuite();

        foreach ($resourceNodes as $resourceNode) {
            // check the requested action exists
            if (!$this->actionManager->support($resourceNode, $action, $request->getMethod())) {
                // undefined action
                throw new NotFoundHttpException(
                    sprintf('The action %s with method [%s] does not exist for resource type %s.', $action, $request->getMethod(), $resourceNode->getResourceType()->getName())
                );
            }

            // check current user rights
            $this->checkAccess($this->actionManager->get($resourceNode, $action), [$resourceNode]);

            // dispatch action event
            $responses[] = $this->actionManager->execute($resourceNode, $action, $parameters, $content, $files);
        }

        $this->om->endFlushSuite();

        return new JsonResponse(array_map(function (Response $response) {
            return json_decode($response->getContent(), true);
        }, $responses));
    }
1273070
public function execute(RestRequestModel $apiRequest, $action, $indexedArgs)
    {
        $actionReader = $this->actionReader;
        $response = new ActionResponseModel();

        $actionCollection = $actionReader->getActionCollection();

        /* @var ActionModel $targetAction */
        if (!isset($actionCollection[$action][$apiRequest->getMethod()])) {
            throw new \Exception('Method '.$apiRequest->getMethod().' not supported by '.$action.' action.');
        }

        $targetAction = $actionCollection[$action][$apiRequest->getMethod()];

        if (!isset($targetAction)) {
            throw new \Exception('Unknown action "'.$action.'" for this controller.');
        }

        $query = [];
        parse_str($apiRequest->getQueryString(), $query);

        $content = $this->contentParser($apiRequest);

        // array of hashed based args
        $searchHashedArgs = [$query, $content];

        // get a hash of paramName => value ($preparedArgs), and a list of the params
        list($preparedArgs, $params) = $this->prepareArgs($targetAction, $indexedArgs, $searchHashedArgs);

        $callAction = [$actionReader->getController(), $targetAction->getClassMethod()];
        $callResponse = call_user_func_array($callAction, $preparedArgs);

        if ($callResponse) {
            $response
                ->setArgs($this->sanitizeArgs($preparedArgs))
                ->setParams($params)
                ->setResponse($callResponse)
                ->setPkgUuid($this->pkgUuid);
        }

        return $response;
    }
1194156
protected function execute($action, array $parameters = [])
    {
        $parameters += $this->input;

        return $this->server->dispatch(
            new ServerRequest($action, $parameters)
        )->getData();
    }
570409
public function jsonSaveAction(Request $request)
    {
        //@FIXME: This code need to be moved to ContentController somehow.
        $this->save($request);

        $response = new Response(json_encode(['status' => 'ok']));
        $response->headers->set("Content-Type", 'application/json');

        return $response;
    }
6407
public function cgetAction(Request $request)
    {
        $list = new CollectionRepresentation(
            $this->getManager()->findAll($this->getLocale($request)),
            self::$entityKey
        );

        $view = $this->view($list);

        return $this->handleView($view);
    }
1256553
public function handleAction($request, $action)
    {
        // if we submitted a form, let that pass
        if (!$request->isGET() && !$request->isHEAD()) {
            return parent::handleAction($request, $action);
        }

        $url = $request->getURL();

        //
        // If the current request has an extension attached to it, strip that
        // off and redirect the user to the page without an extension.
        //
        if (DocumentationHelper::get_extension($url)) {
            $this->response = new SS_HTTPResponse();
            $this->response->redirect(
                Director::absoluteURL(DocumentationHelper::trim_extension_off($url)) .'/',
                301
            );

            $request->shift();
            $request->shift();

            return $this->response;
        }

        //
        // Strip off the base url
        //
        $base = ltrim(
            Config::inst()->get('DocumentationViewer', 'link_base'),
            '/'
        );

        if ($base && strpos($url, $base) !== false) {
            $url = substr(
                ltrim($url, '/'),
                strlen($base)
            );
        }

        //
        // Handle any permanent redirections that the developer has defined.
        //
        if ($link = DocumentationPermalinks::map($url)) {
            // the first param is a shortcode for a page so redirect the user to
            // the short code.
            $this->response = new SS_HTTPResponse();
            $this->response->redirect($link, 301);

            $request->shift();
            $request->shift();

            return $this->response;
        }

        //
        // Validate the language provided. Language is a required URL parameter.
        // as we use it for generic interfaces and language selection. If
        // language is not set, redirects to 'en'
        //
        $languages = i18n::get_common_languages();

        if (!$lang = $request->param('Lang')) {
            $lang = $request->param('Action');
            $action = $request->param('ID');
        } else {
            $action = $request->param('Action');
        }

        if (!$lang) {
            return $this->redirect($this->Link('en'));
        } elseif (!isset($languages[$lang])) {
            return $this->httpError(404);
        }

        $request->shift(10);

        $allowed = $this->config()->allowed_actions;

        if (in_array($action, $allowed)) {
            //
            // if it's one of the allowed actions such as search or all then the
            // URL must be prefixed with one of the allowed languages and versions
            //
            return parent::handleAction($request, $action);
        } else {
            //
            // look up the manifest to see find the nearest match against the
            // list of the URL. If the URL exists then set that as the current
            // page to match against.

            // strip off any extensions.


            // if($cleaned !== $url) {
            // 	$redirect = new SS_HTTPResponse();

            // 	return $redirect->redirect($cleaned, 302);
            // }
            if ($record = $this->getManifest()->getPage($url)) {
                // In SS 3 offsetSet() isn't implemented for some reason... this is a workaround
                $routeParams = $this->request->routeParams();
                $routeParams['Lang'] = $lang;
                $this->request->setRouteParams($routeParams);

                $this->record = $record;
                $this->init();

                $type = get_class($this->record);
                $body = $this->renderWith(
                    array(
                        "DocumentationViewer_{$type}",
                        'DocumentationViewer'
                    )
                );

                return new SS_HTTPResponse($body, 200);
            } elseif ($redirect = $this->getManifest()->getRedirect($url)) {
                $response = new SS_HTTPResponse();
                $to = Controller::join_links(Director::baseURL(), $base, $redirect);
                return $response->redirect($to, 301);
            } elseif (!$url || $url == $lang) {
                $body = $this->renderWith(
                    array(
                        'DocumentationViewer_DocumentationFolder',
                        'DocumentationViewer'
                    )
                );

                return new SS_HTTPResponse($body, 200);
            }
        }

        return $this->httpError(404);
    }
937722
public function execute(Request $request, Response $response, ...$params)
    {
        try {
            $className = "{$this->_controllerNs}\\{$this->_controllerName}";
            $methodName = $this->_actionName.'Action';

            $classRefl = new \ReflectionClass($className);

            $instance = $classRefl->newInstance();
            if (method_exists($instance, '__init__')) {
                $instance->__init__();
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug("exec: {$className}->__init__");
                }
            }
            if (!method_exists($instance, $methodName)) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug('the request method not exist');
                }

                throw new HttpNotFoundException('The request method not exist!');
            }

            $methodRefl = $classRefl->getMethod($methodName);
            $paramsRefl = $methodRefl->getParameters();
            $params = [];
            foreach ($paramsRefl as $index => $param) {
                $paramClass = $param->getClass();

                if ($paramClass->implementsInterface('Focus\Request\Request')) {
                    $params[$index] = $request;
                } elseif ($paramClass->implementsInterface('Focus\Response\Response')) {
                    $params[$index] = $response;
                } elseif ($paramClass->implementsInterface('Focus\Request\Session')) {
                    $params[$index] = $request->session();
                } elseif ($paramClass->implementsInterface('Focus\Config\Config')) {
                    $params[$index] = $request->config();
                } elseif ($paramClass->implementsInterface('Focus\MVC\Model')
                           || $paramClass->implementsInterface('Focus\MVC\Service')) {
                    if ($request->container()->has($paramClass->getName())) {
                        $object = $request->container()->get($paramClass->getName());
                    } else {
                        $object = $paramClass->newInstance();
                    }
                    $params[$index] = $object;
                    $params[$index]->init();
                } elseif ($paramClass->implementsInterface('Focus\MVC\View')) {
                    $params[$index] = $paramClass->newInstance();
                } else {
                    if (!empty($this->_pathParams)) {
                        $params[$index] = array_shift($this->_pathParams);
                    }
                }
            }

            $res = $instance->{$methodName}(...$params);
            if ($res instanceof View) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug('use view object for response');
                }

                $res->output($response);
            } elseif (is_string($res) || is_numeric($res)) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug('use scalar type for response');
                }

                $response->write($res);
            }

            return $res;
        } catch (\ReflectionException $exception) {
            if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                $this->getLogger()->debug(sprintf(
                    'reflection exception: [%s] %s',
                    $exception->getCode(),
                    $exception->getMessage()
                ));
            }
            throw new \RuntimeException($exception->getMessage(), $exception->getCode(), $exception);
        }
    }
84304
public function call($action, $params = array()) {
		$time = 0.0;
		$response = new Client\Response($action, $this->directCall($action, $params, $time), $time);
		
		if(!$response->isOk()) {
			throw new Client\Exception\ActionFailed($response, "Action '".$action->name()."' failed: ".$response->getMessage());
		}
		
		switch($action->layout('output')) {
			case 'object':
				return new Client\ResourceInstance($this->client, $action, $response);
			
			case 'object_list':
				return new Client\ResourceInstanceList($this->client, $action, $response);
			
			default:
				return $response;
		}
	}
1053020
public function renameAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $folder = $this->findFolderById($request->attributes->get('id'));

        $folder->setName($request->request->get('name'));

        if (true !== $message = $this->validateFolder($folder)) {
            $result = array(
                'error'   => true,
                'message' => $message,
            );
        } else {
            $this->persistFolder($folder);
            $result = array(
                'name' => $folder->getName(),
            );
        }

        $response = new Response(json_encode($result, JSON_FORCE_OBJECT));
        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
210450
protected function handleAction($request, $action)
	{
		$module = $this->findModule();
		
		if(!$module) {
			return parent::handleAction($request, $action);
		}
		
		$data = [];
		
		if($this->isGreenPage()) {
			$data = $this->data()->toViewableData();
		}
		elseif($module->getDataSource()) {
			$data = $module->getDataSource()->toDBObject();
		}

		$module->loadRequirements();
		$viewer = $this->getViewer($action);					
		$viewer->setTemplateFile('Layout', $module->getLayoutTemplateFile());

		$main = $module->getMainTemplateFile();
		if($main) {
			$viewer->setTemplateFile('main', $main);
		}
		
		return $viewer->process($this->customise($data));
	}
1034178
private function callAction($controller, $actionName, $request = null)
    {
        if (method_exists($controller, $actionName)) {
            $context = $controller->$actionName($request);
            if ($context == null) {
                $context = [];
            }
            return $context;
        }
        throw new PageNotFoundException("Method " . $actionName . " not found!");
    }
823398
protected function processRaw(Request $request) {
		$resolver = $this->getResolver();
		$resolver->sortRoutes();

		$route = $resolver->getRoute($request);

		if($route) {
			$request->setRoute($route);
			$controllerClass = $route->getController();
			$action = $route->getAction();

			$controller = new $controllerClass();
			$controller->setFlash($this->flash);
			$controller->setResolver($this->resolver);
			$controller->setContainer($this->container);

			$this->prepareController($controller, $action, $request, $route);
		}
		else
			$controller = null;

		if($response = $this->hookManager->trigger('Asgard.Http.Start', [$request, $controller]))
			return $response;

		if($response = $this->executeStart($request, $controller))
			return $response;

		if($route === null)
			throw new Exception\NotFoundException;

		return $controller->run($action, $request);
	}
345526
public function execute($action = NULL)
	{
		$action = ($action == NULL)
			? strtolower($this->request->getMethod())
			: $action;

		$this->before();
		$this->{$action}();
		$this->after();
	}
479953
public function queryAction(Request $request)
    {
        $geolocatorName = $request->get('providerName');
        $query = $request->get('query');

        try {
            $geolocator = $this->geolocatorManager->get($geolocatorName);
        } catch (GeolocatorNotFoundException $e) {
            throw new NotFoundHttpException(
                sprintf(
                    'Wrapped "%s"',
                    $e->getMessage()
                ),
                $e
            );
        }

        $res = $geolocator->locate($query);

        return new JsonResponse(['_embedded' => ['locations' => $res->toArray()]]);
    }
612172
public function createAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $refFolder = $this->findFolderById($request->attributes->get('id'));
        $repo = $this->getFolderRepository();

        $newFolder = $repo->createNew();
        $newFolder->setName('New folder');

        $mode = strtolower($request->request->get('mode'));
        if (!in_array($mode, array('child', 'after'))) {
            $response = new Response(json_encode(array(
                'error'   => true,
                'message' => 'Unexpected creation mode.',
            ), JSON_FORCE_OBJECT));
        } else {
            if ($mode === 'after') {
                $repo->persistAsNextSiblingOf($newFolder, $refFolder);
            } else {
                $repo->persistAsFirstChildOf($newFolder, $refFolder);
            }

            if (true !== $message = $this->validateFolder($newFolder)) {
                $response = new Response(json_encode(array(
                    'error'   => true,
                    'message' => $message,
                ), JSON_FORCE_OBJECT));
            } else {
                $this->getEntityManager()->flush();
                $data = $this->get('jms_serializer')->serialize(
                    $newFolder,
                    'json',
                    SerializationContext::create()->setGroups(array('Manager'))
                );
                $response = new Response(sprintf('{"node":%s}', $data));
            }
        }

        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
1193222
public function listAction(Request $request)
    {
        return new JsonResponse(
            $this->finder->search(
                'UJM\ExoBundle\Entity\Item\Item',
                $request->query->all(),
                [Transfer::INCLUDE_SOLUTIONS, Transfer::INCLUDE_ADMIN_META]
            )
        );
    }
1310706
public function cgetAction(Request $request)
    {
        $ids = array_filter(explode(',', $request->get('ids', '')));

        $result = $this->getCustomerManager()->findByIds($ids);

        $list = new CollectionRepresentation(
            $result,
            self::$entityKey
        );
        $view = $this->view($list, 200);

        return $this->handleView($view);
    }