Handles a request with the proper handler.

Decides on which handler to use based on the request format.

@param View    $view
@param Request $request

@throws UnsupportedMediaTypeHttpException

@return Response
334774
public function handle(View $view, Request $request = null)
    {
        if (null === $request) {
            $request = $this->requestStack->getCurrentRequest();
        }

        $format = $view->getFormat() ?: $request->getRequestFormat();

        if (!$this->supports($format)) {
            $msg = "Format '$format' not supported, handler must be implemented";

            throw new UnsupportedMediaTypeHttpException($msg);
        }

        if (isset($this->customHandlers[$format])) {
            return call_user_func($this->customHandlers[$format], $this, $view, $request, $format);
        }

        return $this->createResponse($view, $request, $format);
    }
412073
public function handleWebhook(Request $request)
    {
        try {
            $webhook = $this->parseBraintreeNotification($request);
        } catch (Exception $e) {
            return;
        }

        $method = 'handle'.Str::studly(str_replace('.', '_', $webhook->kind));

        if (method_exists($this, $method)) {
            return $this->{$method}($webhook);
        }

        return $this->missingMethod();
    }
488028
public function handle(Request $request, $requestType = self::REQUEST_TYPE_MASTER)
  {
    // Boot on first request
    if (!$this->booted) $this->boot();
    
    try
    {
      return $this->handleRaw($request,$requestType);
    } 
    catch (\Exception $ex) // TODO: Implement Exception listener
    {
      $class = get_class($ex);
      $message = $ex->getMessage();
      switch($class)
      {
        case 'Symfony\Component\Security\Core\Exception\AccessDeniedException':
          $code = 401;
          break;
        default:
          $code = 401;
      }
      $response = new ResponseJson(['error' => $message],$code);
      
      // Need this so auth headers get set
      $dispatcher = $this->container->get('event_dispatcher');
      return $this->dispatchResponse($dispatcher,$request,$response);
    }
  }
1127984
public function postMediaAction($provider, Request $request) {
    	$pool = $this->get("sonata.media.pool");
        $manager = $this->get("sonata.media.manager.media");
    	$formFactory = $this->get('form.factory');

    	try {
    		$mediaProvider = $pool->getProvider($provider);
    	} catch (\RuntimeException $ex) {
    		throw new NotFoundHttpException($ex->getMessage(), $ex);
    	}
    	$medium = $manager->create();
    	$medium->setProviderName($provider);
    	$form = $formFactory->createNamed(null, 'sonata_media_api_form_media', $medium, array(
    			'provider_name'   => $mediaProvider->getName(),
//    			'csrf_protection' => false
    	));

    	$form->bind($request);

    	if ($form->isValid()) {
            try {
	    		$medium = $form->getData();
	    		$manager->save($medium);
            } catch (DBALException $e) {
                return $this->handleView(
                    View::create(array('errors'=>array($e->getMessage())), 400)
                );
            }
            return $this->handleView(
                View::create($this->formatMedia($medium), 200, array('Location'=>$this->generateUrl(
                    "_togu_media_rest_get_media",
                    array('id'=>$medium->getId()),
                    true
                )))->setSerializationContext($this->getSerializerContext(array('sonata_api_read')))
            );
    	} else {
            return $this->handleView(
                View::create(array('errors'=>$form->getErrors()), 400)
            );
        }
    }
123997
public function handle(Request $request): Response
    {
        try {
            $matcher = $this->getUrlMatcher($request);

            $parameters = $matcher->match($request->getPathInfo());

            if (empty($parameters['_controller'])) {
                throw new InvalidRouteException('Route requires a _controller callable');
            }

            if (!\is_callable($parameters['_controller'])) {
                throw new InvalidRouteException('_controller must be a callable');
            }

            $callback = $parameters['_controller'];

            $result = call_user_func_array($callback, $this->getControllerParameters($request, $parameters));

            if (!$result instanceof Response) {
                throw new InvalidResponseException('Response must be an instance of \Symfony\Component\HttpFoundation\Response');
            }
        } catch (\Exception $e) {
            $result = $this->handleException($request, $e);
        }

        return $result;
    }
443506
protected function handleCreateView()
    {
        $input = $this->getCommandInput();
        $resources = Resource::fromFile($input->resourceFile, $input->languageFileName);
        $destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix);

        if ($this->canCreateView($destenationFile, $input->force, $resources)) {
            $stub = $this->getStub();
            $htmlCreator = $this->getHtmlGenerator($resources->fields, $input->modelName, $this->getTemplateName());
            $headers = $this->getHeaderFieldAccessor($resources->fields, $input->modelName);

            $this->createLanguageFile($input->languageFileName, $input->resourceFile, $input->modelName)
                ->replaceCommonTemplates($stub, $input, $resources->fields)
                ->replaceFields($stub, $htmlCreator->getHtmlFields())
                ->replaceModelHeader($stub, $headers)
                ->createFile($destenationFile, $stub)
                ->info('Form view was crafted successfully.');
        }
    }
478959
public function createResponse(View $view, Request $request, $format)
    {
        $route = $view->getRoute();

        $location = $route
            ? $this->urlGenerator->generate($route, (array) $view->getRouteParameters(), UrlGeneratorInterface::ABSOLUTE_URL)
            : $view->getLocation();

        if ($location) {
            return $this->createRedirectResponse($view, $location, $format);
        }

        $response = $this->initResponse($view, $format);

        if (!$response->headers->has('Content-Type')) {
            $mimeType = $request->attributes->get('media_type');
            if (null === $mimeType) {
                $mimeType = $request->getMimeType($format);
            }

            $response->headers->set('Content-Type', $mimeType);
        }

        return $response;
    }
49063
protected function handleCreateView()
    {
        $input = $this->getCommandInput();
        $resources = Resource::fromFile($input->resourceFile, $input->languageFileName);
        $destenationFile = $this->getDestinationViewFullname($input->viewsDirectory, $input->prefix);

        if ($this->canCreateView($destenationFile, $input->force, $resources)) {
            $stub = $this->getStub();

            $this->createLanguageFile($input->languageFileName, $input->resourceFile, $input->modelName)
                ->createMissingViews($input)
                ->replaceCommonTemplates($stub, $input, $resources->fields)
                ->replaceFileUpload($stub, $resources->fields)
                ->replacePrimaryKey($stub, $this->getPrimaryKeyName($resources->fields))
                ->replaceModelHeader($stub, $this->getHeaderFieldAccessor($resources->fields, $input->modelName))
                ->replaceFormId($stub, $this->getFormId($input->modelName))
                ->replaceFormName($stub, $this->getFormName($input->modelName))
                ->createFile($destenationFile, $stub)
                ->info('Edit view was crafted successfully.');
        }
    }
165290
public function compose(View $view)
    {
        $corporation_info = CorporationInfo::find($this->request->corporation_id);

        if (! is_null($corporation_info))
            $view->with('corporation_name', $corporation_info->name);
    }
947484
public function handle(CrudBuilder $crud, ViewBuilder $view)
    {


        if ( $crud->makeCrudFiles($this->argument()) ) {

            $this->sendSuccessMessage();

        } else {

            $this->error('Oops, something went wrong!');

        }

        if ( $view->makeViewFiles($this->argument()) ) {

            $this->sendViewsSuccessMessage();

            return;

        }

        $this->error('Oops, something went wrong!');

    }
290606
public function dispatch(Request $request, $result)
    {
        foreach ($request->getAcceptableContentTypes() as $mimeType) {
            /** @var \eZ\Publish\Core\REST\Common\Output\Visitor $visitor */
            foreach ($this->mapping as $regexp => $visitor) {
                if (preg_match($regexp, $mimeType)) {
                    return $visitor->visit($result);
                }
            }
        }

        throw new RuntimeException('No view mapping found.');
    }
1241426
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// check for presence of callback param
		// if we have one lets replace response content with a function executing the 
		// current response content
		if ($callback = $request->getVar('callback', null))
		{
			$response->headers->set('content-type', 'application/javascript');
			$response->setContent(sprintf('%s(%s);', $callback, $response->getContent()));
		}

		// return response
		return $response;
	}
577453
public function compose(View $view)
    {
        $view->withComponentCount($this->componentCount);
        $view->withIncidentCount($this->incidentCount);
        $view->withIncidentTemplateCount($this->incidentTemplateCount);
        $view->withScheduleCount($this->scheduleCount);
        $view->withSubscriberCount($this->subscriberCount);
        $view->withIsWriteable(is_writable(app()->bootstrapPath().'/cachet'));
    }
296898
protected function processView($action, View $view)
    {
        $this->getRestEventDispatcher()->dispatch(
            RestEvents::VIEW,
            $event = new ViewEvent($this->resource, $action, $view)
        );

        return $this->handleView($event->getView());
    }
243063
protected function render(string $view, array $params = []): Response
    {
        $this->getTemplateEngine()->addGlobal('_request', $this->getRequest());
        $template = $this->getTemplateEngine()->render($view, $params);

        return $this->getResponse()->setContent($template);
    }
514894
public function process(Request $request, Handler $handler): Response
    {
        $request = $request->withAttribute(
            $this->authAttribute,
            $this->resume()
        );
        return $handler->handle($request);
    }
112118
public function applyPostHandle(ServletRequestInterface $request, ServletResponseInterface $response, ModelAndView $model)
    {
        $interceptors = $this->getInterceptors();
        if (!empty($interceptors)) {
            for ($i = $this->interceptorIndex; $i >= 0; $i--) {
                $interceptor = $interceptors[$i];
                $interceptor->postHandle($request, $response, $this->handler, $model);
            }
        }
    }