Mark V
1: <?php
2: namespace MOC\V\Core\HttpKernel\Component\Bridge\Repository;
3:
4: use MOC\V\Core\HttpKernel\Component\Bridge\Bridge;
5: use MOC\V\Core\HttpKernel\Component\IBridgeInterface;
6: use MOC\V\Core\HttpKernel\Vendor\Universal\Request;
7:
8: /**
9: * Class UniversalRequest
10: *
11: * @package MOC\V\Core\HttpKernel\Component\Bridge
12: */
13: class UniversalRequest extends Bridge implements IBridgeInterface
14: {
15:
16: /** @var null|array $ParameterArray */
17: private static $ParameterArray = null;
18: /** @var Request $Instance */
19: private static $Instance = null;
20:
21: /**
22: *
23: */
24: public function __construct()
25: {
26:
27: if (null === self::$Instance) {
28: self::$Instance = new Request();
29: }
30: }
31:
32: /**
33: * Returns the root path from which this request is executed.
34: *
35: * Suppose that an index.php file instantiates this request object:
36: *
37: * - http://localhost/index.php returns an empty string
38: * - http://localhost/index.php/page returns an empty string
39: * - http://localhost/web/index.php returns '/web'
40: * - http://localhost/we%20b/index.php returns '/we%20b'
41: *
42: * @return string
43: */
44: public function getPathBase()
45: {
46:
47: return (string)self::$Instance->getSymfonyRequest()->getBasePath();
48: }
49:
50: /**
51: * Returns the path being requested relative to the executed script.
52: *
53: * The path info always starts with a /.
54: *
55: * Suppose this request is instantiated from /mysite on localhost:
56: *
57: * - http://localhost/mysite returns an empty string
58: * - http://localhost/mysite/about returns '/about'
59: * - http://localhost/mysite/enco%20ded returns '/enco%20ded'
60: * - http://localhost/mysite/about?var=1 returns '/about'
61: *
62: * @return string
63: */
64: public function getPathInfo()
65: {
66:
67: return (string)self::$Instance->getSymfonyRequest()->getPathInfo();
68: }
69:
70: /**
71: * Returns the root URL from which this request is executed.
72: *
73: * The base URL never ends with a /.
74: *
75: * This is similar to getPathBase(),
76: * except that it also includes the script filename (e.g. index.php) if one exists.
77: *
78: * @return string
79: */
80: public function getUrlBase()
81: {
82:
83: return (string)self::$Instance->getSymfonyRequest()->getBaseUrl();
84: }
85:
86: /**
87: * Returns the requested URI.
88: *
89: * @return string
90: */
91: public function getUrl()
92: {
93:
94: return (string)self::$Instance->getSymfonyRequest()->getRequestUri();
95: }
96:
97: /**
98: * Returns the port on which the request is made.
99: *
100: * This method can read the client port from the "X-Forwarded-Port" header,
101: * when trusted proxies were set via "setTrustedProxies()".
102: *
103: * The "X-Forwarded-Port" header must contain the client port.
104: *
105: * If your reverse proxy uses a different header name than "X-Forwarded-Port",
106: * configure it via "setTrustedHeaderName()" with the "client-port" key.
107: *
108: * @return string
109: */
110: public function getPort()
111: {
112:
113: return (string)self::$Instance->getSymfonyRequest()->getPort();
114: }
115:
116: /**
117: * Returns the host name.
118: *
119: * This method can read the client port from the "X-Forwarded-Host" header
120: * when trusted proxies were set via "setTrustedProxies()".
121: *
122: * The "X-Forwarded-Host" header must contain the client host name.
123: *
124: * If your reverse proxy uses a different header name than "X-Forwarded-Host",
125: * configure it via "setTrustedHeaderName()" with the "client-host" key.
126: *
127: * @return string
128: */
129: public function getHost()
130: {
131:
132: return (string)self::$Instance->getSymfonyRequest()->getHost();
133: }
134:
135: /**
136: * @return array
137: */
138: public function getParameterArray()
139: {
140:
141: if (null === self::$ParameterArray) {
142: self::$ParameterArray = array_merge(
143: $this->getRequestGETArray(),
144: $this->getRequestFILESArray(),
145: $this->getRequestPOSTArray(),
146: $this->getRequestCUSTOMArray()
147: );
148: }
149: return self::$ParameterArray;
150: }
151:
152: /**
153: * @return array
154: */
155: public function getRequestGETArray()
156: {
157:
158: return (array)self::$Instance->getSymfonyRequest()->query->all();
159: }
160:
161: /**
162: * @return array
163: */
164: public function getRequestFILESArray()
165: {
166:
167: return (array)self::$Instance->getSymfonyRequest()->files->all();
168: }
169:
170: /**
171: * @return array
172: */
173: public function getRequestPOSTArray()
174: {
175:
176: return (array)self::$Instance->getSymfonyRequest()->request->all();
177: }
178:
179: /**
180: * @return array
181: */
182: public function getRequestCUSTOMArray()
183: {
184:
185: return (array)self::$Instance->getSymfonyRequest()->attributes->all();
186: }
187: }
188: