Example #1
0
 /**
  * Rad\Network\Http\Response\JsonResponse constructor
  *
  * @param mixed  $content
  * @param int    $jsonOption
  * @param int    $status
  * @param string $reason
  * @param array  $headers
  */
 public function __construct($content, $jsonOption = 0, $status = 200, $reason = '', array $headers = [])
 {
     $content = json_encode($content, $jsonOption);
     $this->throwJsonException();
     $headers = $this->withContentType('application/json')->getHeaders();
     parent::__construct($content, $status, $reason, $headers);
 }
Example #2
0
 /**
  * Rad\Network\Http\Response\RedirectResponse constructor
  *
  * @param string $location
  * @param int    $status
  * @param string $reason
  * @param array  $headers
  */
 public function __construct($location, $status = 302, $reason = '', array $headers = [])
 {
     if ($status < 300 || $status > 308) {
         throw new InvalidArgumentException(sprintf('Invalid redirection status code "%s".', $status));
     }
     $headers = $this->withHeader('Location', $location)->getHeaders();
     parent::__construct(null, $status, $reason, $headers);
 }
Example #3
0
 /**
  * Twig\Library\TwigResponse constructor
  *
  * @param string $templateName
  * @param array  $context
  * @param int    $status
  * @param string $reason
  * @param array  $headers
  *
  * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException
  */
 public function __construct($templateName, array $context = [], $status = 200, $reason = '', array $headers = [])
 {
     /** @var \Twig_Environment $twig */
     $twig = $this->getContainer()->get('twig');
     parent::__construct($twig->render($templateName, $context), $status, $reason, $headers);
 }
Example #4
0
 /**
  * Handle Web Request
  *
  * @param ServerRequestInterface $request
  *
  * @throws BaseException
  * @throws DependencyInjection\Exception\ServiceLockedException
  * @throws DependencyInjection\Exception\ServiceNotFoundException
  * @throws NotFoundException
  * @throws Response\Exception
  */
 public function handleWeb(ServerRequestInterface $request)
 {
     $this->container->set('request', $request);
     /** @var Router $router */
     $router = $this->container->get('router');
     $router->handle();
     $dispatcher = new Dispatcher();
     $response = $dispatcher->setAction($router->getAction())->setActionNamespace($router->getActionNamespace())->setBundle($router->getBundle())->setParams($router->getParams())->setResponderNamespace($router->getResponderNamespace())->setRouteMatched($router->isMatched())->dispatch($request);
     if (!$response instanceof Response) {
         $response = new Response();
     }
     $response->send();
 }