コード例 #1
0
ファイル: JsonResponse.php プロジェクト: radphp/network
 /**
  * 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);
 }
コード例 #2
0
ファイル: RedirectResponse.php プロジェクト: radphp/network
 /**
  * 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);
 }
コード例 #3
0
ファイル: TwigResponse.php プロジェクト: radphp/twig-bundle
 /**
  * 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);
 }
コード例 #4
0
ファイル: AbstractApplication.php プロジェクト: radphp/radphp
 /**
  * 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();
 }