@param Request $request
@param mixed   $data

@throws \Exception

@return Response
9312
public function editAction(Request $request, $data = null)
    {
        if (null === $data) {
            $data = $this->getDataFromRequest($request);
        }
        $form = $this->getForm($request, $data);

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $this->saveEntity($data);

            $parameters = $request->query->all();
            $parameters['success'] = 1;

            return $this->redirectToEntity($data, 'edit', $parameters);
        }

        return $this->renderAction($this->getViewParameters($request, $form, $data));
    }
875365
public function handle(Request $request)
    {
        try {
            $restRequest = new RestRequest($this->config, $request->getMethod(), $request->getUri(), $request->getContent());
            $restResponse = $this->adapter->processRequest($restRequest);
        } catch (\Exception $e) {
            if (true === $this->debugEnabled()) {
                throw $e;
            }
            $restResponse = $this->adapter->handleException($e);
        }
        return new Response($restResponse->getContent(), $restResponse->getStatus(), $restResponse->getHeaders());
    }
478546
public function parseRequest(Request $request)
    {
        try {
            $this->setPath($request->get('_route'));

            $this->setQuery($request->query->all());

            $this->setRouteParams($request->attributes->get('_route_params'));

            if ($request->get('page')) {
                $this->setCurrentPage((int)$request->get('page'));
            }

            if ($request->get('maxItems')) {
                $this->setNumberOfElementsPerPage((int)$request->get('maxItems'));
            }

        } catch (\Exception $e) {
            throw new \Exception ('The request provided is not a valid Request Object');
        }

        return $this;
    }
797618
public function receiveRequest(Request $request): Response
    {
        $curie = $request::schema()->getCurie();
        $curieStr = $curie->toString();

        if (isset($this->handlers[$curieStr])) {
            $handler = $this->handlers[$curieStr];
        } else {
            try {
                $handler = $this->locator->getRequestHandler($curie);
            } catch (\Throwable $e) {
                return $this->createResponseForFailedRequest($request, $e);
            }

            $this->handlers[$curieStr] = $handler;
        }

        try {
            $request->freeze();
            $response = $handler->handleRequest($request, $this->locator->getPbjx());
            $response->set('ctx_request_ref', $request->generateMessageRef());
            if ($request->has('ctx_correlator_ref')) {
                $response->set('ctx_correlator_ref', $request->get('ctx_correlator_ref'));
            }

            return $response;
        } catch (\Throwable $e) {
            return $this->createResponseForFailedRequest($request, $e);
        }
    }
516904
protected function _post($data) {
		$ch = curl_init();
		curl_setopt_array($ch, array(
			CURLOPT_URL            => static::ENDPOINT,
			CURLOPT_POST           => true,
			CURLOPT_POSTFIELDS     => json_encode($data),
			CURLOPT_HEADER         => false,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_SSL_VERIFYPEER => true,
			CURLOPT_SSL_VERIFYHOST => 2,
			CURLOPT_FOLLOWLOCATION => false,
			CURLOPT_HTTPHEADER => array('Content-Type: application/json')
		));

		$response = curl_exec($ch);
		curl_close($ch);

		if ($response === false) {
			throw new Exception('Failed to contact BrowserID verification service');
		}

		$decodedResponse = json_decode($response);
		if (!$decodedResponse) {
			throw new Exception('Response is not valid JSON');
		}

		return $decodedResponse;
	}
27758
public function create($api, array $data)
    {
        return $this->checkException($this->callHttpMethod($this->normalizeUri($api), Request::METHOD_POST, $data));
    }
215187
private function createResponseForFailedRequest(Request $request, \Throwable $exception): Response
    {
        $code = $exception->getCode() > 0 ? $exception->getCode() : Code::UNKNOWN;

        $response = RequestFailedResponseV1::create()
            ->set('ctx_request_ref', $request->generateMessageRef())
            ->set('ctx_request', $request)
            ->set('error_code', $code)
            ->set('error_name', ClassUtils::getShortName($exception))
            ->set('error_message', substr($exception->getMessage(), 0, 2048))
            ->set('stack_trace', $exception->getTraceAsString());

        if ($exception->getPrevious()) {
            $response->set('prev_error_message', substr($exception->getPrevious()->getMessage(), 0, 2048));
        }

        if ($request->has('ctx_correlator_ref')) {
            $response->set('ctx_correlator_ref', $request->get('ctx_correlator_ref'));
        }

        return $response;
    }
252963
public function webhook(Request $request): Response
    {
        $content = (string) $request->getContent();
        $spaceId = $request->headers->get('X-Space-Id');
        $spaceId = is_array($spaceId) ? $spaceId[0] : $spaceId;

        try {
            $client = $this->contentful->getClientBySpaceId((string) $spaceId);
        } catch (Throwable $t) {
            throw new BadRequestHttpException('Invalid request');
        }

        if ($client === null) {
            throw new BadRequestHttpException('Invalid request');
        }

        try {
            $remoteEntry = $client->parseJson($content);
        } catch (Throwable $t) {
            throw new BadRequestHttpException('Invalid request');
        }

        switch ($request->headers->get('X-Contentful-Topic')) {
            case self::ENTRY_PUBLISH:
                if (!$remoteEntry instanceof Entry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->refreshContentfulEntry($remoteEntry);

                break;
            case self::ENTRY_UNPUBLISH:
                if (!$remoteEntry instanceof DeletedEntry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->unpublishContentfulEntry($remoteEntry);

                break;
            case self::ENTRY_DELETE:
                if (!$remoteEntry instanceof DeletedEntry) {
                    throw new BadRequestHttpException('Invalid request');
                }

                $this->contentful->deleteContentfulEntry($remoteEntry);

                break;
            case self::CONTENT_TYPE_PUBLISH:
            case self::CONTENT_TYPE_UNPUBLISH:
            case self::CONTENT_TYPE_DELETE:
                $this->contentful->refreshContentTypeCache($client);

                break;
            default:
                throw new BadRequestHttpException('Invalid request');
        }

        return new Response();
    }
1342240
public function handle(Request $request)
    {
        if (!$this->booted) {
            $this->bootstrap();
        }

        $this->request = $request;

        try {
            // Route Request
            $req_info = $this->router->matchRequest($request);

            // Resolve Controller
            $resolver = new Resolver();
            $controller = $resolver->resolveController($req_info['_controller']);

            if (false === $controller) {
                throw new Exception(sprintf('Invalid Controller %s From Route %s', $req_info['_controller'], $req_info['_route']));
            }

            // If the controller is ContainerAware, inject the container
            if ($controller[0] instanceof ContainerAwareInterface) {
                $controller[0]->setContainer($this->container);
            }

            // Build controller method arguments
            $arguments = $resolver->resolveArguments($controller, $request, $req_info);

            // Call controller and get response
            $response = call_user_func_array($controller, $arguments);

            if (!$response instanceof Response) {
                throw new Exception(sprintf('Controller %s did not return a valid Response object.', $req_info['_controller']));
            }

        } catch (\Exception $e) {
            $response = $this->handleException($e);
        }

        return($response);
    }
954915
public function send(Request $request)
    {
        $httpRequest = $this->createHttpRequest($request);
        $response    = new GetResponse();

        try {
            $httpResponse = $this->client->send($httpRequest);
            $code         = $httpResponse->getStatusCode();
        } catch (RequestException $e) {
            if ($e->getCode() == 404 && $request->notfoundOk) {
                return $response;
            }

            throw $e;
        }

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        $contentList = $this->getRiakContentList($httpResponse);
        $vClock      = $httpResponse->getHeader('X-Riak-Vclock');

        $response->vClock = $vClock;
        $response->contentList = $contentList;

        return $response;
    }
771467
public function executeAction(Request $request)
    {
        /**
         * @var FormInterface $form
         */
        $form = $this
            ->formFactory
            ->create('stripe_view');

        $form->handleRequest($request);
        $redirect = $this
            ->redirectionRoutes
            ->getRedirectionRoute('success');

        try {
            if (!$form->isValid()) {
                throw new PaymentException();
            }

            $data = $form->getData();
            $paymentMethod = $this->createStripeMethod($data);
            $this
                ->stripeManager
                ->processPayment($paymentMethod, $data['amount']);
        } catch (Exception $e) {

            /**
             * Must redirect to fail route.
             */
            $redirect = $this
                ->redirectionRoutes
                ->getRedirectionRoute('failure');
        }

        $redirectUrl = $this
            ->urlGenerator
            ->generate(
                $redirect->getRoute(),
                $redirect->getRouteAttributes(
                    $this->paymentBridge->getOrderId()
                )
            );

        return new RedirectResponse($redirectUrl);
    }
1095575
public function indexAction(Request $request)
    {

        // For Mailchimp ping GET
        if ($request->isMethod('GET')) {
            return new JsonResponse([
                'success' => true,
                'ping' => 'pong',
            ]);
        }

        // Handle POST request of Mailchimp
        $type = $request->request->get('type');
        $data = $request->request->get('data');
        /* Response example:
            data[merges][FNAME]: Tztz
            data[merges][EMAIL]: tztz@gmail.com
            data[email_type]: html
            data[reason]: manual
            data[email]: tztz@gmail.com
            data[id]: 5c1b5a7c1e
            data[merges][LNAME]: TZST
            data[list_id]: ba039c6198
            data[web_id]: 3375995
        */
        $hooksecret = $request->query->get('hooksecret');

        if (empty($type) || empty($data) || empty($hooksecret) || !array_key_exists('list_id', $data)) {
            throw new AccessDeniedHttpException('incorrect data format!');
        }

        $listId = $data['list_id'];

        $listProviderKey = $this->getParameter('welp_mailchimp.list_provider');
        try {
            $listProvider = $this->get($listProviderKey); 
        } catch (ServiceNotFoundException $e) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should be defined as a service.', $listProviderKey), $e->getCode(), $e);
        }

        if (!$listProvider instanceof ListProviderInterface) {
            throw new \InvalidArgumentException(sprintf('List Provider "%s" should implement Welp\MailchimpBundle\Provider\ListProviderInterface.', $listProviderKey));
        }

        $list = $listProvider->getList($listId);

        // Check the webhook_secret
        $authorized = false;
        if($list != null && $list->getWebhookSecret() == $hooksecret) {
            $authorized = true;                           
        }

        if (!$authorized) {
            throw new AccessDeniedHttpException('Webhook secret mismatch!');
        }

        // Trigger the right event
        switch ($type) {
            case 'subscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_SUBSCRIBE, new WebhookEvent($data));
                break;
            case 'unsubscribe':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UNSUBSCRIBE, new WebhookEvent($data));
                break;
            case 'profile':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_PROFILE, new WebhookEvent($data));
                break;
            case 'cleaned':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CLEANED, new WebhookEvent($data));
                break;
            case 'upemail':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_UPEMAIL, new WebhookEvent($data));
                break;
            case 'campaign':
                $dispatcher = $this->get('event_dispatcher');
                $dispatcher->dispatch(WebhookEvent::EVENT_CAMPAIGN, new WebhookEvent($data));
                break;
            default:
                throw new AccessDeniedHttpException('type mismatch!');
                break;
        }

        return new JsonResponse([
            'type' => $type,
            'data' => $data,
        ]);
    }
1303268
public function render($view, $data = [])
    {
        $this->writeFile($view);
        $blade = new Blade($this->getViewPath(), $this->getCachePath());

        if (is_array($data)) {
            return $blade->view()->make($view, $data)->render();
        } else {
            throw new Exception('data pass into view must be an array.');
        }
    }
53444
public function call($method, array $data = null)
    {
        $options = $this->proxySettings + [
            CURLOPT_URL => $this->getUrl().'/'.$method,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => null,
            CURLOPT_POSTFIELDS => null,
            CURLOPT_TIMEOUT => 5,
        ];

        if ($data) {
            $options[CURLOPT_POST] = true;
            $options[CURLOPT_POSTFIELDS] = $data;
        }

        if (!empty($this->customCurlOptions) && is_array($this->customCurlOptions)) {
            $options += $this->customCurlOptions;
        }

        $response = self::jsonValidate($this->executeCurl($options), $this->returnArray);

        if ($this->returnArray) {
            if (!isset($response['ok'])) {
                throw new Exception($response['description'], $response['error_code']);
            }

            return $response['result'];
        }

        if (!$response->ok) {
            throw new Exception($response->description, $response->error_code);
        }

        return $response->result;
    }
342460
public function post($resource, $data = [])
    {
        $exec = $this->execute(Method::$HTTP_POST, $resource, ['json' => $data]);

        return $exec;
    }
162479
public function post($url, $data)
    {
        $request = $this->webclient->createRequest('POST', $url, array(
            'body' => $data,
        ));
        return $this->sendRequest($request);
    }
1278850
public function doPostRequest($uri, $data = null)
    {
        return $this->doRequest(Request::POST, $uri, $data);
    }