@param Application $app
@param Request     $request
@param array       $parameters

@return Response
512220
public function defaultViewAction(Application $app, Request $request, $id)
    {
        return $this->renderView($app, array(
            'entity' => $app->getRepository($this->getModelName())->find($id),
        ));
    }
1092794
public function doRequest($request)
    {
        $this->createApplication();
        $zendRequest = $this->application->getRequest();

        $uri = new HttpUri($request->getUri());
        $queryString = $uri->getQuery();
        $method = strtoupper($request->getMethod());

        $zendRequest->setCookies(new Parameters($request->getCookies()));

        $query = [];
        $post = [];
        $content = $request->getContent();
        if ($queryString) {
            parse_str($queryString, $query);
        }

        if ($method !== HttpRequest::METHOD_GET) {
            $post = $request->getParameters();
        }

        $zendRequest->setQuery(new Parameters($query));
        $zendRequest->setPost(new Parameters($post));
        $zendRequest->setFiles(new Parameters($request->getFiles()));
        $zendRequest->setContent($content);
        $zendRequest->setMethod($method);
        $zendRequest->setUri($uri);
        $requestUri = $uri->getPath();
        if (!empty($queryString)) {
            $requestUri .= '?' . $queryString;
        }

        $zendRequest->setRequestUri($requestUri);

        $zendRequest->setHeaders($this->extractHeaders($request));
        $this->application->run();

        // get the response *after* the application has run, because other ZF
        //     libraries like API Agility may *replace* the application's response
        //
        $zendResponse = $this->application->getResponse();

        $this->zendRequest = $zendRequest;

        $exception = $this->application->getMvcEvent()->getParam('exception');
        if ($exception instanceof \Exception) {
            throw $exception;
        }

        $response = new Response(
            $zendResponse->getBody(),
            $zendResponse->getStatusCode(),
            $zendResponse->getHeaders()->toArray()
        );

        return $response;
    }
238753
public function updateResponse(ApplicationInterface $application, RequestInterface $request, ResponseInterface $response): void
    {
        parent::updateResponse($application, $request, $response);

        $locationUrl = Url::parseRelative($this->location, $request->getUrl());
        $response->setHeader('Location', $locationUrl->__toString());
    }
965849
public function indexDataAction(Request $request)
        {

            $aRemoteApps = RemoteAppQuery::create()->find();
            $sResult     = $this->renderView('SlashworksAppBundle:RemoteApp:data.json.twig', array(
                'entities' => $aRemoteApps,
            ));

            $response = new Response($sResult);
            $response->headers->set('Content-Type', 'application/json');

            return $response;

        }
1019359
public static final function create(App $app): ?Service
    {
        $request = $app->request();
        $response = $app->response();
        $requestUri = $request->uri();
        $requestMethod = $request->method();

        // detect service name if provided
        $service = null;
        $serviceName = strtolower($requestUri->segment(1, ''));
        $serviceNameAlias = '';
        $serviceMethod = null;
        $serviceMethodFilter = null;
        $serviceMethodArguments = null;
        $serviceAliases = $app->configValue('service.aliases');

        // main
        if ($serviceName == '') {
            $serviceName = Service::SERVICE_MAIN;
        }
        // aliases
        elseif (isset($serviceAliases[$serviceName][0])) {
            $serviceNameAlias = $serviceName;
            // 0 => name, methods => ...
            $serviceName = $serviceAliases[$serviceNameAlias][0];
            // 0 => name, method => ... if given for one invoke direction
            $serviceMethod = $serviceAliases[$serviceNameAlias]['method'] ?? null;
            // 0 => name, method => ..., methodFilter => ... if given for one invoke direction filter
            $serviceMethodFilter = $serviceAliases[$serviceNameAlias]['methodFilter'] ?? null;
        }
        // regexp routes
        else if (isset($serviceAliases['~~'])) {
            $uriPath = $requestUri->getPath();
            foreach ((array) $serviceAliases['~~'] as $route) {
                // these are required
                if (empty($route['method']) || empty($route['pattern'])) {
                    throw new ServiceException("Both 'method' and 'pattern' are required for RegExp aliases");
                }

                if (preg_match($route['pattern'], $uriPath, $match)) {
                    $serviceName = $route[0];
                    $serviceMethod = $route['method'];
                    $serviceMethodFilter = $route['methodFilter'] ?? null;
                    $serviceMethodArguments = array_slice($match, 1);
                    break;
                }
            }
        }

        $serviceName = self::toServiceName($serviceName);
        $serviceFile = self::toServiceFile($serviceName);
        $serviceClass = self::toServiceClass($serviceName);

        // set service as FailService
        if (!self::isServiceExists($serviceFile, $serviceClass)) {
            set_global('app.service.fail', [
                'code' => 404,
                'text' => sprintf('Service not found [%s]', $serviceName),
            ]);

            // set response status
            $response->setStatus(404);

            $serviceName   = Service::SERVICE_FAIL . Service::SERVICE_NAME_SUFFIX;
            $serviceMethod = Service::METHOD_MAIN;
            $serviceFile   = self::toServiceFile($serviceName);
            $serviceClass  = self::toServiceClass($serviceName);
        }

        $service = new $serviceClass($app, $serviceName, $serviceMethod);

        // detect and set service method
        if (!$service->isFailService()) {
            if ($serviceMethod != '') { // pass
                // @note: method could be checked in main() [if $useMainOnly=true in service]
                // @note: this will override $useMainOnly option in service
            } elseif ($service->usesMainOnly()) {
                // main only
                $serviceMethod = Service::METHOD_MAIN;
            } elseif ($service->isSite()) {
                // from segment
                if ($serviceMethod == '') {
                    $serviceMethod = strtolower($requestUri->segment(2, ''));
                }

                // alias
                if (isset($serviceAliases[$serviceNameAlias]['methods'][$serviceMethod])) {
                    $serviceMethod = self::toServiceMethod($serviceAliases[$serviceNameAlias]['methods'][$serviceMethod]);
                } elseif ($serviceMethod == '' || $serviceMethod == Service::METHOD_MAIN) {
                    // main
                    $serviceMethod = Service::METHOD_MAIN;
                } else {
                    $serviceMethod = self::toServiceMethod($serviceMethod);
                }
            } elseif ($service->isRest()) {
                // from request method
                $serviceMethod = strtolower($requestMethod->getName());
            }

            // check method
            if (!self::isServiceMethodExists($service, $serviceMethod)) {
                // check fallback method
                if (self::isServiceFallMethodExists($service)) {
                    $serviceMethod = Service::METHOD_FALL;
                } else {
                    set_global('app.service.fail', [
                        'code' => 404,
                        'text' => sprintf('Service method not found [%s::%s()]', $serviceName, $serviceMethod)
                    ]);

                    // set response status
                    $response->setStatus(404);

                    // override
                    $serviceName   = Service::SERVICE_FAIL . Service::SERVICE_NAME_SUFFIX;
                    $serviceMethod = Service::METHOD_MAIN;
                    $serviceFile   = self::toServiceFile($serviceName);
                    $serviceClass  = self::toServiceClass($serviceName);

                    // re-create service as FailService
                    $service = new $serviceClass($app, $serviceName, $serviceMethod);
                }
            }

            $service->setMethod($serviceMethod);

            // set service method arguments
            if (self::isServiceMethodExists($service, $serviceMethod)) {
                $serviceMethodArguments = isset($serviceMethodArguments) ? $serviceMethodArguments
                    : $requestUri->segmentArguments($service->isSite() ? 2 : 1);

                $ref = new \ReflectionMethod($serviceClass, $serviceMethod);
                foreach ($ref->getParameters() as $i => $param) {
                    if (!isset($serviceMethodArguments[$i])) {
                        $serviceMethodArguments[$i] = $param->isDefaultValueAvailable()
                            ? $param->getDefaultValue() : null;
                    }
                }

                $service->setMethodArguments($serviceMethod, $serviceMethodArguments);

                // method filter
                if ($serviceMethodFilter != null) {
                    $serviceMethodFilter->call($service);
                }
            }
        }

        return $service;
    }
532496
public function run(Request $request = null)
    {
        $this->init();
        $this->getLogger()->debug('Application launched');
        if (!($request instanceof Request)) {
            $appMode = $this->detectRunMode();
            if ($appMode == self::MODE_WEB) {
                $request = Request\Web::makeFromGlobals();
            } else {
                $request = Request\Cli::makeFromGlobals();
            }
        }
        $this->setupRouter($request);
        $response = $this->execute($request);
        $this->output($response);
        $this->getLogger()->debug('Application execution completed');
    }
21577
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null, $async = false)
    {
        $this->currentUri = $this->prepareUrlForRequest($uri);

        $symfonyRequest = SymfonyRequest::create(
            $this->currentUri,
            $method,
            $parameters,
            $cookies,
            $files,
            $server,
            $content
        );

        return $this->response = $this->send(
            Request::createFromBase($symfonyRequest),
            $async
        );
    }
205513
public function connect(Application $app)
    {
        /** @var ControllerCollection $controllers */
        $controllers = $app['controllers_factory'];
        $controllers->get('/', 'oauth.controller::signinRedirect');
        $controllers->get('/signin', 'oauth.controller::signinGet');
        $controllers->post('/signin', 'oauth.controller::signinPost');
        $controllers->post('/authorize', 'oauth.controller::authorize');
        $controllers->get('/access_token', 'oauth.controller::accessToken');
        $controllers->post('/access_token', 'oauth.controller::accessToken');
        $controllers->get('/token', 'oauth.controller::tokenInfo');

        return $controllers;
    }
661458
public static function runThis(Application $app, array $handlers, ServerRequestInterface $request)
    {
        return $app->set($handlers)
            ->run($request, new Emitter());
    }
724246
public function connect(Application $app)
    {
        $ctrl = $app['controllers_factory'];



        /**
         * Homepage
         */
        $ctrl
            ->get(
                '/',
                function () use ($app) {
                    $root = str_replace('index.php/', '', $app['url_generator']->generate('home'));

                    if ($app['request']->getRequestURI() != $root) {
                        return $app->redirect($root, Response::HTTP_MOVED_PERMANENTLY);
                    }

                    return $app['twig']->render('front/partials/home.twig');
                }
            )
            ->bind('home');



        /**
         * Admin root
         */
        $ctrl
            ->get(
                '/admin',
                function () use ($app) {
                    return $app->redirect($app['url_generator']->generate($app['config']['admin']['root']));
                }
            );


        /**
         * robots.txt
         */
        $ctrl
            ->get(
                '/robots.txt',
                function () use ($app) {
                    $response = new Response(
                        'User-agent: *'.PHP_EOL.(
                            $app['debug']
                                ? 'Disallow: /'
                                : 'Sitemap: '.$app['url_generator']->generate('home').'sitemap.xml'
                        )
                    );

                    $response->headers->set('Content-Type', 'text/plain');
                    return $response;
                }
            );



        return $ctrl;
    }
1105719
public function setApplication($app)
    {
        Argument::i()->test(1, 'string');

        $this->application = $app;
        return $this->setData($this->message);
    }
1189830
public function beforeRequest(Request $request, Application $app)
    {
        $this->root = $request->attributes->get('_root');
    }
740754
public function callAction($method, $parameters)
    {
        $this->responseArray['type'] = Response::TYPE_CONTENT;
        $this->responseArray['method'] = Request::method();
        $this->responseArray['code'] = Response::NO_ERROR;

        if (isset($this->requiredFields[$method]) and is_array($this->requiredFields[$method])) {
            $this->validateParameters($this->requiredFields[$method]);
        }

        $response = parent::callAction($method, $parameters);

        if ($response instanceof RedirectResponse) {
            $this->responseArray['type'] = Response::TYPE_REDIRECT;
            $this->responseArray['targetUrl'] = $response->getTargetUrl();
            $this->responseArray['code'] = $response->getStatusCode();
        } else {
            if ($response instanceof View) {
                return new JsonResponse($response->render());
            } else {
                if ($response instanceof JsonResponse) {
                    return $response;
                }
            }
        }

        return (new Response(config('app.debug')))->createResponse($this->responseArray);
    }
60472
public function updateResponse(ApplicationInterface $application, RequestInterface $request, ResponseInterface $response): void
    {
        $response->setStatusCode($this->statusCode);
        $response->setContent($this->content);
    }
720723
public function bootstrap(Application $app)
    {
        $uri = $app->make('config')->get('app.url', 'http://localhost');

        $components = parse_url($uri);

        $server = $_SERVER;

        if (isset($components['path'])) {
            $server = array_merge($server, [
                'SCRIPT_FILENAME' => $components['path'],
                'SCRIPT_NAME' => $components['path']
            ]);
        }

        $app->instance('request', Request::create(
            $uri,
            'GET',
            [],
            [],
            [],
            $server
        ));
    }
969498
public function run(Application $app)
    {
        $response = call_user_func_array($this->callback, array_merge($this->parameters, [$app]));
        parent::callAfterCallbacks($app);

        return $response;
    }
918754
public function error(Base $app, array $params)
    {
        $eol = PHP_EOL;
        $req = $app['VERB'].' '.$app['PATH'];
        $error = ($app['ERROR']?:[]) + [
            'text' => 'No-Message',
            'trace' => 'No-Trace',
            'status' => 'No-Status',
            'code' => '000',
        ];


        $this->log(sprintf(
            "[%s] %s %s",
            $req,
            $error['text'] ?: 'No-Message',
            $error['trace']
        ));

        if ($app['CLI']) {
            return;
        }

        if ($app['AJAX']) {
            echo json_decode($error);

            return;
        }

        if ($app['ERROR_TEMPLATE']) {
            echo ExtendedTemplate::instance()->render($app['ERROR_TEMPLATE']);

            return;
        }

        echo '<!DOCTYPE html>'.$eol.
            '<html lang="en">'.$eol.
            '<head>'.$eol.
                '<meta charset="utf-8">'.$eol.
                '<meta http-equiv="X-UA-Compatible" content="IE=edge">'.$eol.
                '<meta name="viewport" content="width=device-width, initial-scale=1">'.$eol.
                '<meta name="author" content="Eko Kurniawan">'.$eol.
                '<title>'.$error['code'].' '.$error['status'].'</title>'.$eol.
                '<style>'.$eol.
                'code{word-wrap:break-word;color:black}.comment,.doc_comment,.ml_comment{color:dimgray;font-style:italic}.variable{color:blueviolet}.const,.constant_encapsed_string,.class_c,.dir,.file,.func_c,.halt_compiler,.line,.method_c,.lnumber,.dnumber{color:crimson}.string,.and_equal,.boolean_and,.boolean_or,.concat_equal,.dec,.div_equal,.inc,.is_equal,.is_greater_or_equal,.is_identical,.is_not_equal,.is_not_identical,.is_smaller_or_equal,.logical_and,.logical_or,.logical_xor,.minus_equal,.mod_equal,.mul_equal,.ns_c,.ns_separator,.or_equal,.plus_equal,.sl,.sl_equal,.sr,.sr_equal,.xor_equal,.start_heredoc,.end_heredoc,.object_operator,.paamayim_nekudotayim{color:black}.abstract,.array,.array_cast,.as,.break,.case,.catch,.class,.clone,.continue,.declare,.default,.do,.echo,.else,.elseif,.empty.enddeclare,.endfor,.endforach,.endif,.endswitch,.endwhile,.eval,.exit,.extends,.final,.for,.foreach,.function,.global,.goto,.if,.implements,.include,.include_once,.instanceof,.interface,.isset,.list,.namespace,.new,.print,.private,.public,.protected,.require,.require_once,.return,.static,.switch,.throw,.try,.unset,.use,.var,.while{color:royalblue}.open_tag,.open_tag_with_echo,.close_tag{color:orange}.ini_section{color:black}.ini_key{color:royalblue}.ini_value{color:crimson}.xml_tag{color:dodgerblue}.xml_attr{color:blueviolet}.xml_data{color:red}.section{color:black}.directive{color:blue}.data{color:dimgray}'.
                '</style>'.$eol.
            '</head>'.$eol.
            '<body>'.$eol.
                '<h1>'.$error['status'].'</h1>'.$eol.
                '<p>'.$app->encode($error['text']?:$req).'</p>'.$eol.
                ($app['DEBUG']?('<pre>'.$error['trace'].'</pre>'.$eol):'').
            '</body>'.$eol.
            '</html>';
    }