Passed
Branch 0.7.0 (a860c5)
by Alexander
02:46
created
src/components/Http/Contributors/Parameters.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -34,156 +34,156 @@
 block discarded – undo
34 34
  */
35 35
 class Parameters implements IteratorAggregate, Countable
36 36
 {
37
-	/**
38
-	 * Array parameters from the Server global.
39
-	 *
40
-	 * @var array $parameters
41
-	 */
42
-	protected $parameters = [];
37
+    /**
38
+     * Array parameters from the Server global.
39
+     *
40
+     * @var array $parameters
41
+     */
42
+    protected $parameters = [];
43 43
 
44
-	/**
45
-	 * Parameter Object Constructor.
46
-	 *
47
-	 * @param  array  $parameters
48
-	 *
49
-	 * @return array
50
-	 */
51
-	public function __construct(array $parameters = [])
52
-	{
53
-		$this->parameters = $parameters;
54
-	}
44
+    /**
45
+     * Parameter Object Constructor.
46
+     *
47
+     * @param  array  $parameters
48
+     *
49
+     * @return array
50
+     */
51
+    public function __construct(array $parameters = [])
52
+    {
53
+        $this->parameters = $parameters;
54
+    }
55 55
 
56
-	/**
57
-	 * Returns the parameters.
58
-	 * 
59
-	 * @return array
60
-	 */
61
-	public function all()
62
-	{
63
-		return $this->parameters;
64
-	}
56
+    /**
57
+     * Returns the parameters.
58
+     * 
59
+     * @return array
60
+     */
61
+    public function all()
62
+    {
63
+        return $this->parameters;
64
+    }
65 65
 
66
-	/**
67
-	 * Returns the parameter keys.
68
-	 * 
69
-	 * @return array
70
-	 */
71
-	public function keys()
72
-	{
73
-		return array_keys($this->parameters);
74
-	}
66
+    /**
67
+     * Returns the parameter keys.
68
+     * 
69
+     * @return array
70
+     */
71
+    public function keys()
72
+    {
73
+        return array_keys($this->parameters);
74
+    }
75 75
 
76
-	/**
77
-	 * Replaces the current parameters.
78
-	 * 
79
-	 * @param  array  $parameters
80
-	 * 
81
-	 * @return array
82
-	 */
83
-	public function replace(array $parameters = [])
84
-	{
85
-		$this->parameters = $parameters;
86
-	}
76
+    /**
77
+     * Replaces the current parameters.
78
+     * 
79
+     * @param  array  $parameters
80
+     * 
81
+     * @return array
82
+     */
83
+    public function replace(array $parameters = [])
84
+    {
85
+        $this->parameters = $parameters;
86
+    }
87 87
 
88
-	/**
89
-	 * Adds parameters.
90
-	 * 
91
-	 * @param  array  $parameters
92
-	 * 
93
-	 * @return array
94
-	 */
95
-	public function add(array $parameters = [])
96
-	{
97
-		$this->parameters = array_replace($this->parameters, $parameters);
98
-	}
88
+    /**
89
+     * Adds parameters.
90
+     * 
91
+     * @param  array  $parameters
92
+     * 
93
+     * @return array
94
+     */
95
+    public function add(array $parameters = [])
96
+    {
97
+        $this->parameters = array_replace($this->parameters, $parameters);
98
+    }
99 99
 
100
-	/**
101
-	 * Get a parameter array item.
102
-	 *
103
-	 * @param  string  $key
104
-	 * @param  string|null  $default  
105
-	 *
106
-	 * @return mixed
107
-	 */
108
-	public function get($key, $default = null)
109
-	{
110
-		if ($this->has($key)) {
111
-			return $this->parameters[$key];
112
-		}
100
+    /**
101
+     * Get a parameter array item.
102
+     *
103
+     * @param  string  $key
104
+     * @param  string|null  $default  
105
+     *
106
+     * @return mixed
107
+     */
108
+    public function get($key, $default = null)
109
+    {
110
+        if ($this->has($key)) {
111
+            return $this->parameters[$key];
112
+        }
113 113
 
114
-		return $default;
115
-	}
114
+        return $default;
115
+    }
116 116
 
117
-	/**
118
-	 * Check if a parameter array item exists.
119
-	 *
120
-	 * @param  string  $key
121
-	 *
122
-	 * @return mixed
123
-	 */
124
-	public function has($key)
125
-	{
126
-		return Arr::exists($this->parameters, $key);
127
-	}
117
+    /**
118
+     * Check if a parameter array item exists.
119
+     *
120
+     * @param  string  $key
121
+     *
122
+     * @return mixed
123
+     */
124
+    public function has($key)
125
+    {
126
+        return Arr::exists($this->parameters, $key);
127
+    }
128 128
 
129
-	/**
130
-	 * Set a parameter array item.
131
-	 *
132
-	 * @param  string  $key
133
-	 * @param  string  $value 
134
-	 *
135
-	 * @return mixed
136
-	 */
137
-	public function set($key, $value)
138
-	{
139
-		$this->parameters[$key] = $value;
140
-	}
129
+    /**
130
+     * Set a parameter array item.
131
+     *
132
+     * @param  string  $key
133
+     * @param  string  $value 
134
+     *
135
+     * @return mixed
136
+     */
137
+    public function set($key, $value)
138
+    {
139
+        $this->parameters[$key] = $value;
140
+    }
141 141
 
142
-	/**
143
-	 * Remove a parameter array item.
144
-	 *
145
-	 * @param  string  $key 
146
-	 *
147
-	 * @return void
148
-	 */
149
-	public function remove($key)
150
-	{
151
-		if ($this->has($key)) {
152
-			unset($this->parameters[$key]);
153
-		}
154
-	}
142
+    /**
143
+     * Remove a parameter array item.
144
+     *
145
+     * @param  string  $key 
146
+     *
147
+     * @return void
148
+     */
149
+    public function remove($key)
150
+    {
151
+        if ($this->has($key)) {
152
+            unset($this->parameters[$key]);
153
+        }
154
+    }
155 155
 
156
-	/*
156
+    /*
157 157
 	|-----------------------------------------------------------------
158 158
 	| IteratorAggregate Method
159 159
 	|-----------------------------------------------------------------
160 160
 	*/
161 161
 	
162
-	/**
163
-	 * Retrieve an external iterator.
164
-	 * 
165
-	 * @see    \IteratorAggregate::getIterator
166
-	 * 
167
-	 * @return new \ArrayIterator
168
-	 */
169
-	public function getIterator()
170
-	{
171
-		return new ArrayIterator($this->parameters);
172
-	}
162
+    /**
163
+     * Retrieve an external iterator.
164
+     * 
165
+     * @see    \IteratorAggregate::getIterator
166
+     * 
167
+     * @return new \ArrayIterator
168
+     */
169
+    public function getIterator()
170
+    {
171
+        return new ArrayIterator($this->parameters);
172
+    }
173 173
 	
174
-	/*
174
+    /*
175 175
 	|-----------------------------------------------------------------
176 176
 	| Countable Method
177 177
 	|-----------------------------------------------------------------
178 178
 	*/
179 179
 	
180
-	/**
181
-	 * Returns the number of parameters.
182
-	 * 
183
-	 * @return int The number of parameters
184
-	 */
185
-	public function count()
186
-	{
187
-		return count($this->parameters);
188
-	}
180
+    /**
181
+     * Returns the number of parameters.
182
+     * 
183
+     * @return int The number of parameters
184
+     */
185
+    public function count()
186
+    {
187
+        return count($this->parameters);
188
+    }
189 189
 }
190 190
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Contributors/Inputs.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -33,46 +33,46 @@  discard block
 block discarded – undo
33 33
 final class Inputs extends Parameters
34 34
 {
35 35
     /**
36
-	 * {@inheritdoc}
37
-	 */
38
-	public function all(string $key = null)
39
-	{
40
-		return parent::all($key);
36
+     * {@inheritdoc}
37
+     */
38
+    public function all(string $key = null)
39
+    {
40
+        return parent::all($key);
41 41
     }
42 42
     
43 43
     /**
44
-	 * {@inheritdoc}
45
-	 */
46
-	public function replace(array $inputs = [])
47
-	{
48
-		$this->parameters = [];
44
+     * {@inheritdoc}
45
+     */
46
+    public function replace(array $inputs = [])
47
+    {
48
+        $this->parameters = [];
49 49
         $this->add($inputs);
50
-	}
50
+    }
51 51
 
52
-	/**
53
-	 * Adds input values.
52
+    /**
53
+     * Adds input values.
54 54
      * 
55 55
      * @param  array  $inputs
56 56
      * 
57 57
      * @return mixed
58
-	 */
59
-	public function add(array $inputs = [])
60
-	{
58
+     */
59
+    public function add(array $inputs = [])
60
+    {
61 61
         foreach ($inputs as $key => $file) {
62 62
             $this->set($key, $file);
63 63
         }
64 64
     }
65 65
     
66 66
     /**
67
-	 * Gets a string input value by name.
68
-	 *
69
-	 * @param  string  $key
70
-	 * @param  string|null  $default  
71
-	 *
72
-	 * @return string|null
73
-	 */
74
-	public function get($key, $default = null)
75
-	{
67
+     * Gets a string input value by name.
68
+     *
69
+     * @param  string  $key
70
+     * @param  string|null  $default  
71
+     *
72
+     * @return string|null
73
+     */
74
+    public function get($key, $default = null)
75
+    {
76 76
         if (null !== $default && ! is_scalar($default) && ! (is_object($default)) && ! method_exist($default, '__toString')) {
77 77
             throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__));
78 78
         }
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
     }
88 88
     
89 89
     /**
90
-	 * Sets an input by name.
91
-	 *
92
-	 * @param  string  $key
93
-	 * @param  string|array|null  $value 
94
-	 *
95
-	 * @return mixed
96
-	 */
97
-	public function set($key, $value)
98
-	{
90
+     * Sets an input by name.
91
+     *
92
+     * @param  string  $key
93
+     * @param  string|array|null  $value 
94
+     *
95
+     * @return mixed
96
+     */
97
+    public function set($key, $value)
98
+    {
99 99
         if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! method_exist($value, '__toString')) {
100 100
             throw new BadRequestHttpException(sprintf('Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string, array, or null instead', get_debug_type($value), __METHOD__));
101 101
         }
102 102
 
103
-		$this->parameters[$key] = $value;
104
-	}
103
+        $this->parameters[$key] = $value;
104
+    }
105 105
 }
106 106
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Contributors/Headers.php 1 patch
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -33,236 +33,236 @@
 block discarded – undo
33 33
  */
34 34
 class Headers implements IteratorAggregate, Countable
35 35
 {
36
-	/**
37
-	 * An array of HTTP headers.
38
-	 * 
39
-	 * @var array $herders
40
-	 */
41
-	protected $headers = [];
36
+    /**
37
+     * An array of HTTP headers.
38
+     * 
39
+     * @var array $herders
40
+     */
41
+    protected $headers = [];
42 42
 	
43
-	/**
44
-	 * Specifies the directives for the caching mechanisms in both
45
-	 * the requests and the responses.
46
-	 * 
47
-	 * @var array $cacheControl
48
-	 */
49
-	protected $cacheControl = [];
43
+    /**
44
+     * Specifies the directives for the caching mechanisms in both
45
+     * the requests and the responses.
46
+     * 
47
+     * @var array $cacheControl
48
+     */
49
+    protected $cacheControl = [];
50 50
 	
51
-	/**
52
-	 * Constructor. The Headers class instance.
53
-	 * 
54
-	 * @param  array  $headers
55
-	 * 
56
-	 * @return void
57
-	 */
58
-	public function __construct(array $headers = [])
59
-	{
60
-		foreach ($headers as $key => $values) {
61
-			$this->set($key, $values);
62
-		}
63
-	}
51
+    /**
52
+     * Constructor. The Headers class instance.
53
+     * 
54
+     * @param  array  $headers
55
+     * 
56
+     * @return void
57
+     */
58
+    public function __construct(array $headers = [])
59
+    {
60
+        foreach ($headers as $key => $values) {
61
+            $this->set($key, $values);
62
+        }
63
+    }
64 64
 	
65
-	/**
66
-	 * Returns all the headers.
67
-	 * 
68
-	 * @return array
69
-	 */
70
-	public function all()
71
-	{
72
-		return $this->headers;
73
-	}
65
+    /**
66
+     * Returns all the headers.
67
+     * 
68
+     * @return array
69
+     */
70
+    public function all()
71
+    {
72
+        return $this->headers;
73
+    }
74 74
 	
75
-	/**
76
-	 * Returns the parameter keys.
77
-	 * 
78
-	 * @return array An array of parameter keys
79
-	 */
80
-	public function keys()
81
-	{
82
-		return array_keys($this->all());
83
-	}
75
+    /**
76
+     * Returns the parameter keys.
77
+     * 
78
+     * @return array An array of parameter keys
79
+     */
80
+    public function keys()
81
+    {
82
+        return array_keys($this->all());
83
+    }
84 84
 	
85
-	/**
86
-	 * Replaces the current HTTP headers by a new set.
87
-	 * 
88
-	 * @param  array  $headers
89
-	 * 
90
-	 * @return void
91
-	 */
92
-	public function replace(array $headers = [])
93
-	{
94
-		$this->headers = [];
95
-		$this->add($headers);
96
-	}
85
+    /**
86
+     * Replaces the current HTTP headers by a new set.
87
+     * 
88
+     * @param  array  $headers
89
+     * 
90
+     * @return void
91
+     */
92
+    public function replace(array $headers = [])
93
+    {
94
+        $this->headers = [];
95
+        $this->add($headers);
96
+    }
97 97
 	
98
-	/**
99
-	 * Adds multiple header to the queue.
100
-	 * 
101
-	 * @param  array  $headers  The header name
102
-	 * 
103
-	 * @return mixed
104
-	 */
105
-	public function add(array $headers)
106
-	{
107
-		foreach ($headers as $key => $values) {
108
-			$this->set($key, $values);
109
-		}
98
+    /**
99
+     * Adds multiple header to the queue.
100
+     * 
101
+     * @param  array  $headers  The header name
102
+     * 
103
+     * @return mixed
104
+     */
105
+    public function add(array $headers)
106
+    {
107
+        foreach ($headers as $key => $values) {
108
+            $this->set($key, $values);
109
+        }
110 110
 		
111
-		return $this;
112
-	}
111
+        return $this;
112
+    }
113 113
 	
114
-	/**
115
-	 * Returns the headers, with original capitalizations.
116
-	 * 
117
-	 * @return array An array of headers
118
-	 */
119
-	public function allPreserveCase()
120
-	{
121
-		$headers = [];
114
+    /**
115
+     * Returns the headers, with original capitalizations.
116
+     * 
117
+     * @return array An array of headers
118
+     */
119
+    public function allPreserveCase()
120
+    {
121
+        $headers = [];
122 122
 		
123
-		foreach ($this->all() as $name => $value) {
124
-			$headers[$name] = $value;
125
-		}
123
+        foreach ($this->all() as $name => $value) {
124
+            $headers[$name] = $value;
125
+        }
126 126
 		
127
-		return $headers;
128
-	}
127
+        return $headers;
128
+    }
129 129
 	
130
-	/**
131
-	 * Gets a header value by name.
132
-	 *
133
-	 * @param  string  $key  The header name, or null for all headers
134
-	 * @param  string|null  $default  The default value
135
-	 * @param  bool  $option  Whether to return the option value or all header values
136
-	 *
137
-	 * @return mixed
138
-	 */
139
-	public function get($key, $default =  null, $option = true)
140
-	{
141
-		$key = str_replace('_', '-', strtolower($key));
130
+    /**
131
+     * Gets a header value by name.
132
+     *
133
+     * @param  string  $key  The header name, or null for all headers
134
+     * @param  string|null  $default  The default value
135
+     * @param  bool  $option  Whether to return the option value or all header values
136
+     *
137
+     * @return mixed
138
+     */
139
+    public function get($key, $default =  null, $option = true)
140
+    {
141
+        $key = str_replace('_', '-', strtolower($key));
142 142
 		
143
-		$headers = $this->all();
143
+        $headers = $this->all();
144 144
 		
145
-		if ( ! array_key_exists($key, $headers)) {
146
-			if (null === $default) {
147
-				return $option ? null : [];
148
-			}
145
+        if ( ! array_key_exists($key, $headers)) {
146
+            if (null === $default) {
147
+                return $option ? null : [];
148
+            }
149 149
 			
150
-			return $option ? $default : [$default];
151
-		}
150
+            return $option ? $default : [$default];
151
+        }
152 152
 		
153
-		if ($option) {
154
-			return count($headers[$key]) ? $headers[$key][0] : $default;
155
-		}
153
+        if ($option) {
154
+            return count($headers[$key]) ? $headers[$key][0] : $default;
155
+        }
156 156
 		
157
-		return $headers[$key];
158
-	}
157
+        return $headers[$key];
158
+    }
159 159
 
160
-	/**
161
-	 * Sets a header by name.
162
-	 * 
163
-	 * @param  string  $key  The header name
164
-	 * @param  string  $values  The value or an array of values
165
-	 * @param  bool  $replace  If you want to replace the value exists by the header, 
166
-	 * 					       it is not overwritten / overwritten when it is false
167
-	 *
168
-	 * @return $this
169
-	 */
170
-	public function set($key, $values, $replace = true)
171
-	{
172
-		$key = str_replace('_', '-', strtolower($key));
160
+    /**
161
+     * Sets a header by name.
162
+     * 
163
+     * @param  string  $key  The header name
164
+     * @param  string  $values  The value or an array of values
165
+     * @param  bool  $replace  If you want to replace the value exists by the header, 
166
+     * 					       it is not overwritten / overwritten when it is false
167
+     *
168
+     * @return $this
169
+     */
170
+    public function set($key, $values, $replace = true)
171
+    {
172
+        $key = str_replace('_', '-', strtolower($key));
173 173
 
174
-		if (is_array($values)) {
175
-			$values = array_values($values);
174
+        if (is_array($values)) {
175
+            $values = array_values($values);
176 176
 
177
-			if (true === $replace || ! isset($this->headers[$key])) {
178
-				$this->headers[$key] = $values;
179
-			} else {
180
-				$this->headers[$key] = array_merge($this->headers[$key], $values);
181
-			}
182
-		} else {
183
-			if (true === $replace || ! isset($this->headers[$key])) {
184
-				$this->headers[$key] = [$values];
185
-			} else {
186
-				$this->headers[$key][] = $values;
187
-			}
188
-		}
177
+            if (true === $replace || ! isset($this->headers[$key])) {
178
+                $this->headers[$key] = $values;
179
+            } else {
180
+                $this->headers[$key] = array_merge($this->headers[$key], $values);
181
+            }
182
+        } else {
183
+            if (true === $replace || ! isset($this->headers[$key])) {
184
+                $this->headers[$key] = [$values];
185
+            } else {
186
+                $this->headers[$key][] = $values;
187
+            }
188
+        }
189 189
 
190
-		return $this;
191
-	}
190
+        return $this;
191
+    }
192 192
 
193
-	/**
194
-	 * Returns true if the HTTP header is defined.
195
-	 * 
196
-	 * @param  string  $key  The HTTP header
197
-	 * 
198
-	 * @return bool  true if the parameter exists, false otherwise
199
-	 */
200
-	public function has($key)
201
-	{
202
-		return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
203
-	}
193
+    /**
194
+     * Returns true if the HTTP header is defined.
195
+     * 
196
+     * @param  string  $key  The HTTP header
197
+     * 
198
+     * @return bool  true if the parameter exists, false otherwise
199
+     */
200
+    public function has($key)
201
+    {
202
+        return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
203
+    }
204 204
 
205
-	/**
206
-	 * Removes a header.
207
-	 * 
208
-	 * @param  string  $name  The header name
209
-	 * 
210
-	 * @return mixed
211
-	 */
212
-	public function remove($key)
213
-	{
214
-		$key = str_replace('_', '-', strtolower($key));
205
+    /**
206
+     * Removes a header.
207
+     * 
208
+     * @param  string  $name  The header name
209
+     * 
210
+     * @return mixed
211
+     */
212
+    public function remove($key)
213
+    {
214
+        $key = str_replace('_', '-', strtolower($key));
215 215
 
216
-		unset($this->headers[$key]);
216
+        unset($this->headers[$key]);
217 217
 
218
-		if ('cache-control' === $key) {
219
-			$this->cacheControl = [];
220
-		}
221
-	}
218
+        if ('cache-control' === $key) {
219
+            $this->cacheControl = [];
220
+        }
221
+    }
222 222
 	
223
-	/**
224
-	 * Returns an iterator for headers.
225
-	 * 
226
-	 * @return \ArrayIterator An \ArrayIterator instance
227
-	 */
228
-	public function getIterator()
229
-	{
230
-		return new ArrayIterator($this->headers);
231
-	}
223
+    /**
224
+     * Returns an iterator for headers.
225
+     * 
226
+     * @return \ArrayIterator An \ArrayIterator instance
227
+     */
228
+    public function getIterator()
229
+    {
230
+        return new ArrayIterator($this->headers);
231
+    }
232 232
 	
233
-	/**
234
-	 * Returns the number of headers.
235
-	 * 
236
-	 * @return int The number of headers
237
-	 */
238
-	public function count()
239
-	{
240
-		return count($this->headers);
241
-	}
233
+    /**
234
+     * Returns the number of headers.
235
+     * 
236
+     * @return int The number of headers
237
+     */
238
+    public function count()
239
+    {
240
+        return count($this->headers);
241
+    }
242 242
 	
243
-	/**
244
-	 * Returns the headers as a string.
245
-	 * 
246
-	 * @return string The headers
247
-	 */
248
-	public function __toString()
249
-	{
250
-		if ( ! $headers = $this->all()) {
251
-			return '';
252
-		}
243
+    /**
244
+     * Returns the headers as a string.
245
+     * 
246
+     * @return string The headers
247
+     */
248
+    public function __toString()
249
+    {
250
+        if ( ! $headers = $this->all()) {
251
+            return '';
252
+        }
253 253
 		
254
-		ksort($headers);
255
-		$max     = max(array_map('strlen', array_keys($headers))) + 1;
256
-		$content = '';
254
+        ksort($headers);
255
+        $max     = max(array_map('strlen', array_keys($headers))) + 1;
256
+        $content = '';
257 257
 		
258
-		foreach ($headers as $name => $values) {
259
-			$name = ucwords($name, '-');
258
+        foreach ($headers as $name => $values) {
259
+            $name = ucwords($name, '-');
260 260
 			
261
-			foreach ($values as $value) {
262
-				$content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
263
-			}
264
-		}
261
+            foreach ($values as $value) {
262
+                $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
263
+            }
264
+        }
265 265
 
266
-		return $content;
267
-	}
266
+        return $content;
267
+    }
268 268
 }
269 269
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Request.php 1 patch
Indentation   +850 added lines, -850 removed lines patch added patch discarded remove patch
@@ -40,868 +40,868 @@
 block discarded – undo
40 40
  */
41 41
 class Request
42 42
 {
43
-	/**
44
-	 * Holds the global active request instance.
45
-	 *
46
-	 * @var bool $requestURI
47
-	 */
48
-	protected static $requestURI;
49
-
50
-	/**
51
-	 * The base URL.
52
-	 * 
53
-	 * @var string $baseUrl
54
-	 */
55
-	protected $baseUrl;
56
-
57
-	/**
58
-	 * Gets cookies ($_COOKIE).
59
-	 * 
60
-	 * @var string $cookies
61
-	 */
62
-	public $cookies;
63
-
64
-	/**
65
-	 * Gets the string with format JSON.
66
-	 * 
67
-	 * @var string|resource|null $content
68
-	 */
69
-	protected $content;
70
-
71
-	/**
72
-	 * The default Locale this request.
73
-	 * 
74
-	 * @var string $defaultLocale
75
-	 */
76
-	protected $defaultLocale = 'en';
43
+    /**
44
+     * Holds the global active request instance.
45
+     *
46
+     * @var bool $requestURI
47
+     */
48
+    protected static $requestURI;
49
+
50
+    /**
51
+     * The base URL.
52
+     * 
53
+     * @var string $baseUrl
54
+     */
55
+    protected $baseUrl;
56
+
57
+    /**
58
+     * Gets cookies ($_COOKIE).
59
+     * 
60
+     * @var string $cookies
61
+     */
62
+    public $cookies;
63
+
64
+    /**
65
+     * Gets the string with format JSON.
66
+     * 
67
+     * @var string|resource|null $content
68
+     */
69
+    protected $content;
70
+
71
+    /**
72
+     * The default Locale this request.
73
+     * 
74
+     * @var string $defaultLocale
75
+     */
76
+    protected $defaultLocale = 'en';
77 77
 	
78
-	/**
79
-	 * Gets files request ($_FILES).
80
-	 * 
81
-	 * @var string $files
82
-	 */
83
-	public $files;
84
-
85
-	/**
86
-	 * The detected uri and server variables.
87
-	 * 
88
-	 * @var string $http
89
-	 */
90
-	protected $http;
91
-
92
-	/**
93
-	 * The decoded JSON content for the request.
94
-	 * 
95
-	 * @var \Syscodes\Http\Contributors\Parameters|null $json
96
-	 */
97
-	protected $json;
98
-
99
-	/**
100
-	 * The current language of the application.
101
-	 * 
102
-	 * @var string $languages
103
-	 */
104
-	protected $languages;
78
+    /**
79
+     * Gets files request ($_FILES).
80
+     * 
81
+     * @var string $files
82
+     */
83
+    public $files;
84
+
85
+    /**
86
+     * The detected uri and server variables.
87
+     * 
88
+     * @var string $http
89
+     */
90
+    protected $http;
91
+
92
+    /**
93
+     * The decoded JSON content for the request.
94
+     * 
95
+     * @var \Syscodes\Http\Contributors\Parameters|null $json
96
+     */
97
+    protected $json;
98
+
99
+    /**
100
+     * The current language of the application.
101
+     * 
102
+     * @var string $languages
103
+     */
104
+    protected $languages;
105 105
 	
106
-	/** 
107
-	 * The method name.
108
-	 * 
109
-	 * @var string $method
110
-	 */
111
-	protected $method;
112
-
113
-	/**
114
-	 * The path info of URL.
115
-	 * 
116
-	 * @var string $pathInfo
117
-	 */
118
-	protected $pathInfo;
119
-
120
-	/**
121
-	 * Request body parameters ($_POST).
122
-	 * 
123
-	 * @var \Syscodes\Http\Contributors\Parameters $request
124
-	 */
125
-	public $request;
126
-
127
-	/**
128
-	 * Get request URI.
129
-	 * 
130
-	 * @var string $requestToURI
131
-	 */
132
-	protected $requestToURI;
133
-
134
-	/**
135
-	 * The detected uri and server variables ($_FILES).
136
-	 * 
137
-	 * @var array $server
138
-	 */
139
-	public $server = [];
140
-
141
-	/** 
142
-	 * List of routes uri.
143
-	 *
144
-	 * @var string|array $uri 
145
-	 */
146
-	public $uri;
147
-
148
-	/**
149
-	 * Stores the valid locale codes.
150
-	 * 
151
-	 * @var array $validLocales
152
-	 */
153
-	protected $validLocales = [];
154
-
155
-	/**
156
-	 * Constructor: Create new the Request class.
157
-	 * 
158
-	 * @param  array  $request
159
-	 * @param  array  $cookies
160
-	 * @param  array  $files
161
-	 * @param  array  $server
162
-	 * @param  string|resource|null $content  
163
-	 * 
164
-	 * @return void
165
-	 */
166
-	public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
167
-	{
168
-		static::$requestURI = $this;
106
+    /** 
107
+     * The method name.
108
+     * 
109
+     * @var string $method
110
+     */
111
+    protected $method;
112
+
113
+    /**
114
+     * The path info of URL.
115
+     * 
116
+     * @var string $pathInfo
117
+     */
118
+    protected $pathInfo;
119
+
120
+    /**
121
+     * Request body parameters ($_POST).
122
+     * 
123
+     * @var \Syscodes\Http\Contributors\Parameters $request
124
+     */
125
+    public $request;
126
+
127
+    /**
128
+     * Get request URI.
129
+     * 
130
+     * @var string $requestToURI
131
+     */
132
+    protected $requestToURI;
133
+
134
+    /**
135
+     * The detected uri and server variables ($_FILES).
136
+     * 
137
+     * @var array $server
138
+     */
139
+    public $server = [];
140
+
141
+    /** 
142
+     * List of routes uri.
143
+     *
144
+     * @var string|array $uri 
145
+     */
146
+    public $uri;
147
+
148
+    /**
149
+     * Stores the valid locale codes.
150
+     * 
151
+     * @var array $validLocales
152
+     */
153
+    protected $validLocales = [];
154
+
155
+    /**
156
+     * Constructor: Create new the Request class.
157
+     * 
158
+     * @param  array  $request
159
+     * @param  array  $cookies
160
+     * @param  array  $files
161
+     * @param  array  $server
162
+     * @param  string|resource|null $content  
163
+     * 
164
+     * @return void
165
+     */
166
+    public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
167
+    {
168
+        static::$requestURI = $this;
169 169
 		
170
-		$this->initialize($request, $cookies, $files, $server, $content);
171
-
172
-		$this->detectURI(config('app.uriProtocol'), config('app.baseUrl'));
173
-
174
-		$this->detectLocale();
175
-	}
176
-
177
-	/**
178
-	 * Sets the parameters for this request.
179
-	 * 
180
-	 * @param  array  $request
181
-	 * @param  array  $cookies
182
-	 * @param  array  $files
183
-	 * @param  array  $server
184
-	 * 
185
-	 * @return void
186
-	 */
187
-	public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
188
-	{
189
-		$this->request      = new Parameters($request);
190
-		$this->cookies      = new Inputs($cookies);
191
-		$this->files        = new Files($files);
192
-		$this->server       = new Server($server);
193
-		$this->headers      = new Headers($this->server->all());
194
-
195
-		$this->uri          = new URI;
196
-		$this->http         = new Http;
197
-		$this->method       = null;
198
-		$this->baseUrl      = null;
199
-		$this->content      = $content;
200
-		$this->pathInfo     = null;
201
-		$this->languages    = null;
202
-		$this->validLocales = config('app.supportedLocales');
203
-	}
204
-
205
-	/**
206
-	 * Create a new Syscodes HTTP request from server variables.
207
-	 * 
208
-	 * @return static
209
-	 */
210
-	public static function capture()
211
-	{
212
-		return static::createFromRequest(static::createFromRequestGlobals());
213
-	}
214
-
215
-	/**
216
-	 * Creates an Syscodes request from of the Request class instance.
217
-	 * 
218
-	 * @param  \Syscodes\Http\Request  $request
219
-	 * 
220
-	 * @return static
221
-	 */
222
-	public static function createFromRequest($request)
223
-	{
224
-		$newRequest = (new static)->duplicate(
225
-			$request->request->all(), $request->cookies->all(), 
226
-			$request->files->all(), $request->server->all()
227
-		);
228
-
229
-		$newRequest->content = $request->content;
230
-
231
-		return $newRequest;
232
-	}
233
-
234
-	/**
235
-	 * Creates a new request with value from PHP's super global.
236
-	 * 
237
-	 * @return static
238
-	 */
239
-	public static function createFromRequestGlobals()
240
-	{
241
-		$request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER);
242
-
243
-		return $request;
244
-	}
245
-
246
-	/**
247
-	 * Creates a new request from a factory.
248
-	 * 
249
-	 * @param  array  $request
250
-	 * @param  array  $cookies
251
-	 * @param  array  $files
252
-	 * @param  array  $server
253
-	 * 
254
-	 * @return static
255
-	 */
256
-	protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = [])
257
-	{
258
-		if (self::$requestURI) {
259
-			$request = (self::$requestURI)($request, $cookies, $files, $server);
260
-
261
-			if ( ! $request instanceof self) {
262
-				throw new LogicException('The Request active must return an instance of Syscodes\Http\Request');
263
-			}
264
-
265
-			return $request;
266
-		}
267
-
268
-		return new static($request, $cookies, $files, $server);
269
-	}
270
-
271
-	/**
272
-	 * Clones a request and overrides some of its parameters.
273
-	 * 
274
-	 * @param  array  $request
275
-	 * @param  array  $cookies
276
-	 * @param  array  $files
277
-	 * @param  array  $server
278
-	 * 
279
-	 * @return static
280
-	 */
281
-	public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = [])
282
-	{
283
-		$duplicate = clone $this;
284
-
285
-		if (null !== $request) {
286
-			$duplicate->request = new Parameters($request);
287
-		}
288
-
289
-		if (null !== $cookies) {
290
-			$duplicate->cookies = new Inputs($cookies);
291
-		}
292
-
293
-		if (null !== $files) {
294
-			$duplicate->files = new Files($files);
295
-		}
296
-
297
-		if (null !== $server) {
298
-			$duplicate->server  = new Server($server);
299
-			$duplicate->headers = new Headers($duplicate->server->all());
300
-		}
301
-
302
-		$duplicate->uri          = new URI;
303
-		$duplicate->http         = new Http;
304
-		$duplicate->locale       = null;
305
-		$duplicate->method       = null;
306
-		$duplicate->baseUrl      = null;
307
-		$duplicate->pathInfo     = null;
308
-		$duplicate->validLocales = config('app.supportedLocales');
309
-
310
-		return $duplicate;		
311
-	}
312
-
313
-	/**
314
-	 * Returns the active request currently being used.
315
-	 *
316
-	 * @param  \Syscodes\Http\Request|bool|null  $request  Overwrite current request 
317
-	 *                                                     before returning, false prevents 
318
-	 *                                                     overwrite
319
-	 *
320
-	 * @return \Syscodes\Http\Request
321
-	 */
322
-	public static function active($request = false)
323
-	{
324
-		if ($request !== false) {
325
-			static::$requestURI = $request;
326
-		}
327
-
328
-		return static::$requestURI;
329
-	}
330
-
331
-	/**
332
-	 * Returns the desired segment, or $default if it does not exist.
333
-	 *
334
-	 * @param  int  $index  The segment number (1-based index)
335
-	 * @param  mixed  $default  Default value to return
336
-	 *
337
-	 * @return  string
338
-	 */
339
-	public function segment($index, $default = null)
340
-	{
341
-		if ($request = static::active()) {
342
-			return $request->uri->getSegment($index, $default);
343
-		}
344
-
345
-		return null;
346
-	}
347
-
348
-	/**
349
-	 * Returns all segments in an array. For total of segments
350
-	 * used the function PHP count().
351
-	 *
352
-	 * @return array
353
-	 */
354
-	public function segments()
355
-	{
356
-		if ($request = static::active()) {
357
-			return $request->uri->getSegments();
358
-		}
359
-
360
-		return null;
361
-	}
362
-
363
-	/**
364
-	 * Returns the total number of segment.
365
-	 *
366
-	 * @return int|null  
367
-	 */
368
-	public function totalSegments()
369
-	{
370
-		if ($request = static::active()) {
371
-			return $request->uri->getTotalSegments();
372
-		}
373
-
374
-		return null;
375
-	}
376
-
377
-	/**
378
-	 * Detects and returns the current URI based on a number of different server variables.
379
-	 * 
380
-	 * @param  string  $protocol
381
-	 * @param  string  $baseUrl
382
-	 * 
383
-	 * @return string
384
-	 */
385
-	protected function detectURI(string $protocol, string $baseUrl)
386
-	{
387
-		$this->uri->setPath($this->http->detectPath($protocol));
388
-
389
-		$baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl;
390
-
391
-		if ( ! empty($baseUrl)) {
392
-			$this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME));
393
-			$this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST));
394
-			$this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT));
395
-		} else {
396
-			if ( ! $this->http->isCli()) {
397
-				exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.');
398
-			}
399
-		}
400
-	}
401
-
402
-	/**
403
-	 * Handles setting up the locale, auto-detecting of language.
404
-	 * 
405
-	 * @return void
406
-	 */
407
-	public function detectLocale()
408
-	{
409
-		$this->languages = $this->defaultLocale = config('app.locale');
410
-
411
-		$this->setLocale($this->validLocales);
412
-	}
413
-
414
-	/**
415
-	 * Returns the default locale as set.
416
-	 * 
417
-	 * @return string
418
-	 */
419
-	public function getDefaultLocale()
420
-	{
421
-		return $this->defaultLocale;
422
-	}
423
-
424
-	/**
425
-	 * Gets the current locale, with a fallback to the default.
426
-	 * 
427
-	 * @return string 
428
-	 */
429
-	public function getLocale()
430
-	{
431
-		return $this->languages ?: $this->defaultLocale;
432
-	}
433
-
434
-	/**
435
-	 * Sets the locale string for this request.
436
-	 * 
437
-	 * @param  string  $locale
438
-	 * 
439
-	 * @return \Syscodes\Http\Request
440
-	 */
441
-	public function setLocale($locale)
442
-	{
443
-		if ( ! in_array($locale, $this->validLocales)) {
444
-			$locale = $this->defaultLocale;
445
-		}
170
+        $this->initialize($request, $cookies, $files, $server, $content);
171
+
172
+        $this->detectURI(config('app.uriProtocol'), config('app.baseUrl'));
173
+
174
+        $this->detectLocale();
175
+    }
176
+
177
+    /**
178
+     * Sets the parameters for this request.
179
+     * 
180
+     * @param  array  $request
181
+     * @param  array  $cookies
182
+     * @param  array  $files
183
+     * @param  array  $server
184
+     * 
185
+     * @return void
186
+     */
187
+    public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
188
+    {
189
+        $this->request      = new Parameters($request);
190
+        $this->cookies      = new Inputs($cookies);
191
+        $this->files        = new Files($files);
192
+        $this->server       = new Server($server);
193
+        $this->headers      = new Headers($this->server->all());
194
+
195
+        $this->uri          = new URI;
196
+        $this->http         = new Http;
197
+        $this->method       = null;
198
+        $this->baseUrl      = null;
199
+        $this->content      = $content;
200
+        $this->pathInfo     = null;
201
+        $this->languages    = null;
202
+        $this->validLocales = config('app.supportedLocales');
203
+    }
204
+
205
+    /**
206
+     * Create a new Syscodes HTTP request from server variables.
207
+     * 
208
+     * @return static
209
+     */
210
+    public static function capture()
211
+    {
212
+        return static::createFromRequest(static::createFromRequestGlobals());
213
+    }
214
+
215
+    /**
216
+     * Creates an Syscodes request from of the Request class instance.
217
+     * 
218
+     * @param  \Syscodes\Http\Request  $request
219
+     * 
220
+     * @return static
221
+     */
222
+    public static function createFromRequest($request)
223
+    {
224
+        $newRequest = (new static)->duplicate(
225
+            $request->request->all(), $request->cookies->all(), 
226
+            $request->files->all(), $request->server->all()
227
+        );
228
+
229
+        $newRequest->content = $request->content;
230
+
231
+        return $newRequest;
232
+    }
233
+
234
+    /**
235
+     * Creates a new request with value from PHP's super global.
236
+     * 
237
+     * @return static
238
+     */
239
+    public static function createFromRequestGlobals()
240
+    {
241
+        $request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER);
242
+
243
+        return $request;
244
+    }
245
+
246
+    /**
247
+     * Creates a new request from a factory.
248
+     * 
249
+     * @param  array  $request
250
+     * @param  array  $cookies
251
+     * @param  array  $files
252
+     * @param  array  $server
253
+     * 
254
+     * @return static
255
+     */
256
+    protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = [])
257
+    {
258
+        if (self::$requestURI) {
259
+            $request = (self::$requestURI)($request, $cookies, $files, $server);
260
+
261
+            if ( ! $request instanceof self) {
262
+                throw new LogicException('The Request active must return an instance of Syscodes\Http\Request');
263
+            }
264
+
265
+            return $request;
266
+        }
267
+
268
+        return new static($request, $cookies, $files, $server);
269
+    }
270
+
271
+    /**
272
+     * Clones a request and overrides some of its parameters.
273
+     * 
274
+     * @param  array  $request
275
+     * @param  array  $cookies
276
+     * @param  array  $files
277
+     * @param  array  $server
278
+     * 
279
+     * @return static
280
+     */
281
+    public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = [])
282
+    {
283
+        $duplicate = clone $this;
284
+
285
+        if (null !== $request) {
286
+            $duplicate->request = new Parameters($request);
287
+        }
288
+
289
+        if (null !== $cookies) {
290
+            $duplicate->cookies = new Inputs($cookies);
291
+        }
292
+
293
+        if (null !== $files) {
294
+            $duplicate->files = new Files($files);
295
+        }
296
+
297
+        if (null !== $server) {
298
+            $duplicate->server  = new Server($server);
299
+            $duplicate->headers = new Headers($duplicate->server->all());
300
+        }
301
+
302
+        $duplicate->uri          = new URI;
303
+        $duplicate->http         = new Http;
304
+        $duplicate->locale       = null;
305
+        $duplicate->method       = null;
306
+        $duplicate->baseUrl      = null;
307
+        $duplicate->pathInfo     = null;
308
+        $duplicate->validLocales = config('app.supportedLocales');
309
+
310
+        return $duplicate;		
311
+    }
312
+
313
+    /**
314
+     * Returns the active request currently being used.
315
+     *
316
+     * @param  \Syscodes\Http\Request|bool|null  $request  Overwrite current request 
317
+     *                                                     before returning, false prevents 
318
+     *                                                     overwrite
319
+     *
320
+     * @return \Syscodes\Http\Request
321
+     */
322
+    public static function active($request = false)
323
+    {
324
+        if ($request !== false) {
325
+            static::$requestURI = $request;
326
+        }
327
+
328
+        return static::$requestURI;
329
+    }
330
+
331
+    /**
332
+     * Returns the desired segment, or $default if it does not exist.
333
+     *
334
+     * @param  int  $index  The segment number (1-based index)
335
+     * @param  mixed  $default  Default value to return
336
+     *
337
+     * @return  string
338
+     */
339
+    public function segment($index, $default = null)
340
+    {
341
+        if ($request = static::active()) {
342
+            return $request->uri->getSegment($index, $default);
343
+        }
344
+
345
+        return null;
346
+    }
347
+
348
+    /**
349
+     * Returns all segments in an array. For total of segments
350
+     * used the function PHP count().
351
+     *
352
+     * @return array
353
+     */
354
+    public function segments()
355
+    {
356
+        if ($request = static::active()) {
357
+            return $request->uri->getSegments();
358
+        }
359
+
360
+        return null;
361
+    }
362
+
363
+    /**
364
+     * Returns the total number of segment.
365
+     *
366
+     * @return int|null  
367
+     */
368
+    public function totalSegments()
369
+    {
370
+        if ($request = static::active()) {
371
+            return $request->uri->getTotalSegments();
372
+        }
373
+
374
+        return null;
375
+    }
376
+
377
+    /**
378
+     * Detects and returns the current URI based on a number of different server variables.
379
+     * 
380
+     * @param  string  $protocol
381
+     * @param  string  $baseUrl
382
+     * 
383
+     * @return string
384
+     */
385
+    protected function detectURI(string $protocol, string $baseUrl)
386
+    {
387
+        $this->uri->setPath($this->http->detectPath($protocol));
388
+
389
+        $baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl;
390
+
391
+        if ( ! empty($baseUrl)) {
392
+            $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME));
393
+            $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST));
394
+            $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT));
395
+        } else {
396
+            if ( ! $this->http->isCli()) {
397
+                exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.');
398
+            }
399
+        }
400
+    }
401
+
402
+    /**
403
+     * Handles setting up the locale, auto-detecting of language.
404
+     * 
405
+     * @return void
406
+     */
407
+    public function detectLocale()
408
+    {
409
+        $this->languages = $this->defaultLocale = config('app.locale');
410
+
411
+        $this->setLocale($this->validLocales);
412
+    }
413
+
414
+    /**
415
+     * Returns the default locale as set.
416
+     * 
417
+     * @return string
418
+     */
419
+    public function getDefaultLocale()
420
+    {
421
+        return $this->defaultLocale;
422
+    }
423
+
424
+    /**
425
+     * Gets the current locale, with a fallback to the default.
426
+     * 
427
+     * @return string 
428
+     */
429
+    public function getLocale()
430
+    {
431
+        return $this->languages ?: $this->defaultLocale;
432
+    }
433
+
434
+    /**
435
+     * Sets the locale string for this request.
436
+     * 
437
+     * @param  string  $locale
438
+     * 
439
+     * @return \Syscodes\Http\Request
440
+     */
441
+    public function setLocale($locale)
442
+    {
443
+        if ( ! in_array($locale, $this->validLocales)) {
444
+            $locale = $this->defaultLocale;
445
+        }
446 446
 		
447
-		$this->languages = $locale;
448
-
449
-		try {
450
-		    if (class_exists('Locale', false)) {
451
-				Locale::setDefault($locale);
452
-			}
453
-		} catch (Exception $exception) {}
454
-
455
-		return $this;
456
-	}
457
-
458
-	/**
459
-	 * Returns the full request string.
460
-	 *
461
-	 * @return string|null  The Request string
462
-	 */
463
-	public function get() 
464
-	{
465
-		if ($request = static::active()) {
466
-			return $request->uri->get();
467
-		}
468
-
469
-		return null;
470
-	}
471
-
472
-	/**
473
-	 * Get the JSON payload for the request.
474
-	 * 
475
-	 * @param  string|null  $key  
476
-	 * @param  mixed  $default  
477
-	 * 
478
-	 * @return \Syscodes\Http\Contributors\Parameters|mixed
479
-	 */
480
-	public function json($key = null, $default = null)
481
-	{
482
-		if ( ! isset($this->json)) {
483
-			$this->json = new Parameters((array) json_decode($this->getContent(), true));
484
-		}
485
-
486
-		if (is_null($key)) {
487
-			return $this->json;
488
-		}
489
-
490
-		return Arr::get($this->json->all(), $key, $default);
491
-	}
492
-
493
-	/**
494
-	 * Set the JSON payload for the request
495
-	 * 
496
-	 * @param  \Syscodes\Http\Contributors\Parameters  $json
497
-	 * 
498
-	 * @return $this
499
-	 */
500
-	public function setJson($json)
501
-	{
502
-		$this->json = $json;
503
-
504
-		return $this;
505
-	}
506
-
507
-	/**
508
-	 * Returns whether this is an AJAX request or not.
509
-	 *
510
-	 * @return bool
511
-	 */
512
-	public function isXmlHttpRequest()
513
-	{
514
-		return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && 
515
-				strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest';
516
-	}
517
-
518
-	/**
519
-	 * Returns the input method used (GET, POST, DELETE, etc.).
520
-	 *
521
-	 * @return string
522
-	 * 
523
-	 * @throws \LogicException  
524
-	 */
525
-	public function getmethod()
526
-	{
527
-		if (null !== $this->method) {
528
-			return $this->method;
529
-		}
447
+        $this->languages = $locale;
448
+
449
+        try {
450
+            if (class_exists('Locale', false)) {
451
+                Locale::setDefault($locale);
452
+            }
453
+        } catch (Exception $exception) {}
454
+
455
+        return $this;
456
+    }
457
+
458
+    /**
459
+     * Returns the full request string.
460
+     *
461
+     * @return string|null  The Request string
462
+     */
463
+    public function get() 
464
+    {
465
+        if ($request = static::active()) {
466
+            return $request->uri->get();
467
+        }
468
+
469
+        return null;
470
+    }
471
+
472
+    /**
473
+     * Get the JSON payload for the request.
474
+     * 
475
+     * @param  string|null  $key  
476
+     * @param  mixed  $default  
477
+     * 
478
+     * @return \Syscodes\Http\Contributors\Parameters|mixed
479
+     */
480
+    public function json($key = null, $default = null)
481
+    {
482
+        if ( ! isset($this->json)) {
483
+            $this->json = new Parameters((array) json_decode($this->getContent(), true));
484
+        }
485
+
486
+        if (is_null($key)) {
487
+            return $this->json;
488
+        }
489
+
490
+        return Arr::get($this->json->all(), $key, $default);
491
+    }
492
+
493
+    /**
494
+     * Set the JSON payload for the request
495
+     * 
496
+     * @param  \Syscodes\Http\Contributors\Parameters  $json
497
+     * 
498
+     * @return $this
499
+     */
500
+    public function setJson($json)
501
+    {
502
+        $this->json = $json;
503
+
504
+        return $this;
505
+    }
506
+
507
+    /**
508
+     * Returns whether this is an AJAX request or not.
509
+     *
510
+     * @return bool
511
+     */
512
+    public function isXmlHttpRequest()
513
+    {
514
+        return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && 
515
+                strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest';
516
+    }
517
+
518
+    /**
519
+     * Returns the input method used (GET, POST, DELETE, etc.).
520
+     *
521
+     * @return string
522
+     * 
523
+     * @throws \LogicException  
524
+     */
525
+    public function getmethod()
526
+    {
527
+        if (null !== $this->method) {
528
+            return $this->method;
529
+        }
530 530
 		
531
-		$method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
531
+        $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
532 532
 		
533
-		if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {
534
-			return $this->method = $method;
535
-		}
533
+        if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {
534
+            return $this->method = $method;
535
+        }
536 536
 		
537
-		if ( ! preg_match('~^[A-Z]++$#~D', $method)) {
538
-			throw new logicException(sprintf('Invalid method override "%s"', $method));
539
-		}
540
-
541
-		return $this->method = $method;
542
-	}
543
-
544
-	/**
545
-	 * Sets the request method.
546
-	 *
547
-	 * @param  string  $method  
548
-	 *
549
-	 * @return string
550
-	 */
551
-	public function setMethod(string $method) 
552
-	{
553
-		$this->method = null;
554
-
555
-		$this->server->set('REQUEST_METHOD', $method);
556
-	}
537
+        if ( ! preg_match('~^[A-Z]++$#~D', $method)) {
538
+            throw new logicException(sprintf('Invalid method override "%s"', $method));
539
+        }
540
+
541
+        return $this->method = $method;
542
+    }
543
+
544
+    /**
545
+     * Sets the request method.
546
+     *
547
+     * @param  string  $method  
548
+     *
549
+     * @return string
550
+     */
551
+    public function setMethod(string $method) 
552
+    {
553
+        $this->method = null;
554
+
555
+        $this->server->set('REQUEST_METHOD', $method);
556
+    }
557 557
 	
558
-	/**
559
-	 * Determine if the current request URI matches a pattern.
560
-	 * 
561
-	 * @param  mixed  ...$patterns
562
-	 * 
563
-	 * @return bool
564
-	 */
565
-	public function is(...$patterns)
566
-	{
567
-		$path = $this->decodedPath();
558
+    /**
559
+     * Determine if the current request URI matches a pattern.
560
+     * 
561
+     * @param  mixed  ...$patterns
562
+     * 
563
+     * @return bool
564
+     */
565
+    public function is(...$patterns)
566
+    {
567
+        $path = $this->decodedPath();
568 568
 		
569
-		foreach ($patterns as $pattern) {
570
-			if (Str::is($pattern, $path)) {
571
-				return true;
572
-			}
573
-		}
574
-
575
-		return false;
576
-	}
577
-
578
-	/**
579
-	 * Determine if the route name matches a given pattern.
580
-	 * 
581
-	 * @param  mixed  ...$patterns
582
-	 * 
583
-	 * @return bool
584
-	 */
585
-	public function routeIs(...$patterns)
586
-	{
587
-		return $this->route() && $this->route()->is(...$patterns);
588
-	}
589
-
590
-	/**
591
-	 * Get the route handling the request.
592
-	 * 
593
-	 * @param  string|null  $param  
594
-	 * @param  mixed  $default  
595
-	 * 
596
-	 * @return \Syscodes\Routing\Route|object|string|null
597
-	 */
598
-	public function route($param = null, $default = null)
599
-	{
600
-		$route = $this->getRoute();
601
-
602
-		if (is_null($route) || is_null($param)) {
603
-			return $route;
604
-		}
605
-
606
-		return $route->parameter($param, $default);
607
-	}
608
-
609
-	/**
610
-	 * Get the current decoded path info for the request.
611
-	 * 
612
-	 * @return string
613
-	 */
614
-	public function decodedPath()
615
-	{
616
-		return rawurldecode($this->path());
617
-	}
618
-
619
-	/**
620
-	 * Get the current path info for the request.
621
-	 * 
622
-	 * @return string
623
-	 */
624
-	public function path()
625
-	{
626
-		$path = trim($this->getPathInfo(), '/');
627
-
628
-		return $path == '' ? '/' : $path;
629
-	}
630
-
631
-	/**
632
-	 * Retunrs the request body content.
633
-	 * 
634
-	 * @return string
635
-	 */
636
-	public function getContent()
637
-	{
638
-		if (null === $this->content || false === $this->content)
639
-		{
640
-			$this->content = file_get_contents('php://input');
641
-		}
642
-
643
-		return $this->content;
644
-	}
645
-
646
-	/**
647
-	 * Returns the path being requested relative to the executed script. 
648
-	 * 
649
-	 * @return string
650
-	 */
651
-	public function getPathInfo()
652
-	{
653
-		if (null === $this->pathInfo)
654
-		{
655
-			$this->pathInfo = $this->http->parsePathInfo();
656
-		}
657
-
658
-		return $this->pathInfo;
659
-	}
660
-
661
-	/**
662
-	 * Returns the root URL from which this request is executed.
663
-	 * 
664
-	 * @return string
665
-	 */
666
-	public function getBaseUrl()
667
-	{
668
-		if (null === $this->baseUrl)
669
-		{
670
-			$this->baseUrl = $this->http->parseBaseUrl();
671
-		}
672
-
673
-		return $this->baseUrl;
674
-	}
675
-
676
-	/**
677
-	 * Returns the requested URI.
678
-	 * 
679
-	 * @return string
680
-	 */
681
-	public function getRequestUri()
682
-	{
683
-		if (null === $this->requestToUri) {
684
-			$this->requestToUri = $this->http->parseRequestUri();
685
-		}
686
-
687
-		return $this->requestToUri;
688
-	}
569
+        foreach ($patterns as $pattern) {
570
+            if (Str::is($pattern, $path)) {
571
+                return true;
572
+            }
573
+        }
574
+
575
+        return false;
576
+    }
577
+
578
+    /**
579
+     * Determine if the route name matches a given pattern.
580
+     * 
581
+     * @param  mixed  ...$patterns
582
+     * 
583
+     * @return bool
584
+     */
585
+    public function routeIs(...$patterns)
586
+    {
587
+        return $this->route() && $this->route()->is(...$patterns);
588
+    }
589
+
590
+    /**
591
+     * Get the route handling the request.
592
+     * 
593
+     * @param  string|null  $param  
594
+     * @param  mixed  $default  
595
+     * 
596
+     * @return \Syscodes\Routing\Route|object|string|null
597
+     */
598
+    public function route($param = null, $default = null)
599
+    {
600
+        $route = $this->getRoute();
601
+
602
+        if (is_null($route) || is_null($param)) {
603
+            return $route;
604
+        }
605
+
606
+        return $route->parameter($param, $default);
607
+    }
608
+
609
+    /**
610
+     * Get the current decoded path info for the request.
611
+     * 
612
+     * @return string
613
+     */
614
+    public function decodedPath()
615
+    {
616
+        return rawurldecode($this->path());
617
+    }
618
+
619
+    /**
620
+     * Get the current path info for the request.
621
+     * 
622
+     * @return string
623
+     */
624
+    public function path()
625
+    {
626
+        $path = trim($this->getPathInfo(), '/');
627
+
628
+        return $path == '' ? '/' : $path;
629
+    }
630
+
631
+    /**
632
+     * Retunrs the request body content.
633
+     * 
634
+     * @return string
635
+     */
636
+    public function getContent()
637
+    {
638
+        if (null === $this->content || false === $this->content)
639
+        {
640
+            $this->content = file_get_contents('php://input');
641
+        }
642
+
643
+        return $this->content;
644
+    }
645
+
646
+    /**
647
+     * Returns the path being requested relative to the executed script. 
648
+     * 
649
+     * @return string
650
+     */
651
+    public function getPathInfo()
652
+    {
653
+        if (null === $this->pathInfo)
654
+        {
655
+            $this->pathInfo = $this->http->parsePathInfo();
656
+        }
657
+
658
+        return $this->pathInfo;
659
+    }
660
+
661
+    /**
662
+     * Returns the root URL from which this request is executed.
663
+     * 
664
+     * @return string
665
+     */
666
+    public function getBaseUrl()
667
+    {
668
+        if (null === $this->baseUrl)
669
+        {
670
+            $this->baseUrl = $this->http->parseBaseUrl();
671
+        }
672
+
673
+        return $this->baseUrl;
674
+    }
675
+
676
+    /**
677
+     * Returns the requested URI.
678
+     * 
679
+     * @return string
680
+     */
681
+    public function getRequestUri()
682
+    {
683
+        if (null === $this->requestToUri) {
684
+            $this->requestToUri = $this->http->parseRequestUri();
685
+        }
686
+
687
+        return $this->requestToUri;
688
+    }
689 689
 	
690
-	/**
691
-	 * Gets the request's scheme.
692
-	 * 
693
-	 * @return string
694
-	 */
695
-	public function getScheme()
696
-	{
697
-		return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http');
698
-	}
699
-
700
-	/**
701
-	 * Returns the host name.
702
-	 * 
703
-	 * @return void
704
-	 */
705
-	public function getHost()
706
-	{
707
-		if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) {
708
-			$host = $forawardedHost[0];
709
-		} elseif ( ! $host = $this->headers->get('HOST')) {
710
-			if ( ! $host = $this->server->get('SERVER_NAME')) {
711
-				$host = $this->server->get('REMOTE_ADDR', '');
712
-			}
713
-		}
714
-
715
-		$host = $_SERVER['SERVER_NAME'];
716
-
717
-		$host = strtolower(preg_replace('/:\d+$/', '', trim(($host))));
690
+    /**
691
+     * Gets the request's scheme.
692
+     * 
693
+     * @return string
694
+     */
695
+    public function getScheme()
696
+    {
697
+        return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http');
698
+    }
699
+
700
+    /**
701
+     * Returns the host name.
702
+     * 
703
+     * @return void
704
+     */
705
+    public function getHost()
706
+    {
707
+        if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) {
708
+            $host = $forawardedHost[0];
709
+        } elseif ( ! $host = $this->headers->get('HOST')) {
710
+            if ( ! $host = $this->server->get('SERVER_NAME')) {
711
+                $host = $this->server->get('REMOTE_ADDR', '');
712
+            }
713
+        }
714
+
715
+        $host = $_SERVER['SERVER_NAME'];
716
+
717
+        $host = strtolower(preg_replace('/:\d+$/', '', trim(($host))));
718 718
 		
719
-		return $host;
720
-	}
721
-
722
-	/**
723
-	 * Returns the port on which the request is made.
724
-	 * 
725
-	 * @return int
726
-	 */
727
-	public function getPort()
728
-	{
729
-		if ( ! $this->server->get('HTTP_HOST')) 
730
-		{
731
-			return $this->server->get('SERVER_PORT');
732
-		}
719
+        return $host;
720
+    }
721
+
722
+    /**
723
+     * Returns the port on which the request is made.
724
+     * 
725
+     * @return int
726
+     */
727
+    public function getPort()
728
+    {
729
+        if ( ! $this->server->get('HTTP_HOST')) 
730
+        {
731
+            return $this->server->get('SERVER_PORT');
732
+        }
733 733
 		
734
-		return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80);
735
-	}
736
-
737
-	/**
738
-	 * Returns the HTTP host being requested.
739
-	 * 
740
-	 * @return string
741
-	 */
742
-	public function getHttpHost()
743
-	{
744
-		$scheme = $this->getScheme();
745
-		$port   = $this->getPort();
746
-
747
-		if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))		
748
-		{
749
-			return $this->getHost();
750
-		}
751
-
752
-		return $this->getHost().':'.$port;
753
-	}
754
-
755
-	/**
756
-	 * Gets the scheme and HTTP host.
757
-	 * 
758
-	 * @return string
759
-	 */
760
-	public function getSchemeWithHttpHost()
761
-	{
762
-		return $this->getScheme().'://'.$this->getHttpHost();
763
-	}
764
-
765
-	/**
766
-	 * Get the root URL for the application.
767
-	 * 
768
-	 * @return string
769
-	 */
770
-	public function root()
771
-	{
772
-		return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/');
773
-	}
774
-
775
-	/**
776
-	 * Get the URL for the request.
777
-	 * 
778
-	 * @return string
779
-	 */
780
-	public function url()
781
-	{
782
-		return trim(preg_replace('/\?.*/', '', $this->get()), '/');
783
-	}
784
-
785
-	/**
786
-	 * Returns the referer.
787
-	 * 
788
-	 * @param  string  $default
789
-	 * 
790
-	 * @return string
791
-	 */
792
-	public function referer(string $default = '')
793
-	{
794
-		return $this->server->get('HTTP_REFERER', $default);
795
-	}
734
+        return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80);
735
+    }
736
+
737
+    /**
738
+     * Returns the HTTP host being requested.
739
+     * 
740
+     * @return string
741
+     */
742
+    public function getHttpHost()
743
+    {
744
+        $scheme = $this->getScheme();
745
+        $port   = $this->getPort();
746
+
747
+        if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))		
748
+        {
749
+            return $this->getHost();
750
+        }
751
+
752
+        return $this->getHost().':'.$port;
753
+    }
754
+
755
+    /**
756
+     * Gets the scheme and HTTP host.
757
+     * 
758
+     * @return string
759
+     */
760
+    public function getSchemeWithHttpHost()
761
+    {
762
+        return $this->getScheme().'://'.$this->getHttpHost();
763
+    }
764
+
765
+    /**
766
+     * Get the root URL for the application.
767
+     * 
768
+     * @return string
769
+     */
770
+    public function root()
771
+    {
772
+        return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/');
773
+    }
774
+
775
+    /**
776
+     * Get the URL for the request.
777
+     * 
778
+     * @return string
779
+     */
780
+    public function url()
781
+    {
782
+        return trim(preg_replace('/\?.*/', '', $this->get()), '/');
783
+    }
784
+
785
+    /**
786
+     * Returns the referer.
787
+     * 
788
+     * @param  string  $default
789
+     * 
790
+     * @return string
791
+     */
792
+    public function referer(string $default = '')
793
+    {
794
+        return $this->server->get('HTTP_REFERER', $default);
795
+    }
796 796
 	
797
-	/**
798
-	 * Attempts to detect if the current connection is secure through 
799
-	 * over HTTPS protocol.
800
-	 * 
801
-	 * @return bool
802
-	 */
803
-	public function secure()
804
-	{
805
-		if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') {
806
-			return true;
807
-		} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') {
808
-			return true;
809
-		} elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') {
810
-			return true;
811
-		}
812
-
813
-		return false;
814
-	}
815
-
816
-	/**
817
-	 * Returns the user agent.
818
-	 *
819
-	 * @param  string|null  $default
820
-	 *
821
-	 * @return string
822
-	 */
823
-	public function userAgent(string $default = null)
824
-	{
825
-		return $this->server->get('HTTP_USER_AGENT', $default);
826
-	}
827
-
828
-	/**
829
-	 * Get the route resolver.
830
-	 * 
831
-	 * @return \Syscodes\Routing\Router
832
-	 */
833
-	public function getRoute()
834
-	{
835
-		return app('router');
836
-	}
837
-
838
-	/**
839
-	 * Get an element from the request.
840
-	 * 
841
-	 * @return string[]
842
-	 */
843
-	public function __get($key)
844
-	{
845
-		$all = $this->server->all();
846
-
847
-		if (array_key_exists($key, $all)) {
848
-			return $all[$key];
849
-		} else {
850
-			return $key;
851
-		}
852
-	}
853
-
854
-	/**
855
-	 * Returns the Request as an HTTP string.
856
-	 * 
857
-	 * @return string
858
-	 */
859
-	public function __toString()
860
-	{
861
-		try
862
-		{
863
-			$content = $this->getContent();
864
-		}
865
-		catch (LogicException $e)
866
-		{
867
-			if (PHP_VERSION_ID > 70400)
868
-			{
869
-				throw $e;
870
-			}
871
-
872
-			return trigger_error($e, E_USER_ERROR);
873
-		}
874
-
875
-		$cookieHeader = '';
876
-		$cookies      = [];
877
-
878
-		foreach ($this->cookies as $key => $value)
879
-		{
880
-			$cookies[]= "{$key} = {$value}";
881
-		}
882
-
883
-		if ( ! empty($cookies))
884
-		{
885
-			$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
886
-		}
797
+    /**
798
+     * Attempts to detect if the current connection is secure through 
799
+     * over HTTPS protocol.
800
+     * 
801
+     * @return bool
802
+     */
803
+    public function secure()
804
+    {
805
+        if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') {
806
+            return true;
807
+        } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') {
808
+            return true;
809
+        } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') {
810
+            return true;
811
+        }
812
+
813
+        return false;
814
+    }
815
+
816
+    /**
817
+     * Returns the user agent.
818
+     *
819
+     * @param  string|null  $default
820
+     *
821
+     * @return string
822
+     */
823
+    public function userAgent(string $default = null)
824
+    {
825
+        return $this->server->get('HTTP_USER_AGENT', $default);
826
+    }
827
+
828
+    /**
829
+     * Get the route resolver.
830
+     * 
831
+     * @return \Syscodes\Routing\Router
832
+     */
833
+    public function getRoute()
834
+    {
835
+        return app('router');
836
+    }
837
+
838
+    /**
839
+     * Get an element from the request.
840
+     * 
841
+     * @return string[]
842
+     */
843
+    public function __get($key)
844
+    {
845
+        $all = $this->server->all();
846
+
847
+        if (array_key_exists($key, $all)) {
848
+            return $all[$key];
849
+        } else {
850
+            return $key;
851
+        }
852
+    }
853
+
854
+    /**
855
+     * Returns the Request as an HTTP string.
856
+     * 
857
+     * @return string
858
+     */
859
+    public function __toString()
860
+    {
861
+        try
862
+        {
863
+            $content = $this->getContent();
864
+        }
865
+        catch (LogicException $e)
866
+        {
867
+            if (PHP_VERSION_ID > 70400)
868
+            {
869
+                throw $e;
870
+            }
871
+
872
+            return trigger_error($e, E_USER_ERROR);
873
+        }
874
+
875
+        $cookieHeader = '';
876
+        $cookies      = [];
877
+
878
+        foreach ($this->cookies as $key => $value)
879
+        {
880
+            $cookies[]= "{$key} = {$value}";
881
+        }
882
+
883
+        if ( ! empty($cookies))
884
+        {
885
+            $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
886
+        }
887 887
 		
888
-		return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
889
-			$this->headers.
890
-			$cookieHeader."\r\n".
891
-			$content;
892
-	}
893
-
894
-	/**
895
-	 * Clones the current request.
896
-	 * 
897
-	 * @return void
898
-	 */
899
-	public function __clone()
900
-	{
901
-		$this->request = clone $this->request;
902
-		$this->cookies = clone $this->cookies;
903
-		$this->files   = clone $this->files;
904
-		$this->server  = clone $this->server;
905
-		$this->headers = clone $this->headers;
906
-	}
888
+        return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
889
+            $this->headers.
890
+            $cookieHeader."\r\n".
891
+            $content;
892
+    }
893
+
894
+    /**
895
+     * Clones the current request.
896
+     * 
897
+     * @return void
898
+     */
899
+    public function __clone()
900
+    {
901
+        $this->request = clone $this->request;
902
+        $this->cookies = clone $this->cookies;
903
+        $this->files   = clone $this->files;
904
+        $this->server  = clone $this->server;
905
+        $this->headers = clone $this->headers;
906
+    }
907 907
 }
908 908
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Response.php 1 patch
Indentation   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -39,297 +39,297 @@
 block discarded – undo
39 39
  */
40 40
 class Response extends Status 
41 41
 {
42
-	use ResponseTrait;
43
-
44
-	/**
45
-	 * Sets up the response with a content and a status code.
46
-	 *
47
-	 * @param  mixed  $content  The response content 
48
-	 * @param  int  $status  The response status  
49
-	 * @param  array  $headers  Array of HTTP headers for this response
50
-	 *
51
-	 * @return string
52
-	 */
53
-	public function __construct($content = '', int $status = 200, array $headers = [])
54
-	{
55
-		$this->setContent($content);
56
-		$this->setStatusCode($status);
42
+    use ResponseTrait;
43
+
44
+    /**
45
+     * Sets up the response with a content and a status code.
46
+     *
47
+     * @param  mixed  $content  The response content 
48
+     * @param  int  $status  The response status  
49
+     * @param  array  $headers  Array of HTTP headers for this response
50
+     *
51
+     * @return string
52
+     */
53
+    public function __construct($content = '', int $status = 200, array $headers = [])
54
+    {
55
+        $this->setContent($content);
56
+        $this->setStatusCode($status);
57 57
 		
58
-		$this->server  = new Server($_SERVER);
59
-		$this->headers = new Headers($headers);
60
-	}
61
-
62
-	/**
63
-	 * Creates an instance of the same response class for rendering contents to the content, 
64
-	 * status code and headers.
65
-	 *
66
-	 * @param  mixed  $content  The response content  
67
-	 * @param  int  $status  The HTTP response status for this response  
68
-	 * @param  array  $headers  Array of HTTP headers for this response
69
-	 *
70
-	 * @return static
71
-	 */
72
-	public static function render($content = '', $status = 200, $headers = [])
73
-	{
74
-		return new static($content, $status, $headers);
75
-	}
76
-
77
-	/**
78
-	 * Gets the current response content.
79
-	 * 
80
-	 * @return string
81
-	 */
82
-	public function getContent()
83
-	{
84
-		return $this->content;
85
-	}
86
-
87
-	/**
88
-	 * Gets the response status code.
89
-	 *
90
-	 * The status code is a 3-digit code to specify server response results to the browser.
91
-	 *
92
-	 * @return int
93
-	 *
94
-	 * @throws \BadMethodCallException
95
-	 */
96
-	public function getStatusCode()
97
-	{
98
-		if (empty($this->status)) {
99
-			throw new BadMethodCallException('HTTP Response is missing a status code.');
100
-		}
101
-
102
-		return $this->status;
103
-	}
104
-
105
-	/**
106
-	 * Sends the headers if they haven't already been sent. 
107
-	 * Returns whether they were sent or not.
108
-	 *
109
-	 * @return bool
110
-	 *
111
-	 * @uses   \Syscodes\Http\Http
112
-	 */
113
-	public function sendHeaders()
114
-	{
115
-		// Have the headers already been sent?
116
-		if (headers_sent()) {
117
-			return $this;
118
-		}
119
-
120
-		// Headers
121
-		foreach ($this->headers->allPreserveCase() as $name => $values) {
122
-			$replace = 0 === strcasecmp($name, 'Content-Type');
123
-
124
-			foreach ($values as $value) {
125
-				header($name.': '. $value, $replace, $this->status);
126
-			}
127
-		}
128
-
129
-		// Status
130
-		if ( ! empty($_SERVER['FCGI_SERVER_VERSION'])) {
131
-			// Send the protocol/status line first, FCGI servers need different status header
132
-			header(sprintf('Status: %s %s', $this->status, $this->statusText));
133
-		} else {
134
-			$this->protocol = (string) $this->server->get('SERVER_PROTOCOL') ?: 'HTTP/1.1';
135
-			header(sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText), true, $this->status);
136
-		}
137
-
138
-		return $this;
139
-	}
140
-
141
-	/**
142
-	 * Sends content for the current web response.
143
-	 * 
144
-	 * @return $this
145
-	 */
146
-	public function sendContent()
147
-	{
148
-		echo $this->content;
149
-
150
-		return $this;
151
-	}
152
-
153
-	/**
154
-	 * Sends the response to the output buffer. Optionally, headers will be sent. 
155
-	 *
156
-	 * @param  bool  $sendHeader  Whether or not to send the defined HTTP headers
157
-	 *
158
-	 * @return $this
159
-	 */
160
-	public function send($sendHeader = false)
161
-	{
162
-		if ($sendHeader) {
163
-			$this->sendHeaders();
164
-		}
165
-
166
-		if (null !== $this->content) {
167
-			$this->sendContent();
168
-		}
169
-
170
-		return $this;
171
-	}
172
-
173
-	/**
174
-	 * Sends the content of the message to the browser.
175
-	 *
176
-	 * @param  mixed  $content  The response content
177
-	 *
178
-	 * @return $this
179
-	 */
180
-	public function setContent($content)
181
-	{
182
-		if ($content !== null && ! is_string($content) && ! is_numeric($content) && ! is_callable([$content, '__toString'])) {
183
-			throw new UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
184
-		}
185
-
186
-		if ($content instanceof JsonSerializable || is_array($content)) {
187
-			$this->header('Content-Type', 'application/json');
188
-
189
-			$content = json_encode($content);
190
-		} elseif ($content instanceof Renderable) {
191
-			$content = $content->render();
192
-		}
58
+        $this->server  = new Server($_SERVER);
59
+        $this->headers = new Headers($headers);
60
+    }
61
+
62
+    /**
63
+     * Creates an instance of the same response class for rendering contents to the content, 
64
+     * status code and headers.
65
+     *
66
+     * @param  mixed  $content  The response content  
67
+     * @param  int  $status  The HTTP response status for this response  
68
+     * @param  array  $headers  Array of HTTP headers for this response
69
+     *
70
+     * @return static
71
+     */
72
+    public static function render($content = '', $status = 200, $headers = [])
73
+    {
74
+        return new static($content, $status, $headers);
75
+    }
76
+
77
+    /**
78
+     * Gets the current response content.
79
+     * 
80
+     * @return string
81
+     */
82
+    public function getContent()
83
+    {
84
+        return $this->content;
85
+    }
86
+
87
+    /**
88
+     * Gets the response status code.
89
+     *
90
+     * The status code is a 3-digit code to specify server response results to the browser.
91
+     *
92
+     * @return int
93
+     *
94
+     * @throws \BadMethodCallException
95
+     */
96
+    public function getStatusCode()
97
+    {
98
+        if (empty($this->status)) {
99
+            throw new BadMethodCallException('HTTP Response is missing a status code.');
100
+        }
101
+
102
+        return $this->status;
103
+    }
104
+
105
+    /**
106
+     * Sends the headers if they haven't already been sent. 
107
+     * Returns whether they were sent or not.
108
+     *
109
+     * @return bool
110
+     *
111
+     * @uses   \Syscodes\Http\Http
112
+     */
113
+    public function sendHeaders()
114
+    {
115
+        // Have the headers already been sent?
116
+        if (headers_sent()) {
117
+            return $this;
118
+        }
119
+
120
+        // Headers
121
+        foreach ($this->headers->allPreserveCase() as $name => $values) {
122
+            $replace = 0 === strcasecmp($name, 'Content-Type');
123
+
124
+            foreach ($values as $value) {
125
+                header($name.': '. $value, $replace, $this->status);
126
+            }
127
+        }
128
+
129
+        // Status
130
+        if ( ! empty($_SERVER['FCGI_SERVER_VERSION'])) {
131
+            // Send the protocol/status line first, FCGI servers need different status header
132
+            header(sprintf('Status: %s %s', $this->status, $this->statusText));
133
+        } else {
134
+            $this->protocol = (string) $this->server->get('SERVER_PROTOCOL') ?: 'HTTP/1.1';
135
+            header(sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText), true, $this->status);
136
+        }
137
+
138
+        return $this;
139
+    }
140
+
141
+    /**
142
+     * Sends content for the current web response.
143
+     * 
144
+     * @return $this
145
+     */
146
+    public function sendContent()
147
+    {
148
+        echo $this->content;
149
+
150
+        return $this;
151
+    }
152
+
153
+    /**
154
+     * Sends the response to the output buffer. Optionally, headers will be sent. 
155
+     *
156
+     * @param  bool  $sendHeader  Whether or not to send the defined HTTP headers
157
+     *
158
+     * @return $this
159
+     */
160
+    public function send($sendHeader = false)
161
+    {
162
+        if ($sendHeader) {
163
+            $this->sendHeaders();
164
+        }
165
+
166
+        if (null !== $this->content) {
167
+            $this->sendContent();
168
+        }
169
+
170
+        return $this;
171
+    }
172
+
173
+    /**
174
+     * Sends the content of the message to the browser.
175
+     *
176
+     * @param  mixed  $content  The response content
177
+     *
178
+     * @return $this
179
+     */
180
+    public function setContent($content)
181
+    {
182
+        if ($content !== null && ! is_string($content) && ! is_numeric($content) && ! is_callable([$content, '__toString'])) {
183
+            throw new UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
184
+        }
185
+
186
+        if ($content instanceof JsonSerializable || is_array($content)) {
187
+            $this->header('Content-Type', 'application/json');
188
+
189
+            $content = json_encode($content);
190
+        } elseif ($content instanceof Renderable) {
191
+            $content = $content->render();
192
+        }
193 193
 		
194
-		$this->content = $content ?? '';
195
-
196
-		return $this;
197
-	}
198
-
199
-	/**
200
-	 * Prepares the Response before it is sent to the client.
201
-	 * 
202
-	 * @param  \Syscodes\Http\Request  $request
203
-	 * 
204
-	 * @return $this
205
-	 */
206
-	public function prepare($request)
207
-	{
208
-		$headers = $this->headers;
209
-
210
-		if ($this->isInformational() || $this->isEmpty()) {
211
-			$this->setContent(null);
212
-			$headers->remove('Content-Type');
213
-			$headers->remove('Content-Length');
214
-		}
215
-
216
-		return $this;
217
-	}
218
-
219
-	/**
220
-	* Sets the response status code.
221
-	*
222
-	* @param  int  $code  The status code
223
-	* @param  string|null  $text  The status text
224
-	*
225
-	* @return $this
226
-	*
227
-	* @throws \InvalidArgumentException
228
-	*/
229
-	public function setStatusCode(int $code, $text = null)
230
-	{
231
-		$this->status = $code; 
232
-
233
-		// Valid range?
234
-		if ($this->isInvalid()) {
235
-			throw new InvalidArgumentException(__('response.statusCodeNotValid', ['code' => $code]));			
236
-		}
237
-
238
-		// Check if you have an accepted status code if not shows to a message of unknown status
239
-		if (null === $text) {
240
-			$this->statusText = isset($this->statusCodes[$code]) ? $this->statusCodes[$code] : __('response.UnknownStatus');
241
-
242
-			return $this;
243
-		}
244
-
245
-		if (false === $text) {
246
-			$this->statusText = '';
247
-
248
-			return $this;
249
-		}
250
-
251
-		$this->statusText = $text;
252
-
253
-		return $this;
254
-	}
255
-
256
-	/**
257
-	 * Is response invalid?
258
-	 * 
259
-	 * @final
260
-	 * 
261
-	 * @return void
262
-	 */
263
-	public function isInvalid(): bool
264
-	{
265
-		return $this->status < 100 || $this->status >= 600;
266
-	}
267
-
268
-	/**
269
-	 * Is response informative?
270
-	 * 
271
-	 * @final
272
-	 * 
273
-	 * @return void
274
-	 */
275
-	public function isInformational()
276
-	{
277
-		return $this->status >= 100 && $this->status < 200;
278
-	}
194
+        $this->content = $content ?? '';
195
+
196
+        return $this;
197
+    }
198
+
199
+    /**
200
+     * Prepares the Response before it is sent to the client.
201
+     * 
202
+     * @param  \Syscodes\Http\Request  $request
203
+     * 
204
+     * @return $this
205
+     */
206
+    public function prepare($request)
207
+    {
208
+        $headers = $this->headers;
209
+
210
+        if ($this->isInformational() || $this->isEmpty()) {
211
+            $this->setContent(null);
212
+            $headers->remove('Content-Type');
213
+            $headers->remove('Content-Length');
214
+        }
215
+
216
+        return $this;
217
+    }
218
+
219
+    /**
220
+     * Sets the response status code.
221
+     *
222
+     * @param  int  $code  The status code
223
+     * @param  string|null  $text  The status text
224
+     *
225
+     * @return $this
226
+     *
227
+     * @throws \InvalidArgumentException
228
+     */
229
+    public function setStatusCode(int $code, $text = null)
230
+    {
231
+        $this->status = $code; 
232
+
233
+        // Valid range?
234
+        if ($this->isInvalid()) {
235
+            throw new InvalidArgumentException(__('response.statusCodeNotValid', ['code' => $code]));			
236
+        }
237
+
238
+        // Check if you have an accepted status code if not shows to a message of unknown status
239
+        if (null === $text) {
240
+            $this->statusText = isset($this->statusCodes[$code]) ? $this->statusCodes[$code] : __('response.UnknownStatus');
241
+
242
+            return $this;
243
+        }
244
+
245
+        if (false === $text) {
246
+            $this->statusText = '';
247
+
248
+            return $this;
249
+        }
250
+
251
+        $this->statusText = $text;
252
+
253
+        return $this;
254
+    }
255
+
256
+    /**
257
+     * Is response invalid?
258
+     * 
259
+     * @final
260
+     * 
261
+     * @return void
262
+     */
263
+    public function isInvalid(): bool
264
+    {
265
+        return $this->status < 100 || $this->status >= 600;
266
+    }
267
+
268
+    /**
269
+     * Is response informative?
270
+     * 
271
+     * @final
272
+     * 
273
+     * @return void
274
+     */
275
+    public function isInformational()
276
+    {
277
+        return $this->status >= 100 && $this->status < 200;
278
+    }
279 279
 	
280
-	/**
281
-	 * Is the response a redirect?
282
-	 * 
283
-	 * @final
284
-	 * 
285
-	 * @return void
286
-	 */
287
-	public function isRedirection()
288
-	{
289
-		return $this->status >= 300 && $this->status < 400;
290
-	}
280
+    /**
281
+     * Is the response a redirect?
282
+     * 
283
+     * @final
284
+     * 
285
+     * @return void
286
+     */
287
+    public function isRedirection()
288
+    {
289
+        return $this->status >= 300 && $this->status < 400;
290
+    }
291 291
 	
292
-	/**
293
-	 * Is the response empty?
294
-	 * 
295
-	 * @final
296
-	 * 
297
-	 * @return void
298
-	 */
299
-	public function isEmpty()
300
-	{
301
-		return in_array($this->status, [204, 304]);
302
-	}
292
+    /**
293
+     * Is the response empty?
294
+     * 
295
+     * @final
296
+     * 
297
+     * @return void
298
+     */
299
+    public function isEmpty()
300
+    {
301
+        return in_array($this->status, [204, 304]);
302
+    }
303 303
 	
304
-	/**
305
-	 * Is the response a redirect of some form?
306
-	 * 
307
-	 * @return bool
308
-	 */
309
-	public function isRedirect()
310
-	{
311
-		return in_array($this->status, [301, 302, 303, 307, 308]);
312
-	}
304
+    /**
305
+     * Is the response a redirect of some form?
306
+     * 
307
+     * @return bool
308
+     */
309
+    public function isRedirect()
310
+    {
311
+        return in_array($this->status, [301, 302, 303, 307, 308]);
312
+    }
313 313
 	
314
-	/**
315
-	 * Returns the Response as an HTTP string.
316
-	 * 
317
-	 * @return string
318
-	 */
319
-	public function __toString()
320
-	{
321
-		return sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText)."\r\n".
322
-			$this->headers."\r\n".
323
-			$this->getContent();
324
-	}
314
+    /**
315
+     * Returns the Response as an HTTP string.
316
+     * 
317
+     * @return string
318
+     */
319
+    public function __toString()
320
+    {
321
+        return sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText)."\r\n".
322
+            $this->headers."\r\n".
323
+            $this->getContent();
324
+    }
325 325
 	
326
-	/**
327
-	 * Clone the current Response instance.
328
-	 * 
329
-	 * @return void
330
-	 */
331
-	public function __clone()
332
-	{
333
-		$this->headers = clone $this->headers;
334
-	}
326
+    /**
327
+     * Clone the current Response instance.
328
+     * 
329
+     * @return void
330
+     */
331
+    public function __clone()
332
+    {
333
+        $this->headers = clone $this->headers;
334
+    }
335 335
 }
336 336
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Exceptions/PostTooLargeHttpException.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -33,35 +33,35 @@
 block discarded – undo
33 33
  */
34 34
 class PostTooLargeHttpException extends HttpException
35 35
 {
36
-	/**
37
-	 * Get the HTTP status code.
38
-	 * 
39
-	 * @var int $code
40
-	 */
41
-	protected $code = 413;
36
+    /**
37
+     * Get the HTTP status code.
38
+     * 
39
+     * @var int $code
40
+     */
41
+    protected $code = 413;
42 42
 
43
-	/**
44
-	 * Initialize constructor. 
45
-	 * 
46
-	 * @param  string|null  $message   
47
-	 * @param  \Throwable|null  $previous  
48
-	 * @param  int  $code 
49
-	 * @param  array  $headers
50
-	 * 
51
-	 * @return void
52
-	 */
53
-	public function __construct(
54
-		string $message = null, 
55
-		Throwable $previous = null, 
56
-		int $code = 0, 
57
-		array $headers = []
58
-	) {
43
+    /**
44
+     * Initialize constructor. 
45
+     * 
46
+     * @param  string|null  $message   
47
+     * @param  \Throwable|null  $previous  
48
+     * @param  int  $code 
49
+     * @param  array  $headers
50
+     * 
51
+     * @return void
52
+     */
53
+    public function __construct(
54
+        string $message = null, 
55
+        Throwable $previous = null, 
56
+        int $code = 0, 
57
+        array $headers = []
58
+    ) {
59 59
         parent::__construct(
60
-			$this->code, 
61
-			$message, 
62
-			$previous, 
63
-			$headers, 
64
-			$code
65
-		);
66
-	}
60
+            $this->code, 
61
+            $message, 
62
+            $previous, 
63
+            $headers, 
64
+            $code
65
+        );
66
+    }
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/URI.php 1 patch
Indentation   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -34,497 +34,497 @@
 block discarded – undo
34 34
  */
35 35
 class URI
36 36
 {
37
-	/**
38
-	 * Returns default schemes/ports.
39
-	 * 
40
-	 * @var array $defaultPorts
41
-	 */
42
-	protected $defaultPorts = [
43
-		'http'  => 80,
44
-		'https' => 443,
45
-		'ftp'   => 21,
46
-		'sftp'  => 22
47
-	];
48
-
49
-	/**
50
-	 * The name of any fragment.
51
-	 * 
52
-	 * @var string $fragment
53
-	 */
54
-	protected $fragment = '';
55
-
56
-	/**
57
-	 * The URI Host.
58
-	 * 
59
-	 * @var string $host
60
-	 */
61
-	protected $host;
37
+    /**
38
+     * Returns default schemes/ports.
39
+     * 
40
+     * @var array $defaultPorts
41
+     */
42
+    protected $defaultPorts = [
43
+        'http'  => 80,
44
+        'https' => 443,
45
+        'ftp'   => 21,
46
+        'sftp'  => 22
47
+    ];
48
+
49
+    /**
50
+     * The name of any fragment.
51
+     * 
52
+     * @var string $fragment
53
+     */
54
+    protected $fragment = '';
55
+
56
+    /**
57
+     * The URI Host.
58
+     * 
59
+     * @var string $host
60
+     */
61
+    protected $host;
62 62
 	
63
-	/**
64
-	 * The URI User Password.
65
-	 * 
66
-	 * @var string $password
67
-	 */
68
-	protected $password;
69
-
70
-	/**
71
-	 * The URI path.
72
-	 * 
73
-	 * @var string $path
74
-	 */
75
-	protected $path;
76
-
77
-	/**
78
-	 * The URI Port.
79
-	 * 
80
-	 * @var int $port
81
-	 */
82
-	protected $port;
83
-
84
-	/**
85
-	 * The query string.
86
-	 * 
87
-	 * @var string $query
88
-	 */
89
-	protected $query;
90
-
91
-	/**
92
-	 * The URI Scheme.
93
-	 * 
94
-	 * @var string $scheme
95
-	 */
96
-	protected $scheme = 'http';
97
-
98
-	/**
99
-	 * The URI segments.
100
-	 *
101
-	 * @var array $segments
102
-	 */
103
-	protected $segments = [];
104
-
105
-	/**
106
-	 * Whether passwords should be shown in userInfo/authority calls.
107
-	 * 
108
-	 * @var boolean $showPassword
109
-	 */
110
-	protected $showPassword = false;
63
+    /**
64
+     * The URI User Password.
65
+     * 
66
+     * @var string $password
67
+     */
68
+    protected $password;
69
+
70
+    /**
71
+     * The URI path.
72
+     * 
73
+     * @var string $path
74
+     */
75
+    protected $path;
76
+
77
+    /**
78
+     * The URI Port.
79
+     * 
80
+     * @var int $port
81
+     */
82
+    protected $port;
83
+
84
+    /**
85
+     * The query string.
86
+     * 
87
+     * @var string $query
88
+     */
89
+    protected $query;
90
+
91
+    /**
92
+     * The URI Scheme.
93
+     * 
94
+     * @var string $scheme
95
+     */
96
+    protected $scheme = 'http';
97
+
98
+    /**
99
+     * The URI segments.
100
+     *
101
+     * @var array $segments
102
+     */
103
+    protected $segments = [];
104
+
105
+    /**
106
+     * Whether passwords should be shown in userInfo/authority calls.
107
+     * 
108
+     * @var boolean $showPassword
109
+     */
110
+    protected $showPassword = false;
111 111
 	
112
-	/**
113
-	 * The URI User Info.
114
-	 * 
115
-	 * @var string $user
116
-	 */
117
-	protected $user;
118
-
119
-	/**
120
-	 * Constructor. The URI class instance.
121
-	 * 
122
-	 * @param  string|null  $uri  
123
-	 * 
124
-	 * @return void
125
-	 * 
126
-	 * @throws \Syscodes\Http\Exceptions\HttpURIException
127
-	 */
128
-	public function __construct(string $uri = null)
129
-	{
130
-		if ( ! is_null($uri)) {
131
-			$this->setUri($uri);
132
-		}
133
-	}
134
-
135
-	/**
136
-	 * Sets and overwrites any current URI information.
137
-	 * 
138
-	 * @param  string|null  $uri  
139
-	 * 
140
-	 * @return mixed
141
-	 * 
142
-	 * @throws \Syscodes\Http\Exceptions\HttpURIException
143
-	 */
144
-	public function setUri(string $uri = null)
145
-	{
146
-		if ( ! is_null($uri)) {
147
-			$parts = parse_url($uri);
148
-
149
-			if ($parts === false) {
150
-				throw HttpURIException::UnableToParseURI($uri);
151
-			}
152
-
153
-			$this->applyParts($parts);
154
-		}
155
-
156
-		return $this;
157
-	}
158
-
159
-	/**
160
-	 * Returns the full URI string.
161
-	 *
162
-	 * @return string  The URI string
163
-	 */
164
-	public function get()
165
-	{
166
-		return '/'.ltrim($this->path, '/');
167
-	}
168
-
169
-	/**
170
-	 * Sets of URI string.
171
-	 * 
172
-	 * @param  string  $uri
173
-	 * 
174
-	 * @return $this
175
-	 */
176
-	public function set($uri)
177
-	{
178
-		$this->path = $uri;
179
-
180
-		return $this;
181
-	}
182
-
183
-	/**
184
-	 * Retrieve the path component of the URI. The path can either be empty or absolute 
185
-	 * (starting with a slash) or rootless (not starting with a slash).
186
-	 * 
187
-	 * @return string
188
-	 */
189
-	public function getPath()
190
-	{
191
-		return (is_null($this->path) ? '' : $this->path);
192
-	}
193
-
194
-	/**
195
-	 * Sets the path portion of the URI.
196
-	 * 
197
-	 * @param  string  $path
198
-	 *
199
-	 * @return void
200
-	 */
201
-	public function setPath(string $path) 
202
-	{
203
-		$this->path = $this->filterPath($path);
204
-
205
-		$this->filterSegments($this->path);
206
-
207
-		return $this;
208
-	} 
209
-
210
-	/**
211
-	 * Encodes any dangerous characters.
212
-	 * 
213
-	 * @param  string|null  $path
214
-	 * 
215
-	 * @return string
216
-	 */
217
-	protected function filterPath(string $path = null)
218
-	{
219
-		$path = urldecode($path);
220
-
221
-		return $path;
222
-	}
223
-
224
-	/**
225
-	 * Filter the segments of path.
226
-	 * 
227
-	 * @param  string  $uri
228
-	 * 
229
-	 * @return string[]
230
-	 */
231
-	protected function filterSegments($uri)
232
-	{
233
-		$this->segments = (empty($uri) ? [] : explode('/', $uri));
234
-	}
235
-
236
-	/**
237
-	 * Get the specified URI segment, return default if it doesn't exist.
238
-	 * Segment index is 1 based, not 0 based.
239
-	 *
240
-	 * @param  int  $index  The 1-based segment index
241
-	 * @param  mixed  $default  The default value
242
-	 *
243
-	 * @return mixed
244
-	 */
245
-	public function getSegment(int $index, $default = null)
246
-	{
247
-		return Arr::get($this->getSegments(), $index - 1, $default);
248
-	}
249
-
250
-	/**
251
-	 * Returns the segments of the path as an array.
252
-	 *
253
-	 * @return array  The URI segments
254
-	 */
255
-	public function getSegments()
256
-	{
257
-		return array_values(array_filter($this->segments, function ($value) {
258
-			return $value != '';
259
-		}));
260
-	}
261
-
262
-	/**
263
-	 * Returns the total number of segment.
264
-	 *
265
-	 * @return int  
266
-	 */
267
-	public function getTotalSegments()
268
-	{
269
-		return count($this->getSegments());
270
-	}
271
-
272
-	/**
273
-	 * Retrieve the scheme component of the URI.
274
-	 * 
275
-	 * @return string
276
-	 */
277
-	public function getScheme()
278
-	{
279
-		return $this->scheme;
280
-	}
281
-
282
-	/**
283
-	 * Sets the scheme for this URI.
284
-	 * 
285
-	 * @param  string  $str
286
-	 * 
287
-	 * @return $this
288
-	 */
289
-	public function setScheme(string $str)
290
-	{
291
-		$str = preg_replace('~:(//)?$~', '', strtolower($str));
292
-
293
-		$this->scheme = $str;
294
-
295
-		return $this->scheme;
296
-	}
297
-
298
-	/**
299
-	 * Retrieve the user component of the URI.
300
-	 * 
301
-	 * @return string|null
302
-	 */
303
-	public function getUserInfo()
304
-	{
305
-		$user = $this->user;
306
-
307
-		if ($this->showPassword === true && ! empty($this->password)) {
308
-			$user .= ":$this->password";
309
-		}
310
-
311
-		return $user;
312
-	}
313
-
314
-	/**
315
-	 * Sets the userInfo/Authority portion of the URI.
316
-	 * 
317
-	 * @param  string  $user
318
-	 * @param  string  $pass
319
-	 * 
320
-	 * @return $this
321
-	 */
322
-	public function setUserInfo(string $user, string $pass)
323
-	{
324
-		$this->user     = trim($user);
325
-		$this->password = trim($pass);
326
-
327
-		return $this;
328
-	}
329
-
330
-	/**
331
-	 * Temporarily sets the URI to show a password in userInfo.
332
-	 * 
333
-	 * @param  boolean  $option  
334
-	 * 
335
-	 * @return $this
336
-	 */
337
-	public function showPassword(bool $option = true)
338
-	{
339
-		$this->password = $option;
340
-
341
-		return $this->password;
342
-	}
343
-
344
-	/**
345
-	 * Retrieve the authority component of the URI.
346
-	 * 
347
-	 * @param  boolean  $ignore  
348
-	 * 
349
-	 * @return string
350
-	 */
351
-	public function getAuthority(bool $ignore = false)
352
-	{
353
-		if (empty($this->host)) {
354
-			return '';
355
-		}
356
-
357
-		$authority = $this->host;
358
-
359
-		if ( ! empty($this->getUserInfo())) {
360
-			$authority = $this->getUserInfo().'@'.$authority;
361
-		}
362
-
363
-		if ( ! empty($this->port) && ! $ignore) {
364
-			if ($this->port !== $this->defaultPorts[$this->scheme]) {
365
-				$authority .= ":$this->port";
366
-			}
367
-		}
368
-
369
-		$this->showPassword = false;
370
-
371
-		return $authority;
372
-	}
373
-
374
-	/**
375
-	 * Parses the given string an saves the appropriate authority pieces.
376
-	 * 
377
-	 * @param  string  $str
378
-	 * 
379
-	 * @return $this
380
-	 */
381
-	public function setAuthority(string $str)
382
-	{
383
-		$parts = parse_url($str);
384
-
385
-		if (empty($parts['host']) && ! empty($parts['path'])) {
386
-			$parts['host'] = $parts['path'];
387
-			unset($parts['path']);
388
-		}
389
-
390
-		$this->applyParts($parts);
391
-
392
-		return $this;
393
-	}
394
-
395
-	/**
396
-	 * Retrieve the host component of the URI.
397
-	 * 
398
-	 * @return string
399
-	 */
400
-	public function getHost()
401
-	{
402
-		return $this->host;
403
-	}
404
-
405
-	/**
406
-	 * Sets the host name to use.
407
-	 * 
408
-	 * @param  string  $str
409
-	 * 
410
-	 * @return $this
411
-	 */
412
-	public function setHost(string $str)
413
-	{
414
-		$this->host = trim($str);
415
-
416
-		return $this->host;
417
-	}
418
-
419
-	/**
420
-	 * Retrieve the port component of the URI.
421
-	 * 
422
-	 * @return int|null
423
-	 */
424
-	public function getPort()
425
-	{
426
-		return $this->port;
427
-	}
428
-
429
-	/**
430
-	 * Sets the port portion of the URI.
431
-	 * 
432
-	 * @param  int|null  $port  
433
-	 * 
434
-	 * @return string
435
-	 */
436
-	public function setPort(int $port = null)
437
-	{
438
-		if (is_null($port)) {
439
-			return $this;
440
-		}
441
-
442
-		if ($port <= 0 || $port > 65355) {
443
-			throw HttpURIException::invalidPort($port);
444
-		}
445
-
446
-		$this->port = $port;
447
-
448
-		return $this->port;
449
-	}
450
-
451
-	/**
452
-	 * Retrieve a URI fragment.
453
-	 * 
454
-	 * @return string
455
-	 */
456
-	public function getFragment()
457
-	{
458
-		return is_null($this->fragment) ? '' : $this->fragment;
459
-	}
460
-
461
-	/**
462
-	 * Sets the fragment portion of the URI.
463
-	 * 
464
-	 * @param  string  $str
465
-	 * 
466
-	 * @return $this
467
-	 */
468
-	public function setFragment(string $str)
469
-	{
470
-		$this->fragment = trim($str, '# ');
471
-
472
-		return $this->fragment;
473
-	}
474
-
475
-	/**
476
-	 * Saves our parts from a parse_url call.
477
-	 * 
478
-	 * @param  array  $parts
479
-	 * 
480
-	 * @return mixed
481
-	 */
482
-	public function applyParts(array $paths)
483
-	{
484
-		if (isset($parts['scheme'])) {
485
-			$this->SetScheme(rtrim($parts['scheme'], ':/'));
486
-		} else {
487
-			$this->setScheme('http');
488
-		}
489
-
490
-		if ( ! empty($parts['host'])) {
491
-			$this->host = $parts['host'];
492
-		}
493
-
494
-		if (isset($parts['port'])) {
495
-			if ( ! is_null($parts['port'])) {
496
-				$this->port = $parts['port'];
497
-			}
498
-		}
499
-
500
-		if ( ! empty($parts['user'])) {
501
-			$this->user = $parts['user'];
502
-		}
503
-
504
-		if ( ! empty($parts['pass'])) {
505
-			$this->password = $parts['pass'];
506
-		}
507
-
508
-		if ( ! empty($parts['path'])) {
509
-			$this->path = $this->filterPath($parts['path']);
510
-		}
511
-
512
-		if ( ! empty($parts['fragment'])) {
513
-			$this->fragment = $parts['fragment'];
514
-		}
515
-
516
-		if ( ! empty($parts['path'])) {
517
-			$this->segments = explode('/', $parts['path'], '/');
518
-		}
519
-	}
520
-
521
-	/**
522
-	 * Returns the URI string.
523
-	 *
524
-	 * @return string
525
-	 */
526
-	public function __toString()
527
-	{
528
-		return (string) $this->getPath();
529
-	}
112
+    /**
113
+     * The URI User Info.
114
+     * 
115
+     * @var string $user
116
+     */
117
+    protected $user;
118
+
119
+    /**
120
+     * Constructor. The URI class instance.
121
+     * 
122
+     * @param  string|null  $uri  
123
+     * 
124
+     * @return void
125
+     * 
126
+     * @throws \Syscodes\Http\Exceptions\HttpURIException
127
+     */
128
+    public function __construct(string $uri = null)
129
+    {
130
+        if ( ! is_null($uri)) {
131
+            $this->setUri($uri);
132
+        }
133
+    }
134
+
135
+    /**
136
+     * Sets and overwrites any current URI information.
137
+     * 
138
+     * @param  string|null  $uri  
139
+     * 
140
+     * @return mixed
141
+     * 
142
+     * @throws \Syscodes\Http\Exceptions\HttpURIException
143
+     */
144
+    public function setUri(string $uri = null)
145
+    {
146
+        if ( ! is_null($uri)) {
147
+            $parts = parse_url($uri);
148
+
149
+            if ($parts === false) {
150
+                throw HttpURIException::UnableToParseURI($uri);
151
+            }
152
+
153
+            $this->applyParts($parts);
154
+        }
155
+
156
+        return $this;
157
+    }
158
+
159
+    /**
160
+     * Returns the full URI string.
161
+     *
162
+     * @return string  The URI string
163
+     */
164
+    public function get()
165
+    {
166
+        return '/'.ltrim($this->path, '/');
167
+    }
168
+
169
+    /**
170
+     * Sets of URI string.
171
+     * 
172
+     * @param  string  $uri
173
+     * 
174
+     * @return $this
175
+     */
176
+    public function set($uri)
177
+    {
178
+        $this->path = $uri;
179
+
180
+        return $this;
181
+    }
182
+
183
+    /**
184
+     * Retrieve the path component of the URI. The path can either be empty or absolute 
185
+     * (starting with a slash) or rootless (not starting with a slash).
186
+     * 
187
+     * @return string
188
+     */
189
+    public function getPath()
190
+    {
191
+        return (is_null($this->path) ? '' : $this->path);
192
+    }
193
+
194
+    /**
195
+     * Sets the path portion of the URI.
196
+     * 
197
+     * @param  string  $path
198
+     *
199
+     * @return void
200
+     */
201
+    public function setPath(string $path) 
202
+    {
203
+        $this->path = $this->filterPath($path);
204
+
205
+        $this->filterSegments($this->path);
206
+
207
+        return $this;
208
+    } 
209
+
210
+    /**
211
+     * Encodes any dangerous characters.
212
+     * 
213
+     * @param  string|null  $path
214
+     * 
215
+     * @return string
216
+     */
217
+    protected function filterPath(string $path = null)
218
+    {
219
+        $path = urldecode($path);
220
+
221
+        return $path;
222
+    }
223
+
224
+    /**
225
+     * Filter the segments of path.
226
+     * 
227
+     * @param  string  $uri
228
+     * 
229
+     * @return string[]
230
+     */
231
+    protected function filterSegments($uri)
232
+    {
233
+        $this->segments = (empty($uri) ? [] : explode('/', $uri));
234
+    }
235
+
236
+    /**
237
+     * Get the specified URI segment, return default if it doesn't exist.
238
+     * Segment index is 1 based, not 0 based.
239
+     *
240
+     * @param  int  $index  The 1-based segment index
241
+     * @param  mixed  $default  The default value
242
+     *
243
+     * @return mixed
244
+     */
245
+    public function getSegment(int $index, $default = null)
246
+    {
247
+        return Arr::get($this->getSegments(), $index - 1, $default);
248
+    }
249
+
250
+    /**
251
+     * Returns the segments of the path as an array.
252
+     *
253
+     * @return array  The URI segments
254
+     */
255
+    public function getSegments()
256
+    {
257
+        return array_values(array_filter($this->segments, function ($value) {
258
+            return $value != '';
259
+        }));
260
+    }
261
+
262
+    /**
263
+     * Returns the total number of segment.
264
+     *
265
+     * @return int  
266
+     */
267
+    public function getTotalSegments()
268
+    {
269
+        return count($this->getSegments());
270
+    }
271
+
272
+    /**
273
+     * Retrieve the scheme component of the URI.
274
+     * 
275
+     * @return string
276
+     */
277
+    public function getScheme()
278
+    {
279
+        return $this->scheme;
280
+    }
281
+
282
+    /**
283
+     * Sets the scheme for this URI.
284
+     * 
285
+     * @param  string  $str
286
+     * 
287
+     * @return $this
288
+     */
289
+    public function setScheme(string $str)
290
+    {
291
+        $str = preg_replace('~:(//)?$~', '', strtolower($str));
292
+
293
+        $this->scheme = $str;
294
+
295
+        return $this->scheme;
296
+    }
297
+
298
+    /**
299
+     * Retrieve the user component of the URI.
300
+     * 
301
+     * @return string|null
302
+     */
303
+    public function getUserInfo()
304
+    {
305
+        $user = $this->user;
306
+
307
+        if ($this->showPassword === true && ! empty($this->password)) {
308
+            $user .= ":$this->password";
309
+        }
310
+
311
+        return $user;
312
+    }
313
+
314
+    /**
315
+     * Sets the userInfo/Authority portion of the URI.
316
+     * 
317
+     * @param  string  $user
318
+     * @param  string  $pass
319
+     * 
320
+     * @return $this
321
+     */
322
+    public function setUserInfo(string $user, string $pass)
323
+    {
324
+        $this->user     = trim($user);
325
+        $this->password = trim($pass);
326
+
327
+        return $this;
328
+    }
329
+
330
+    /**
331
+     * Temporarily sets the URI to show a password in userInfo.
332
+     * 
333
+     * @param  boolean  $option  
334
+     * 
335
+     * @return $this
336
+     */
337
+    public function showPassword(bool $option = true)
338
+    {
339
+        $this->password = $option;
340
+
341
+        return $this->password;
342
+    }
343
+
344
+    /**
345
+     * Retrieve the authority component of the URI.
346
+     * 
347
+     * @param  boolean  $ignore  
348
+     * 
349
+     * @return string
350
+     */
351
+    public function getAuthority(bool $ignore = false)
352
+    {
353
+        if (empty($this->host)) {
354
+            return '';
355
+        }
356
+
357
+        $authority = $this->host;
358
+
359
+        if ( ! empty($this->getUserInfo())) {
360
+            $authority = $this->getUserInfo().'@'.$authority;
361
+        }
362
+
363
+        if ( ! empty($this->port) && ! $ignore) {
364
+            if ($this->port !== $this->defaultPorts[$this->scheme]) {
365
+                $authority .= ":$this->port";
366
+            }
367
+        }
368
+
369
+        $this->showPassword = false;
370
+
371
+        return $authority;
372
+    }
373
+
374
+    /**
375
+     * Parses the given string an saves the appropriate authority pieces.
376
+     * 
377
+     * @param  string  $str
378
+     * 
379
+     * @return $this
380
+     */
381
+    public function setAuthority(string $str)
382
+    {
383
+        $parts = parse_url($str);
384
+
385
+        if (empty($parts['host']) && ! empty($parts['path'])) {
386
+            $parts['host'] = $parts['path'];
387
+            unset($parts['path']);
388
+        }
389
+
390
+        $this->applyParts($parts);
391
+
392
+        return $this;
393
+    }
394
+
395
+    /**
396
+     * Retrieve the host component of the URI.
397
+     * 
398
+     * @return string
399
+     */
400
+    public function getHost()
401
+    {
402
+        return $this->host;
403
+    }
404
+
405
+    /**
406
+     * Sets the host name to use.
407
+     * 
408
+     * @param  string  $str
409
+     * 
410
+     * @return $this
411
+     */
412
+    public function setHost(string $str)
413
+    {
414
+        $this->host = trim($str);
415
+
416
+        return $this->host;
417
+    }
418
+
419
+    /**
420
+     * Retrieve the port component of the URI.
421
+     * 
422
+     * @return int|null
423
+     */
424
+    public function getPort()
425
+    {
426
+        return $this->port;
427
+    }
428
+
429
+    /**
430
+     * Sets the port portion of the URI.
431
+     * 
432
+     * @param  int|null  $port  
433
+     * 
434
+     * @return string
435
+     */
436
+    public function setPort(int $port = null)
437
+    {
438
+        if (is_null($port)) {
439
+            return $this;
440
+        }
441
+
442
+        if ($port <= 0 || $port > 65355) {
443
+            throw HttpURIException::invalidPort($port);
444
+        }
445
+
446
+        $this->port = $port;
447
+
448
+        return $this->port;
449
+    }
450
+
451
+    /**
452
+     * Retrieve a URI fragment.
453
+     * 
454
+     * @return string
455
+     */
456
+    public function getFragment()
457
+    {
458
+        return is_null($this->fragment) ? '' : $this->fragment;
459
+    }
460
+
461
+    /**
462
+     * Sets the fragment portion of the URI.
463
+     * 
464
+     * @param  string  $str
465
+     * 
466
+     * @return $this
467
+     */
468
+    public function setFragment(string $str)
469
+    {
470
+        $this->fragment = trim($str, '# ');
471
+
472
+        return $this->fragment;
473
+    }
474
+
475
+    /**
476
+     * Saves our parts from a parse_url call.
477
+     * 
478
+     * @param  array  $parts
479
+     * 
480
+     * @return mixed
481
+     */
482
+    public function applyParts(array $paths)
483
+    {
484
+        if (isset($parts['scheme'])) {
485
+            $this->SetScheme(rtrim($parts['scheme'], ':/'));
486
+        } else {
487
+            $this->setScheme('http');
488
+        }
489
+
490
+        if ( ! empty($parts['host'])) {
491
+            $this->host = $parts['host'];
492
+        }
493
+
494
+        if (isset($parts['port'])) {
495
+            if ( ! is_null($parts['port'])) {
496
+                $this->port = $parts['port'];
497
+            }
498
+        }
499
+
500
+        if ( ! empty($parts['user'])) {
501
+            $this->user = $parts['user'];
502
+        }
503
+
504
+        if ( ! empty($parts['pass'])) {
505
+            $this->password = $parts['pass'];
506
+        }
507
+
508
+        if ( ! empty($parts['path'])) {
509
+            $this->path = $this->filterPath($parts['path']);
510
+        }
511
+
512
+        if ( ! empty($parts['fragment'])) {
513
+            $this->fragment = $parts['fragment'];
514
+        }
515
+
516
+        if ( ! empty($parts['path'])) {
517
+            $this->segments = explode('/', $parts['path'], '/');
518
+        }
519
+    }
520
+
521
+    /**
522
+     * Returns the URI string.
523
+     *
524
+     * @return string
525
+     */
526
+    public function __toString()
527
+    {
528
+        return (string) $this->getPath();
529
+    }
530 530
 }
Please login to merge, or discard this patch.
src/components/View/Factory.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -38,313 +38,313 @@
 block discarded – undo
38 38
  */
39 39
 class Factory implements FactoryContract
40 40
 {
41
-	use Extensions,
42
-		Concerns\ManagesLayouts,
43
-		Concerns\ManagesComponents,
44
-		Concerns\ManagesTranslations;
41
+    use Extensions,
42
+        Concerns\ManagesLayouts,
43
+        Concerns\ManagesComponents,
44
+        Concerns\ManagesTranslations;
45 45
 	
46
-	/**
47
-	 * The IoC container instance.
48
-	 * 
49
-	 * @var \Syscodes\Contracts\Container\Container $container
50
-	 */
51
-	protected $container;
46
+    /**
47
+     * The IoC container instance.
48
+     * 
49
+     * @var \Syscodes\Contracts\Container\Container $container
50
+     */
51
+    protected $container;
52 52
 
53
-	/**
54
-	 * The engine implementation.
55
-	 * 
56
-	 * @var \Syscodes\View\Engines\EngineResolver $engines
57
-	 */
58
-	protected $engines;
53
+    /**
54
+     * The engine implementation.
55
+     * 
56
+     * @var \Syscodes\View\Engines\EngineResolver $engines
57
+     */
58
+    protected $engines;
59 59
 
60
-	/**
61
-	 * The event dispatcher instance.
62
-	 * 
63
-	 * @var \Syscodes\Contracts\Events\Dispatcher $events
64
-	 */
65
-	protected $events;
60
+    /**
61
+     * The event dispatcher instance.
62
+     * 
63
+     * @var \Syscodes\Contracts\Events\Dispatcher $events
64
+     */
65
+    protected $events;
66 66
 
67
-	/**
68
-	 * The view finder implementation.
69
-	 * 
70
-	 * @var \Syscodes\View\FileViewFinder $finder
71
-	 */
72
-	protected $finder;
67
+    /**
68
+     * The view finder implementation.
69
+     * 
70
+     * @var \Syscodes\View\FileViewFinder $finder
71
+     */
72
+    protected $finder;
73 73
 
74
-	/**
75
-	 * The number of active rendering operations.
76
-	 * 
77
-	 * @var int $renderCount
78
-	 */
79
-	protected $renderCount = 0;
74
+    /**
75
+     * The number of active rendering operations.
76
+     * 
77
+     * @var int $renderCount
78
+     */
79
+    protected $renderCount = 0;
80 80
 
81
-	/**
82
-	 * Array of shared data.
83
-	 * 
84
-	 * @var array $shared
85
-	 */
86
-	protected $shared = [];
81
+    /**
82
+     * Array of shared data.
83
+     * 
84
+     * @var array $shared
85
+     */
86
+    protected $shared = [];
87 87
 
88
-	/**
89
-	 * Constructor: Create a new Parser class instance.
90
-	 * 
91
-	 * @param  \Syscodes\View\Engines\EngineResolver  $engine
92
-	 * @param  \Syscodes\Contracts\View\ViewFinder  $finder
93
-	 * @param  \Syscodes\Contracts\Events\Dispatcher  $events
94
-	 *
95
-	 * @return void
96
-	 */
97
-	public function __construct(EngineResolver $engines, ViewFinder $finder, Dispatcher $events)
98
-	{
99
-		$this->finder  = $finder;
100
-		$this->engines = $engines;
101
-		$this->events  = $events;
88
+    /**
89
+     * Constructor: Create a new Parser class instance.
90
+     * 
91
+     * @param  \Syscodes\View\Engines\EngineResolver  $engine
92
+     * @param  \Syscodes\Contracts\View\ViewFinder  $finder
93
+     * @param  \Syscodes\Contracts\Events\Dispatcher  $events
94
+     *
95
+     * @return void
96
+     */
97
+    public function __construct(EngineResolver $engines, ViewFinder $finder, Dispatcher $events)
98
+    {
99
+        $this->finder  = $finder;
100
+        $this->engines = $engines;
101
+        $this->events  = $events;
102 102
 
103
-		$this->share('__env', $this);
104
-	}
103
+        $this->share('__env', $this);
104
+    }
105 105
 	
106
-	/**
107
-	 * Check existance view file.
108
-	 * 
109
-	 * @param  string  $view
110
-	 *
111
-	 * @return bool
112
-	 */
113
-	public function viewExists($view)
114
-	{
115
-		try {
116
-			$this->finder->find($view);
117
-		} catch(InvalidArgumentException $e) {
118
-			return false;
119
-		}
106
+    /**
107
+     * Check existance view file.
108
+     * 
109
+     * @param  string  $view
110
+     *
111
+     * @return bool
112
+     */
113
+    public function viewExists($view)
114
+    {
115
+        try {
116
+            $this->finder->find($view);
117
+        } catch(InvalidArgumentException $e) {
118
+            return false;
119
+        }
120 120
 
121
-		return true;
122
-	}
121
+        return true;
122
+    }
123 123
 	
124
-	/**
125
-	 * Global and local data are merged and extracted to create local variables within the view file.
126
-	 * Renders the view object to a string.
127
-	 *
128
-	 * @example $output = $view->make();
129
-	 *
130
-	 * @param  string  $view  View filename
131
-	 * @param  array  $data  Array of values
132
-	 *
133
-	 * @return string
134
-	 */
135
-	public function make($view, $data = []) 
136
-	{
137
-		$path = $this->finder->find(
138
-			$view = $this->normalizeName($view)
139
-		);
124
+    /**
125
+     * Global and local data are merged and extracted to create local variables within the view file.
126
+     * Renders the view object to a string.
127
+     *
128
+     * @example $output = $view->make();
129
+     *
130
+     * @param  string  $view  View filename
131
+     * @param  array  $data  Array of values
132
+     *
133
+     * @return string
134
+     */
135
+    public function make($view, $data = []) 
136
+    {
137
+        $path = $this->finder->find(
138
+            $view = $this->normalizeName($view)
139
+        );
140 140
 		
141
-		// Loader class instance.
142
-		return take($this->viewInstance($view, $path, $data), function ($view) {
143
-			$this->callCreator($view);
144
-		});
145
-	}
141
+        // Loader class instance.
142
+        return take($this->viewInstance($view, $path, $data), function ($view) {
143
+            $this->callCreator($view);
144
+        });
145
+    }
146 146
 
147
-	/**
148
-	 * Normalize a view name.
149
-	 * 
150
-	 * @param  string  $name
151
-	 * 
152
-	 * @return string
153
-	 */
154
-	protected function normalizeName($name)
147
+    /**
148
+     * Normalize a view name.
149
+     * 
150
+     * @param  string  $name
151
+     * 
152
+     * @return string
153
+     */
154
+    protected function normalizeName($name)
155 155
     {
156
-		return ViewName::normalize($name);
156
+        return ViewName::normalize($name);
157 157
     }
158 158
 
159
-	/**
160
-	 * Create a new view instance from the given arguments.
161
-	 * 
162
-	 * @param  string  $file  View filename
163
-	 * * @param  string  $path  Path filename
164
-	 * @param  array  $data  Array of values
165
-	 * 
166
-	 * @return \Syscodes\Contracts\View\View
167
-	 */
168
-	protected function viewInstance($view, $path, $data)
169
-	{
170
-		return new View($this, $this->getEngineFromPath($path), $view, $path, $data);
171
-	}
159
+    /**
160
+     * Create a new view instance from the given arguments.
161
+     * 
162
+     * @param  string  $file  View filename
163
+     * * @param  string  $path  Path filename
164
+     * @param  array  $data  Array of values
165
+     * 
166
+     * @return \Syscodes\Contracts\View\View
167
+     */
168
+    protected function viewInstance($view, $path, $data)
169
+    {
170
+        return new View($this, $this->getEngineFromPath($path), $view, $path, $data);
171
+    }
172 172
 	
173
-	/**
174
-	 * Get the appropriate view engine for the given path.
175
-	 * 
176
-	 * @param  string  $path
177
-	 * 
178
-	 * @return \Illuminate\Contracts\View\Engine
179
-	 * 
180
-	 * @throws \InvalidArgumentException
181
-	 */
182
-	public function getEngineFromPath($path)
183
-	{
184
-		if ( ! $extension = $this->getExtension($path)) {
185
-			throw new InvalidArgumentException("Unrecognized extension in file: {$path}");
186
-		}
173
+    /**
174
+     * Get the appropriate view engine for the given path.
175
+     * 
176
+     * @param  string  $path
177
+     * 
178
+     * @return \Illuminate\Contracts\View\Engine
179
+     * 
180
+     * @throws \InvalidArgumentException
181
+     */
182
+    public function getEngineFromPath($path)
183
+    {
184
+        if ( ! $extension = $this->getExtension($path)) {
185
+            throw new InvalidArgumentException("Unrecognized extension in file: {$path}");
186
+        }
187 187
 		
188
-		$engine = $this->extensions[$extension];
188
+        $engine = $this->extensions[$extension];
189 189
 		
190
-		return $this->engines->resolve($engine);
191
-	}
190
+        return $this->engines->resolve($engine);
191
+    }
192 192
 	
193
-	/**
194
-	 * Get the extension used by the view file.
195
-	 * 
196
-	 * @param  string  $path
197
-	 * 
198
-	 * @return string
199
-	 */
200
-	protected function getExtension($path)
201
-	{
202
-		$extensions = array_keys($this->extensions);
193
+    /**
194
+     * Get the extension used by the view file.
195
+     * 
196
+     * @param  string  $path
197
+     * 
198
+     * @return string
199
+     */
200
+    protected function getExtension($path)
201
+    {
202
+        $extensions = array_keys($this->extensions);
203 203
 		
204
-		return Arr::first($extensions, function($key, $value) use ($path) {
205
-			return Str::endsWith($path, '.'.$value);
206
-		});
207
-	}
204
+        return Arr::first($extensions, function($key, $value) use ($path) {
205
+            return Str::endsWith($path, '.'.$value);
206
+        });
207
+    }
208 208
 	
209
-	/**
210
-	 * Call the creator for a given view.
211
-	 * 
212
-	 * @param  \Syscodes\View\View  $view
213
-	 * 
214
-	 * @return void
215
-	 */
216
-	public function callCreator(View $view)
217
-	{
218
-		$this->events->dispatch('creating: '.$view->getView(), [$view]);
219
-	}
209
+    /**
210
+     * Call the creator for a given view.
211
+     * 
212
+     * @param  \Syscodes\View\View  $view
213
+     * 
214
+     * @return void
215
+     */
216
+    public function callCreator(View $view)
217
+    {
218
+        $this->events->dispatch('creating: '.$view->getView(), [$view]);
219
+    }
220 220
 	
221
-	/**
222
-	 * Get the extension to engine bindings.
223
-	 * 
224
-	 * @return array
225
-	 */
226
-	public function getExtensions()
227
-	{
228
-		return $this->extensions;
229
-	}
221
+    /**
222
+     * Get the extension to engine bindings.
223
+     * 
224
+     * @return array
225
+     */
226
+    public function getExtensions()
227
+    {
228
+        return $this->extensions;
229
+    }
230 230
 	
231
-	/**
232
-	 * Add a piece of shared data to the environment.
233
-	 * 
234
-	 * @param  array|string  $key
235
-	 * @param  mixed|null  $value  
236
-	 * 
237
-	 * @return mixed
238
-	 */
239
-	public function share($key, $value = null)
240
-	{
241
-		$keys = is_array($key) ? $key : [$key => $value];
231
+    /**
232
+     * Add a piece of shared data to the environment.
233
+     * 
234
+     * @param  array|string  $key
235
+     * @param  mixed|null  $value  
236
+     * 
237
+     * @return mixed
238
+     */
239
+    public function share($key, $value = null)
240
+    {
241
+        $keys = is_array($key) ? $key : [$key => $value];
242 242
 		
243
-		foreach ($keys as $key => $value) {
244
-			$this->shared[$key] = $value;
245
-		}
243
+        foreach ($keys as $key => $value) {
244
+            $this->shared[$key] = $value;
245
+        }
246 246
 		
247
-		return $value;
248
-	}
247
+        return $value;
248
+    }
249 249
 
250
-	/**
251
-	 * Replace the namespace hints for the given namespace.
252
-	 * 
253
-	 * @param  string  $namespace
254
-	 * @param  string|array  $hints
255
-	 * 
256
-	 * @return $this
257
-	 */
258
-	public function replaceNamespace($namespace, $hints)
259
-	{
260
-		$this->finder->replaceNamespace($namespace, $hints);
250
+    /**
251
+     * Replace the namespace hints for the given namespace.
252
+     * 
253
+     * @param  string  $namespace
254
+     * @param  string|array  $hints
255
+     * 
256
+     * @return $this
257
+     */
258
+    public function replaceNamespace($namespace, $hints)
259
+    {
260
+        $this->finder->replaceNamespace($namespace, $hints);
261 261
 
262
-		return $this;
263
-	}
262
+        return $this;
263
+    }
264 264
 
265
-	/**
266
-	 * Increment the rendering counter.
267
-	 * 
268
-	 * @return void
269
-	 */
270
-	public function increment()
271
-	{
272
-		return $this->renderCount++;
273
-	}
265
+    /**
266
+     * Increment the rendering counter.
267
+     * 
268
+     * @return void
269
+     */
270
+    public function increment()
271
+    {
272
+        return $this->renderCount++;
273
+    }
274 274
 
275
-	/**
276
-	 * Decrement the rendering counter.
277
-	 * 
278
-	 * @return void
279
-	 */
280
-	public function decrement()
281
-	{
282
-		return $this->renderCount--;
283
-	}
275
+    /**
276
+     * Decrement the rendering counter.
277
+     * 
278
+     * @return void
279
+     */
280
+    public function decrement()
281
+    {
282
+        return $this->renderCount--;
283
+    }
284 284
 
285
-	/**
286
-	 * Check if there are no active render operations.
287
-	 * 
288
-	 * @return bool
289
-	 */
290
-	public function doneRendering()
291
-	{
292
-		return $this->renderCount == 0;
293
-	}
285
+    /**
286
+     * Check if there are no active render operations.
287
+     * 
288
+     * @return bool
289
+     */
290
+    public function doneRendering()
291
+    {
292
+        return $this->renderCount == 0;
293
+    }
294 294
 
295
-	/**
296
-	 * Flush all of the parser state like sections.
297
-	 * 
298
-	 * @return void
299
-	 */
300
-	public function flushState()
301
-	{
302
-		$this->renderCount = 0;
295
+    /**
296
+     * Flush all of the parser state like sections.
297
+     * 
298
+     * @return void
299
+     */
300
+    public function flushState()
301
+    {
302
+        $this->renderCount = 0;
303 303
 
304
-		$this->flushSections();
305
-	}
304
+        $this->flushSections();
305
+    }
306 306
 
307
-	/**
308
-	 * Flush all of the section contents if done rendering.
309
-	 * 
310
-	 * @return void
311
-	 */
312
-	public function flushStateIfDoneRendering()
313
-	{
314
-		if ($this->doneRendering()) {
315
-			$this->flushState();
316
-		}
317
-	}
307
+    /**
308
+     * Flush all of the section contents if done rendering.
309
+     * 
310
+     * @return void
311
+     */
312
+    public function flushStateIfDoneRendering()
313
+    {
314
+        if ($this->doneRendering()) {
315
+            $this->flushState();
316
+        }
317
+    }
318 318
 
319
-	/**
320
-	 * Get all of the shared data for the environment.
321
-	 * 
322
-	 * @return void
323
-	 */
324
-	public function getShared()
325
-	{
326
-		return $this->shared;
327
-	}
319
+    /**
320
+     * Get all of the shared data for the environment.
321
+     * 
322
+     * @return void
323
+     */
324
+    public function getShared()
325
+    {
326
+        return $this->shared;
327
+    }
328 328
 
329
-	/**
330
-	 * Get the IoC container instance.
331
-	 * 
332
-	 * @return \Syscodes\Contracts\Container\Container
333
-	 */
334
-	public function getContainer()
335
-	{
336
-		return $this->container;
337
-	}
329
+    /**
330
+     * Get the IoC container instance.
331
+     * 
332
+     * @return \Syscodes\Contracts\Container\Container
333
+     */
334
+    public function getContainer()
335
+    {
336
+        return $this->container;
337
+    }
338 338
 
339
-	/**
340
-	 * Set the IoC container instance.
341
-	 * 
342
-	 * @param  \Syscodes\Contracts\Container\Container  $container
343
-	 * 
344
-	 * @return void
345
-	 */
346
-	public function setContainer($container)
347
-	{
348
-		$this->container = $container;
349
-	}
339
+    /**
340
+     * Set the IoC container instance.
341
+     * 
342
+     * @param  \Syscodes\Contracts\Container\Container  $container
343
+     * 
344
+     * @return void
345
+     */
346
+    public function setContainer($container)
347
+    {
348
+        $this->container = $container;
349
+    }
350 350
 }
351 351
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/View/Concerns/ManagesLayouts.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -32,178 +32,178 @@
 block discarded – undo
32 32
  */
33 33
 trait ManagesLayouts
34 34
 {	
35
-	/**
36
-	 * Started blocks.
37
-	 * 
38
-	 * @var array $sections
39
-	 */
40
-	protected $sections = [];
35
+    /**
36
+     * Started blocks.
37
+     * 
38
+     * @var array $sections
39
+     */
40
+    protected $sections = [];
41 41
 	
42
-	/**
43
-	 * The stack of in-progress sections.
44
-	 * 
45
-	 * @var array $sectionStack
46
-	 */
47
-	protected $sectionStack = [];
42
+    /**
43
+     * The stack of in-progress sections.
44
+     * 
45
+     * @var array $sectionStack
46
+     */
47
+    protected $sectionStack = [];
48 48
 	
49
-	/**
50
-	 * Starting section.
51
-	 * 
52
-	 * @param  string  $section
53
-	 * @param  string|null  $content  
54
-	 * 
55
-	 * @return array
56
-	 */
57
-	public function beginSection($section, $content = null)
58
-	{
59
-		if (null === $content) {
60
-			if (ob_start()) {
61
-				$this->sectionStack[] = $section;
62
-			}
63
-		} else {
64
-			$this->extendSection($section, $content instanceof View ? $content : e($content));
65
-		}
66
-	}
49
+    /**
50
+     * Starting section.
51
+     * 
52
+     * @param  string  $section
53
+     * @param  string|null  $content  
54
+     * 
55
+     * @return array
56
+     */
57
+    public function beginSection($section, $content = null)
58
+    {
59
+        if (null === $content) {
60
+            if (ob_start()) {
61
+                $this->sectionStack[] = $section;
62
+            }
63
+        } else {
64
+            $this->extendSection($section, $content instanceof View ? $content : e($content));
65
+        }
66
+    }
67 67
 	
68
-	/**
69
-	 * Append content to a given section.
70
-	 * 
71
-	 * @param  string  $section
72
-	 * @param  string  $content
73
-	 * 
74
-	 * @return void
75
-	 */
76
-	protected function extendSection($section, $content)
77
-	{
78
-		if (isset($this->sections[$section])) {
79
-			$content = str_replace(static::parent(), $content, $this->sections[$section]);
80
-		}
68
+    /**
69
+     * Append content to a given section.
70
+     * 
71
+     * @param  string  $section
72
+     * @param  string  $content
73
+     * 
74
+     * @return void
75
+     */
76
+    protected function extendSection($section, $content)
77
+    {
78
+        if (isset($this->sections[$section])) {
79
+            $content = str_replace(static::parent(), $content, $this->sections[$section]);
80
+        }
81 81
 		
82
-		$this->sections[$section] = $content;
83
-	}
82
+        $this->sections[$section] = $content;
83
+    }
84 84
 	
85
-	/**
86
-	 * Close and printing section.
87
-	 * 
88
-	 * @return string
89
-	 */
90
-	public function showSection()
91
-	{
92
-		if (empty($this->sectionStack)) {
93
-			return '';
94
-		}
85
+    /**
86
+     * Close and printing section.
87
+     * 
88
+     * @return string
89
+     */
90
+    public function showSection()
91
+    {
92
+        if (empty($this->sectionStack)) {
93
+            return '';
94
+        }
95 95
 		
96
-		return $this->giveContent($this->stopSection());
97
-	}
96
+        return $this->giveContent($this->stopSection());
97
+    }
98 98
 	
99
-	/**
100
-	 * Give sections the page view from the master page.
101
-	 * 
102
-	 * @param  string  $name
103
-	 * 
104
-	 * @return string
105
-	 */
106
-	public function giveContent($name, $default = '')
107
-	{
108
-		$sectionContent = $default instanceof View ? $default : e($default);
99
+    /**
100
+     * Give sections the page view from the master page.
101
+     * 
102
+     * @param  string  $name
103
+     * 
104
+     * @return string
105
+     */
106
+    public function giveContent($name, $default = '')
107
+    {
108
+        $sectionContent = $default instanceof View ? $default : e($default);
109 109
 		
110
-		if (isset($this->sections[$name])) {
111
-			$sectionContent = $this->sections[$name];
112
-		}
110
+        if (isset($this->sections[$name])) {
111
+            $sectionContent = $this->sections[$name];
112
+        }
113 113
 		
114
-		return str_replace(static::parent(), '', $sectionContent);
115
-	}
114
+        return str_replace(static::parent(), '', $sectionContent);
115
+    }
116 116
 	
117
-	/**
118
-	 * Closing section.
119
-	 * 
120
-	 * @param  bool  $overwrite  
121
-	 * 
122
-	 * @return mixed
123
-	 * 
124
-	 * @throws \InvalidArgumentException
125
-	 */
126
-	public function stopSection($overwrite = false)
127
-	{
128
-		if (empty($this->sectionStack)) {
129
-			throw new InvalidArgumentException('You cannot finish a section without first starting with one.');
130
-		}
117
+    /**
118
+     * Closing section.
119
+     * 
120
+     * @param  bool  $overwrite  
121
+     * 
122
+     * @return mixed
123
+     * 
124
+     * @throws \InvalidArgumentException
125
+     */
126
+    public function stopSection($overwrite = false)
127
+    {
128
+        if (empty($this->sectionStack)) {
129
+            throw new InvalidArgumentException('You cannot finish a section without first starting with one.');
130
+        }
131 131
 		
132
-		$last = array_pop($this->sectionStack);
132
+        $last = array_pop($this->sectionStack);
133 133
 		
134
-		if ($overwrite) { 
135
-			$this->sections[$last] = ob_get_clean();
136
-		} else {
137
-			$this->extendSection($last, ob_get_clean());
138
-		}
134
+        if ($overwrite) { 
135
+            $this->sections[$last] = ob_get_clean();
136
+        } else {
137
+            $this->extendSection($last, ob_get_clean());
138
+        }
139 139
 		
140
-		return $last;
141
-	}
140
+        return $last;
141
+    }
142 142
 	
143
-	/**
144
-	 * Stop injecting content into a section and append it.
145
-	 * 
146
-	 * @return string
147
-	 * 
148
-	 * @throws \InvalidArgumentException
149
-	 */
150
-	public function appendSection()
151
-	{
152
-		if (empty($this->sectionStack)) {
153
-			throw new InvalidArgumentException('You cannot finish a section without first starting with one.');
154
-		}
143
+    /**
144
+     * Stop injecting content into a section and append it.
145
+     * 
146
+     * @return string
147
+     * 
148
+     * @throws \InvalidArgumentException
149
+     */
150
+    public function appendSection()
151
+    {
152
+        if (empty($this->sectionStack)) {
153
+            throw new InvalidArgumentException('You cannot finish a section without first starting with one.');
154
+        }
155 155
 		
156
-		$last = array_pop($this->sectionStack);
156
+        $last = array_pop($this->sectionStack);
157 157
 		
158
-		if (isset($this->sections[$last])) {
159
-			$this->sections[$last] .= ob_get_clean();
160
-		} else {
161
-			$this->sections[$last] = ob_get_clean();
162
-		}
158
+        if (isset($this->sections[$last])) {
159
+            $this->sections[$last] .= ob_get_clean();
160
+        } else {
161
+            $this->sections[$last] = ob_get_clean();
162
+        }
163 163
 		
164
-		return $last;
165
-	}
164
+        return $last;
165
+    }
166 166
 	
167
-	/**
168
-	 * Check if section exists.
169
-	 * 
170
-	 * @param  string  $name
171
-	 * 
172
-	 * @return bool
173
-	 */
174
-	public function hasSection($name)
175
-	{
176
-		return array_key_exists($name, $this->sections);
177
-	}
167
+    /**
168
+     * Check if section exists.
169
+     * 
170
+     * @param  string  $name
171
+     * 
172
+     * @return bool
173
+     */
174
+    public function hasSection($name)
175
+    {
176
+        return array_key_exists($name, $this->sections);
177
+    }
178 178
 	
179
-	/**
180
-	 * Get the entire array of sections.
181
-	 * 
182
-	 * @return array
183
-	 */
184
-	public function getSections()
185
-	{
186
-		return $this->sections;
187
-	}
179
+    /**
180
+     * Get the entire array of sections.
181
+     * 
182
+     * @return array
183
+     */
184
+    public function getSections()
185
+    {
186
+        return $this->sections;
187
+    }
188 188
 	
189
-	/**
190
-	 * Replace the @parent directive to a placeholder.
191
-	 * 
192
-	 * @return string
193
-	 */
194
-	public static function parent()
195
-	{
196
-		return '@parent';
197
-	}
189
+    /**
190
+     * Replace the @parent directive to a placeholder.
191
+     * 
192
+     * @return string
193
+     */
194
+    public static function parent()
195
+    {
196
+        return '@parent';
197
+    }
198 198
 	
199
-	/**
200
-	 * Flush all of the section contents.
201
-	 * 
202
-	 * @return void
203
-	 */
204
-	public function flushSections()
205
-	{
206
-		$this->sections     = [];
207
-		$this->sectionStack = [];
208
-	}
199
+    /**
200
+     * Flush all of the section contents.
201
+     * 
202
+     * @return void
203
+     */
204
+    public function flushSections()
205
+    {
206
+        $this->sections     = [];
207
+        $this->sectionStack = [];
208
+    }
209 209
 }
210 210
\ No newline at end of file
Please login to merge, or discard this patch.