Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 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);
 }