Inheritance: use trait Webiny\Component\StdLib\StdObjectTrait
Esempio n. 1
0
 /**
  * Redirect the request to the given url.
  *
  * @param string|UrlObject $url
  * @param string|int|array $headers Headers that you wish to send with your request.
  * @param int              $redirectCode
  */
 protected static function httpRedirect($url, $headers = [], $redirectCode = 301)
 {
     $url = new UrlObject($url);
     $headers['Location'] = $url->val();
     $response = new Response('', $redirectCode, $headers);
     $response->sendHeaders();
 }
Esempio n. 2
0
 /**
  * Base constructor.
  *
  * @param string|array|ArrayObject $content     Json content.
  * @param array                    $headers     Headers to attach to the response.
  * @param bool                     $prettyPrint Should we use JSON_PRETTY_PRINT to nicely format the output.
  */
 public function __construct($content, $headers = [], $prettyPrint = false)
 {
     if (StdObjectWrapper::isArrayObject($content)) {
         $content = $this->jsonEncode($content->val(), $prettyPrint ? JSON_PRETTY_PRINT : 0);
     } else {
         if ($this->isArray($content) || $this->isObject($content)) {
             $content = $this->jsonEncode($content, $prettyPrint ? JSON_PRETTY_PRINT : 0);
         }
     }
     parent::__construct($content, 200, $headers);
     $this->setContentType('application/json');
 }
Esempio n. 3
0
 public function testCacheControl()
 {
     $response = Response::create();
     $this->assertInstanceOf('\\Webiny\\Component\\Http\\Response\\CacheControl', $response->cacheControl());
 }