4040use Config \App ;
4141use Config \Format ;
4242use CodeIgniter \HTTP \Exceptions \HTTPException ;
43-
44- /**
45- * Redirect exception
46- */
47- class RedirectException extends \Exception
48- {
49-
50- }
43+ use CodeIgniter \Pager \PagerInterface ;
5144
5245/**
5346 * Representation of an outgoing, getServer-side response.
@@ -310,8 +303,8 @@ public function getStatusCode(): int
310303 * provided status code; if none is provided, will
311304 * default to the IANA name.
312305 *
313- * @return self
314- * @throws \InvalidArgumentException For invalid status code arguments.
306+ * @return $this
307+ * @throws \CodeIgniter\HTTP\Exceptions\HTTPException For invalid status code arguments.
315308 */
316309 public function setStatusCode (int $ code , string $ reason = '' )
317310 {
@@ -383,6 +376,43 @@ public function setDate(\DateTime $date)
383376
384377 //--------------------------------------------------------------------
385378
379+ /**
380+ * Set the Link Header
381+ *
382+ * @param \CodeIgniter\Pager\PagerInterface $pager
383+ *
384+ * @see http://tools.ietf.org/html/rfc5988
385+ *
386+ * @return Response
387+ */
388+ public function setLink (PagerInterface $ pager )
389+ {
390+ $ links = '' ;
391+
392+ if ($ previous = $ pager ->getPreviousPageURI ())
393+ {
394+ $ links .= '< ' . $ pager ->getPageURI ($ pager ->getFirstPage ()) . '>; rel="first", ' ;
395+ $ links .= '< ' . $ previous . '>; rel="prev" ' ;
396+ }
397+
398+ if (($ next = $ pager ->getNextPageURI ()) && $ previous )
399+ {
400+ $ links .= ', ' ;
401+ }
402+
403+ if ($ next )
404+ {
405+ $ links .= '< ' . $ next . '>; rel="next", ' ;
406+ $ links .= '< ' . $ pager ->getPageURI ($ pager ->getLastPage ()) . '>; rel="last" ' ;
407+ }
408+
409+ $ this ->setHeader ('Link ' , $ links );
410+
411+ return $ this ;
412+ }
413+
414+ //--------------------------------------------------------------------
415+
386416 /**
387417 * Sets the Content Type header for this response with the mime type
388418 * and, optionally, the charset.
@@ -411,7 +441,7 @@ public function setContentType(string $mime, string $charset = 'UTF-8')
411441 /**
412442 * Converts the $body into JSON and sets the Content Type header.
413443 *
414- * @param $body
444+ * @param array|string $body
415445 *
416446 * @return $this
417447 */
@@ -428,13 +458,18 @@ public function setJSON($body)
428458 * Returns the current body, converted to JSON is it isn't already.
429459 *
430460 * @return mixed|string
461+ *
462+ * @throws \InvalidArgumentException If the body property is not array.
431463 */
432464 public function getJSON ()
433465 {
434466 $ body = $ this ->body ;
435467
436468 if ($ this ->bodyFormat !== 'json ' )
437469 {
470+ /**
471+ * @var Format $config
472+ */
438473 $ config = config (Format::class);
439474 $ formatter = $ config ->getFormatter ('application/json ' );
440475
@@ -449,7 +484,7 @@ public function getJSON()
449484 /**
450485 * Converts $body into XML, and sets the correct Content-Type.
451486 *
452- * @param $body
487+ * @param array|string $body
453488 *
454489 * @return $this
455490 */
@@ -466,13 +501,17 @@ public function setXML($body)
466501 * Retrieves the current body into XML and returns it.
467502 *
468503 * @return mixed|string
504+ * @throws \InvalidArgumentException If the body property is not array.
469505 */
470506 public function getXML ()
471507 {
472508 $ body = $ this ->body ;
473509
474510 if ($ this ->bodyFormat !== 'xml ' )
475511 {
512+ /**
513+ * @var Format $config
514+ */
476515 $ config = config (Format::class);
477516 $ formatter = $ config ->getFormatter ('application/xml ' );
478517
@@ -488,10 +527,11 @@ public function getXML()
488527 * Handles conversion of the of the data into the appropriate format,
489528 * and sets the correct Content-Type header for our response.
490529 *
491- * @param $body
492- * @param string $format Valid: json, xml
530+ * @param string|array $body
531+ * @param string $format Valid: json, xml
493532 *
494533 * @return mixed
534+ * @throws \InvalidArgumentException If the body property is not string or array.
495535 */
496536 protected function formatBody ($ body , string $ format )
497537 {
@@ -502,6 +542,9 @@ protected function formatBody($body, string $format)
502542 // Nothing much to do for a string...
503543 if (! is_string ($ body ))
504544 {
545+ /**
546+ * @var Format $config
547+ */
505548 $ config = config (Format::class);
506549 $ formatter = $ config ->getFormatter ($ mime );
507550
@@ -718,7 +761,7 @@ public function getBody()
718761 * @param integer $code The type of redirection, defaults to 302
719762 *
720763 * @return $this
721- * @throws \CodeIgniter\HTTP\RedirectException
764+ * @throws \CodeIgniter\HTTP\Exceptions\HTTPException For invalid status code.
722765 */
723766 public function redirect (string $ uri , string $ method = 'auto ' , int $ code = null )
724767 {
@@ -775,6 +818,8 @@ public function redirect(string $uri, string $method = 'auto', int $code = null)
775818 * @param string $prefix Cookie name prefix
776819 * @param boolean|false $secure Whether to only transfer cookies via SSL
777820 * @param boolean|false $httponly Whether only make the cookie accessible via HTTP (no javascript)
821+ *
822+ * @return $this
778823 */
779824 public function setCookie (
780825 $ name ,
@@ -851,9 +896,9 @@ public function setCookie(
851896 /**
852897 * Checks to see if the Response has a specified cookie or not.
853898 *
854- * @param string $name
855- * @param null $value
856- * @param string $prefix
899+ * @param string $name
900+ * @param string| null $value
901+ * @param string $prefix
857902 *
858903 * @return boolean
859904 */
@@ -887,8 +932,8 @@ public function hasCookie(string $name, $value = null, string $prefix = '')
887932 /**
888933 * Returns the cookie
889934 *
890- * @param string $name
891- * @param string $prefix
935+ * @param string|null $name
936+ * @param string $prefix
892937 *
893938 * @return mixed
894939 */
@@ -924,12 +969,14 @@ public function getCookie(string $name = null, string $prefix = '')
924969 * @param string $domain
925970 * @param string $path
926971 * @param string $prefix
972+ *
973+ * @return $this
927974 */
928975 public function deleteCookie ($ name = '' , string $ domain = '' , string $ path = '/ ' , string $ prefix = '' )
929976 {
930977 if (empty ($ name ))
931978 {
932- return ;
979+ return $ this ;
933980 }
934981
935982 if ($ prefix === '' && $ this ->cookiePrefix !== '' )
@@ -989,6 +1036,8 @@ protected function sendCookies()
9891036 * @param string $filename The path to the file to send
9901037 * @param string $data The data to be downloaded
9911038 * @param boolean $setMime Whether to try and send the actual MIME type
1039+ *
1040+ * @return \CodeIgniter\HTTP\DownloadResponse|null
9921041 */
9931042 public function download (string $ filename = '' , $ data = '' , bool $ setMime = false )
9941043 {
0 commit comments