PageRenderTime 23ms CodeModel.GetById 20ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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