Dispatch a CalendarEvent and return a JSON Response of any events returned.

@param Request $request
@return Response
421997
public function loadCalendarAction(Request $request)
    {
        $startDatetime = new \DateTime();
        $startDatetime->setTimestamp($request->get('start'));
        
        $endDatetime = new \DateTime();
        $endDatetime->setTimestamp($request->get('end'));
        
        $events = $this->container->get('event_dispatcher')->dispatch(CalendarEvent::CONFIGURE, new CalendarEvent($startDatetime, $endDatetime, $request))->getEvents();
        
        $response = new \Symfony\Component\HttpFoundation\Response();
        $response->headers->set('Content-Type', 'application/json');
        
        $return_events = array();
        
        foreach($events as $event) {
            $return_events[] = $event->toArray();    
        }
        
        $response->setContent(json_encode($return_events));
        
        return $response;
    }
409517
public function indexAction(Request $request)
    {
        $dispatcher = $this->get('event_dispatcher');
        $event = new ResponseEvent($request);
        $dispatcher->dispatch(OpiferMediaEvents::MEDIA_CONTROLLER_INDEX, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        $providers = $this->get('opifer.media.provider.pool')->getProviders();

        return $this->render($this->container->getParameter('opifer_media.media_index_view'), [
            'providers' => $providers,
        ]);
    }
1198683
public function dispatchToRoute(Request $request)
    {
        // First we will find a route that matches this request. We will also set the
        // route resolver on the request so middlewares assigned to the route will
        // receive access to this route instance for checking of the parameters.
        $route = $this->findRoute($request);
        $request->setRouteResolver(function () use ($route) {
            return $route;
        });
        $this->events->fire('router.matched', [$route, $request]);
        
        if (is_null($response)) {
            $response = $this->runRouteWithinStack(
                $route, $request
            );
        }
        
        return $this->prepareResponse($request, $response);
    }
882230
public function httpPost(Request $request) : Response
    {
        $response = new Response();
        $response->headers->set('Content-Type', 'application/json');

        $response->setContent(
            $this->sdkEndpoint->index(
                $request->getContent()
            )
        );

        return $response;
    }
784117
private function filterRequest(Request $request)
    {
        $event = $this->eventDispatcher->raiseEvent(new FilterRequestEvent($request));
        if ($event->hasResponse()) {
            $rsp = $event->getResponse();
            if ($rsp instanceof Response) {
                $this->eventDispatcher->raiseEvent(new FilterResponseEvent($request, $rsp));

                return $rsp;
            } elseif ($rsp instanceof Request) {
                $this->guardAgainstInfiniteRedirection($request, $rsp);

                return $this->dispatch($rsp);
            }
        }

        //The event handlers did not return a Request or a Response so invoke the controller
        $response = $this->controllerDispatcher->runController($request);
        $this->eventDispatcher->raiseEvent(new FilterResponseEvent($request, $response));

        return $response;
    }
71225
private function _dispatchRequest($request)
	{
		// track the number of requests across instances
		self::$requestCount++;
		$timestart = microtime(true);

		$response = self::transport()->send($request);

		// pass the response through the filter chain
		foreach($this->_filters as $filter)
		{
			$response = $filter->response($response);
		}

		$httpCode = $response->getStatus()->getCode();
		$location = $response->getHeaders()->value('Location');
		$body = $response->getBody();

		// track the time taken across instances
		self::$requestTime += microtime(true) - $timestart;

		// process a redirect if needed
		if($httpCode < 400 && $location)
		{
			return $this->_redirect($location);
		}
		else
		{
			$this->_redirects = 0;
		}

		// translate error code to a typed exception
		if($httpCode == 500)
		{
			throw new Error\InternalServerError($body);
		}
		elseif($httpCode == 400)
		{
			throw new Error\BadRequest($body);
		}
		elseif($httpCode == 401)
		{
			throw new Error\Unauthorized($body);
		}
		elseif($httpCode == 404)
		{
			throw new Error\NotFound($body);
		}
		else if($httpCode >= 300)
		{
			throw new Error($body,$httpCode);
		}

		return $response;
	}
1155165
public function userActionsListAction(Request $request)
    {
        $query = $this->addOrganizationFilter($request->query->all());
        $userList = $this->logManager->getUserActionsList($query);

        return new JsonResponse($userList);
    }
356015
public function render($request)
    {
        if ($request->wantsJson()) {
            return $this->validInternalServerErrorJsonResponse($this, $this->message);
        } else {
            return redirect()->back()->with(['rafflesargentina.status.error' => $this->message]);
        }
    }
476941
public function show(CalendarRequest $request, Calendar $calendar)
    {

        if ($calendar->exists) {
            $view = 'calendar::calendar.show';
        } else {
            $view = 'calendar::calendar.new';
        }

        return $this->response
            ->title(trans('app.view') . ' ' . trans('calendar::calendar.name'))
            ->data(compact('calendar'))
            ->view($view, true)
            ->output();
    }
982975
public function shadedevents($request, $json=true, $calendars = null, $offset=3000)
    {
        if (!$calendars) {
            $calendars = PublicCalendar::get();
        }
        $calendars = $calendars->filter(array(
            'shaded' => true
        ));

        return $this->publicevents($request, $json, $calendars, $offset);
    }
484882
public function dispatch(Request $request)
    {
        $oldRequest = $this->container->setInstance($request);

        ob_start();
        $response = $this->filterRequest($request);
        $response->addContent(ob_get_clean());

        if ($oldRequest) {
            $this->container->setInstance($oldRequest);
        }

        return $response;
    }
506813
public function ajaxAction(Request $request)
    {
        $parentId = $request->query->get('id');
        $entityName = $request->query->get('entityName');
        $currentId = $request->query->get('currentId');

        $em = $this->getDoctrine()->getManager();
        $filter = array(
            'parent' => null,
        );

        if (intval($parentId)) {
            $filter['parent'] = $em->getReference($entityName, (int) $parentId);
        }

        $items = $this->getDoctrine()
            ->getRepository($entityName)
            ->findBy($filter);

        $data = array_map(function (Taxonomy $item) use ($currentId) {
            return array(
                'id' => $item->getId(),
                'text' => $item->getNode()->getTitle(),
                'children' => true,
                'state' => array(
                    'disabled' => ($item->getId() != $currentId),
                ),
            );
        }, $items);

        if (!$currentId && is_null($filter['parent'])) {
            $data[] = array(
                'id' => 'current',
                'text' => 'New Item',
                'children' => false,
                'state' => array(
                    'disabled' => false,
                ),
            );
        }

        return new JsonResponse($data);
    }
663269
public function listJsonAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var \AdminBundle\Services\DataTables\JsonList $jsonList */
        $jsonList = $this->get('json_list');
        $jsonList->setRepository($em->getRepository('CoreBundle:Page'));
        $jsonList->setLocale($request->getLocale());
        $response = $jsonList->get();
        

        return new JsonResponse($response);
    }
1167979
public function destroy(CalendarRequest $request, Calendar $calendar)
    {

        try {

            $t = $calendar->delete();

            return response()->json([
                'message'  => trans('messages.success.deleted', ['Module' => trans('calendar::calendar.name')]),
                'code'     => 202,
                'redirect' => trans_url('/admin/calendar/calendar/0'),
            ], 202);

        } catch (Exception $e) {

            return response()->json([
                'message'  => $e->getMessage(),
                'code'     => 400,
                'redirect' => trans_url('/admin/calendar/calendar/' . $calendar->getRouteKey()),
            ], 400);
        }

    }
364037
protected function getCallbackFromRequest(Request $request)
    {
        $response = new JsonResponse('');
        $response->setCallback($request->query->get(self::PARAMETER_CALLBACK));

        return $response->getCallback();
    }
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);
    }
  }
633397
public function processHookAction(Request $request)
    {
        /** @var LoggerInterface $logger */
        $logger = $this->get('logger');

        $body = $request->getContent();
        $logger->info('Received sendgrid webhook '.$body);

        $events = json_decode($body, true);

        if ($events === false || $events === null) {
            $logger->error('Unable to decode sendgrid webhook. Body: '.$body);
            throw new BadRequestHttpException('Unabled to parse request body');
        }

        /** @var EventDispatcherInterface $dispatcher */
        $dispatcher = $this->get('event_dispatcher');

        foreach ($events as $eventData) {
            $type = 'sendgrid.'.$eventData['event'];
            $dispatcher->dispatch($type, new WebHookEvent($type, $eventData));
        }

        return new Response();
    }