PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/vnsoftdev/amms
PHP | 177 lines | 69 code | 24 blank | 84 comment | 3 complexity | 53a6f48ec5571962488be2089e156dd4 MD5 | raw file
  1<?php
  2
  3namespace YOOtheme\Framework\Routing;
  4
  5class Request
  6{
  7    /**
  8     * @var ParameterBag
  9     */
 10    public $attributes;
 11
 12    /**
 13     * @var ParameterBag
 14     */
 15    public $request;
 16
 17    /**
 18     * @var ParameterBag
 19     */
 20    public $server;
 21
 22    /**
 23     * @var ParameterBag
 24     */
 25    public $cookies;
 26
 27    /**
 28     * @var HeaderBag
 29     */
 30    public $headers;
 31
 32    /**
 33     * @var string
 34     */
 35    protected $baseUrl;
 36
 37    /**
 38     * @var string
 39     */
 40    protected $basePath;
 41
 42    /**
 43     * @var string
 44     */
 45    protected $baseRoute;
 46
 47    /**
 48     * Constructor.
 49     *
 50     * @param string $baseUrl
 51     * @param string $basePath
 52     * @param string $baseRoute
 53     * @param array  $request
 54     * @param array  $server
 55     */
 56    public function __construct($baseUrl, $basePath, $baseRoute, array $request = array(), array $server = array(), array $cookies = array())
 57    {
 58        $this->baseUrl    = $baseUrl;
 59        $this->basePath   = $basePath;
 60        $this->baseRoute  = $baseRoute;
 61        $this->attributes = new ParameterBag;
 62        $this->request    = new ParameterBag($request ?: $_REQUEST);
 63        $this->cookies    = new ParameterBag($cookies ?: $_COOKIE);
 64        $this->server     = new ServerBag($server ?: $_SERVER);
 65        $this->headers    = new HeaderBag($this->server->getHeaders());
 66
 67        // decode json content type
 68        if (stripos($this->headers->get('CONTENT_TYPE'), 'application/json') !== false) {
 69            if ($json = json_decode(@file_get_contents('php://input'), true)) {
 70                $this->request->add($json);
 71            }
 72        }
 73    }
 74
 75    /**
 76     * Gets the base URL.
 77     *
 78     * @return string
 79     */
 80    public function getBaseUrl()
 81    {
 82        return $this->baseUrl;
 83    }
 84
 85    /**
 86     * Sets the base URL.
 87     *
 88     * @param  string $baseUrl
 89     * @return self
 90     */
 91    public function setBaseUrl($baseUrl)
 92    {
 93        $this->baseUrl = $baseUrl;
 94
 95        return $this;
 96    }
 97
 98    /**
 99     * Gets the base path.
100     *
101     * @return string
102     */
103    public function getBasePath()
104    {
105        return $this->basePath;
106    }
107
108    /**
109     * Sets the base path.
110     *
111     * @param  string $basePath
112     * @return self
113     */
114    public function setBasePath($basePath)
115    {
116        $this->basePath = $basePath;
117
118        return $this;
119    }
120
121    /**
122     * Gets the base route.
123     *
124     * @return string
125     */
126    public function getBaseRoute()
127    {
128        return $this->baseRoute;
129    }
130
131    /**
132     * Sets the base route.
133     *
134     * @param  string $baseRoute
135     * @return self
136     */
137    public function setBaseRoute($baseRoute)
138    {
139        $this->baseRoute = $baseRoute;
140
141        return $this;
142    }
143
144    /**
145     * Gets the HTTP method.
146     *
147     * @return string
148     */
149    public function getMethod()
150    {
151        $method = $this->server->get('REQUEST_METHOD', 'GET');
152        $method = $this->headers->get('X-HTTP-Method-Override', $method);
153
154        return strtoupper($method);
155    }
156
157    /**
158     * Checks if this is an XHR request.
159     *
160     * @return bool
161     */
162    public function isXhr()
163    {
164        return $this->server->get('X_REQUESTED_WITH') == 'XMLHttpRequest';
165    }
166
167    /**
168     * Proxy method calls to request parameter bag.
169     *
170     * @param  string $method
171     * @param  array  $args
172     * @return mixed
173     */
174    public function __call($method, $args) {
175        return call_user_func_array(array($this->request, $method), $args);
176    }
177}