/administrator/components/com_widgetkit/vendor/yootheme/framework/src/Routing/RedirectResponse.php

https://gitlab.com/vnsoftdev/amms · PHP · 64 lines · 37 code · 9 blank · 18 comment · 1 complexity · 8ec8100e60d51be43206f344069257b2 MD5 · raw file

  1. <?php
  2. namespace YOOtheme\Framework\Routing;
  3. class RedirectResponse extends Response
  4. {
  5. protected $targetUrl;
  6. /**
  7. * Constructor.
  8. *
  9. * @param string $url
  10. * @param int $status
  11. * @param array $headers
  12. */
  13. public function __construct($url, $status = 302, $headers = array())
  14. {
  15. parent::__construct('', $status, $headers);
  16. $this->setTargetUrl($url);
  17. }
  18. /**
  19. * Gets the target URL.
  20. *
  21. * @return string target URL
  22. */
  23. public function getTargetUrl()
  24. {
  25. return $this->targetUrl;
  26. }
  27. /**
  28. * Sets the redirect target URL of this response.
  29. *
  30. * @param string $url
  31. * @return RedirectResponse
  32. */
  33. public function setTargetUrl($url)
  34. {
  35. if (empty($url)) {
  36. throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
  37. }
  38. $this->targetUrl = $url;
  39. $this->setHeader('Location', $url);
  40. $this->setContent(
  41. sprintf('<!DOCTYPE html>
  42. <html>
  43. <head>
  44. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  45. <meta http-equiv="refresh" content="1;url=%1$s" />
  46. <title>Redirecting to %1$s</title>
  47. </head>
  48. <body>
  49. Redirecting to <a href="%1$s">%1$s</a>.
  50. </body>
  51. </html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')));
  52. return $this;
  53. }
  54. }