Passed
Push — 0.7.0 ( c2424f...06148a )
by Alexander
02:45
created
src/components/Http/Contributors/Files.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -43,22 +43,22 @@
 block discarded – undo
43 43
     }
44 44
 
45 45
     /**
46
-	 * {@inheritdoc}
47
-	 */
48
-	public function replace(array $files = [])
49
-	{
50
-		$this->parameters = [];
46
+     * {@inheritdoc}
47
+     */
48
+    public function replace(array $files = [])
49
+    {
50
+        $this->parameters = [];
51 51
         $this->add($files);
52
-	}
52
+    }
53 53
 
54
-	/**
55
-	 * {@inheritdoc}
56
-	 */
57
-	public function add(array $files = [])
58
-	{
54
+    /**
55
+     * {@inheritdoc}
56
+     */
57
+    public function add(array $files = [])
58
+    {
59 59
         foreach ($files as $key => $file)
60 60
         {
61 61
             $this->set($key, $file);
62 62
         }
63
-	}
63
+    }
64 64
 }
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Contributors/Status.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -30,96 +30,96 @@
 block discarded – undo
30 30
  */
31 31
 class Status 
32 32
 {
33
-	/**
34
-	 * The HTTP status code.
35
-	 *
36
-	 * @var int $status
37
-	 */
38
-	protected $status = 200;
33
+    /**
34
+     * The HTTP status code.
35
+     *
36
+     * @var int $status
37
+     */
38
+    protected $status = 200;
39 39
 
40
-	/**
41
-	 * An array of status codes and messages.
42
-	 *
43
-	 * @var array $statusCode
44
-	 */
45
-	public $statusCodes = [
46
-		// 1xx: Informational
47
-		100 => 'Continue',
48
-		101 => 'Switching Protocols',
49
-		102 => 'Processing',
40
+    /**
41
+     * An array of status codes and messages.
42
+     *
43
+     * @var array $statusCode
44
+     */
45
+    public $statusCodes = [
46
+        // 1xx: Informational
47
+        100 => 'Continue',
48
+        101 => 'Switching Protocols',
49
+        102 => 'Processing',
50 50
 
51
-		// 2xx: Success
52
-		200 => 'OK',
53
-		201 => 'Created',
54
-		202 => 'Accepted',
55
-		203 => 'Non-Authoritative Information',
56
-		204 => 'No Content',
57
-		205 => 'Reset Content',
58
-		206 => 'Partial Content',
59
-		207 => 'Multi-Status',
60
-		208 => 'Already Reported',
61
-		226 => 'IM Used',
51
+        // 2xx: Success
52
+        200 => 'OK',
53
+        201 => 'Created',
54
+        202 => 'Accepted',
55
+        203 => 'Non-Authoritative Information',
56
+        204 => 'No Content',
57
+        205 => 'Reset Content',
58
+        206 => 'Partial Content',
59
+        207 => 'Multi-Status',
60
+        208 => 'Already Reported',
61
+        226 => 'IM Used',
62 62
 
63
-		// 3xx: Redirection
64
-		300 => 'Multiple Choices',
65
-		301 => 'Moved Permanently',
66
-		302 => 'Found',
67
-		303 => 'See Other',
68
-		304 => 'Not Modified',
69
-		305 => 'Use Proxy',
70
-		307 => 'Temporary Redirect',
71
-		308 => 'Permanent Redirect',
63
+        // 3xx: Redirection
64
+        300 => 'Multiple Choices',
65
+        301 => 'Moved Permanently',
66
+        302 => 'Found',
67
+        303 => 'See Other',
68
+        304 => 'Not Modified',
69
+        305 => 'Use Proxy',
70
+        307 => 'Temporary Redirect',
71
+        308 => 'Permanent Redirect',
72 72
 
73
-		// 4xx: Client error
74
-		400 => 'Bad Request',
75
-		401 => 'Unauthorized',
76
-		402 => 'Payment Required',
77
-		403 => 'Forbidden',
78
-		404 => 'Not Found',
79
-		405 => 'Method Not Allowed',
80
-		406 => 'Not Acceptable',
81
-		407 => 'Proxy Authentication Required',
82
-		408 => 'Request Timeout',
83
-		409 => 'Conflict',
84
-		410 => 'Gone',
85
-		411 => 'Length Required',
86
-		412 => 'Precondition Failed',
87
-		413 => 'Request Entity Too Large',
88
-		414 => 'Request-URI Too Long',
89
-		415 => 'Unsupported Media Type',
90
-		416 => 'Requested Range Not Satisfiable',
91
-		417 => 'Expectation Failed',
92
-		418 => 'I\'m a Teapot',
93
-		// 419 (Authentication Timeout) is a non-standard status code with unknown origin
94
-		421 => 'Misdirected Request',
95
-		422 => 'Unprocessable Entity',
96
-		423 => 'Locked',
97
-		424 => 'Failed Dependency',
98
-		426 => 'Upgrade Required',
99
-		428 => 'Precondition Required',
100
-		429 => 'Too Many Requests',
101
-		431 => 'Request Header Fields Too Large',
102
-		451 => 'Unavailable For Legal Reasons',
73
+        // 4xx: Client error
74
+        400 => 'Bad Request',
75
+        401 => 'Unauthorized',
76
+        402 => 'Payment Required',
77
+        403 => 'Forbidden',
78
+        404 => 'Not Found',
79
+        405 => 'Method Not Allowed',
80
+        406 => 'Not Acceptable',
81
+        407 => 'Proxy Authentication Required',
82
+        408 => 'Request Timeout',
83
+        409 => 'Conflict',
84
+        410 => 'Gone',
85
+        411 => 'Length Required',
86
+        412 => 'Precondition Failed',
87
+        413 => 'Request Entity Too Large',
88
+        414 => 'Request-URI Too Long',
89
+        415 => 'Unsupported Media Type',
90
+        416 => 'Requested Range Not Satisfiable',
91
+        417 => 'Expectation Failed',
92
+        418 => 'I\'m a Teapot',
93
+        // 419 (Authentication Timeout) is a non-standard status code with unknown origin
94
+        421 => 'Misdirected Request',
95
+        422 => 'Unprocessable Entity',
96
+        423 => 'Locked',
97
+        424 => 'Failed Dependency',
98
+        426 => 'Upgrade Required',
99
+        428 => 'Precondition Required',
100
+        429 => 'Too Many Requests',
101
+        431 => 'Request Header Fields Too Large',
102
+        451 => 'Unavailable For Legal Reasons',
103 103
 
104
-		// 5xx: Server error
105
-		500 => 'Internal Server Error',
106
-		501 => 'Not Implemented',
107
-		502 => 'Bad Gateway',
108
-		503 => 'Service Unavailable',
109
-		504 => 'Gateway Timeout',
110
-		505 => 'HTTP Version Not Supported',
111
-		506 => 'Variant Also Negotiates',
112
-		507 => 'Insufficient Storage',
113
-		508 => 'Loop Detected',
114
-		509 => 'Bandwidth Limit Exceeded',
115
-		510 => 'Not Extended',
116
-		511 => 'Network Authentication Required'
117
-	];
104
+        // 5xx: Server error
105
+        500 => 'Internal Server Error',
106
+        501 => 'Not Implemented',
107
+        502 => 'Bad Gateway',
108
+        503 => 'Service Unavailable',
109
+        504 => 'Gateway Timeout',
110
+        505 => 'HTTP Version Not Supported',
111
+        506 => 'Variant Also Negotiates',
112
+        507 => 'Insufficient Storage',
113
+        508 => 'Loop Detected',
114
+        509 => 'Bandwidth Limit Exceeded',
115
+        510 => 'Not Extended',
116
+        511 => 'Network Authentication Required'
117
+    ];
118 118
 
119
-	/**
120
-	 * Gets string of status code.
121
-	 * 
122
-	 * @var string $statusText
123
-	 */
124
-	protected $statusText;
119
+    /**
120
+     * Gets string of status code.
121
+     * 
122
+     * @var string $statusText
123
+     */
124
+    protected $statusText;
125 125
 }
126 126
\ 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
@@ -34,31 +34,31 @@  discard block
 block discarded – undo
34 34
 final class Inputs extends Parameters
35 35
 {
36 36
     /**
37
-	 * {@inheritdoc}
38
-	 */
39
-	public function all(string $key = null)
40
-	{
41
-		return parent::all($key);
37
+     * {@inheritdoc}
38
+     */
39
+    public function all(string $key = null)
40
+    {
41
+        return parent::all($key);
42 42
     }
43 43
     
44 44
     /**
45
-	 * {@inheritdoc}
46
-	 */
47
-	public function replace(array $inputs = [])
48
-	{
49
-		$this->parameters = [];
45
+     * {@inheritdoc}
46
+     */
47
+    public function replace(array $inputs = [])
48
+    {
49
+        $this->parameters = [];
50 50
         $this->add($inputs);
51
-	}
51
+    }
52 52
 
53
-	/**
54
-	 * Adds input values.
53
+    /**
54
+     * Adds input values.
55 55
      * 
56 56
      * @param  array  $inputs
57 57
      * 
58 58
      * @return mixed
59
-	 */
60
-	public function add(array $inputs = [])
61
-	{
59
+     */
60
+    public function add(array $inputs = [])
61
+    {
62 62
         foreach ($inputs as $key => $file)
63 63
         {
64 64
             $this->set($key, $file);
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
     }
67 67
     
68 68
     /**
69
-	 * Gets a string input value by name.
70
-	 *
71
-	 * @param  string  $key
72
-	 * @param  string|null  $default  (null by default)
73
-	 *
74
-	 * @return string|null
75
-	 */
76
-	public function get($key, $default = null)
77
-	{
69
+     * Gets a string input value by name.
70
+     *
71
+     * @param  string  $key
72
+     * @param  string|null  $default  (null by default)
73
+     *
74
+     * @return string|null
75
+     */
76
+    public function get($key, $default = null)
77
+    {
78 78
         if (null !== $default && ! is_scalar($default) && ! (is_object($default)) && ! method_exist($default, '__toString'))
79 79
         {
80 80
             throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__));
@@ -91,20 +91,20 @@  discard block
 block discarded – undo
91 91
     }
92 92
     
93 93
     /**
94
-	 * Sets an input by name.
95
-	 *
96
-	 * @param  string  $key
97
-	 * @param  string|array|null  $value 
98
-	 *
99
-	 * @return mixed
100
-	 */
101
-	public function set($key, $value)
102
-	{
94
+     * Sets an input by name.
95
+     *
96
+     * @param  string  $key
97
+     * @param  string|array|null  $value 
98
+     *
99
+     * @return mixed
100
+     */
101
+    public function set($key, $value)
102
+    {
103 103
         if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! method_exist($value, '__toString'))
104 104
         {
105 105
             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__));
106 106
         }
107 107
 
108
-		$this->parameters[$key] = $value;
109
-	}
108
+        $this->parameters[$key] = $value;
109
+    }
110 110
 }
111 111
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Contributors/Headers.php 3 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -34,255 +34,255 @@
 block discarded – undo
34 34
  */
35 35
 class Headers implements IteratorAggregate, Countable
36 36
 {
37
-	/**
38
-	 * An array of HTTP headers.
39
-	 * 
40
-	 * @var array $herders
41
-	 */
42
-	protected $headers = [];
37
+    /**
38
+     * An array of HTTP headers.
39
+     * 
40
+     * @var array $herders
41
+     */
42
+    protected $headers = [];
43 43
 	
44
-	/**
45
-	 * Specifies the directives for the caching mechanisms in both
46
-	 * the requests and the responses.
47
-	 * 
48
-	 * @var array $cacheControl
49
-	 */
50
-	protected $cacheControl = [];
44
+    /**
45
+     * Specifies the directives for the caching mechanisms in both
46
+     * the requests and the responses.
47
+     * 
48
+     * @var array $cacheControl
49
+     */
50
+    protected $cacheControl = [];
51 51
 	
52
-	/**
53
-	 * Constructor. The Headers class instance.
54
-	 * 
55
-	 * @param  array  $headers
56
-	 * 
57
-	 * @return void
58
-	 */
59
-	public function __construct(array $headers = [])
60
-	{
61
-		foreach ($headers as $key => $values)
62
-		{
63
-			$this->set($key, $values);
64
-		}
65
-	}
52
+    /**
53
+     * Constructor. The Headers class instance.
54
+     * 
55
+     * @param  array  $headers
56
+     * 
57
+     * @return void
58
+     */
59
+    public function __construct(array $headers = [])
60
+    {
61
+        foreach ($headers as $key => $values)
62
+        {
63
+            $this->set($key, $values);
64
+        }
65
+    }
66 66
 	
67
-	/**
68
-	 * Returns all the headers.
69
-	 * 
70
-	 * @return array
71
-	 */
72
-	public function all()
73
-	{
74
-		return $this->headers;
75
-	}
67
+    /**
68
+     * Returns all the headers.
69
+     * 
70
+     * @return array
71
+     */
72
+    public function all()
73
+    {
74
+        return $this->headers;
75
+    }
76 76
 	
77
-	/**
78
-	 * Returns the parameter keys.
79
-	 * 
80
-	 * @return array An array of parameter keys
81
-	 */
82
-	public function keys()
83
-	{
84
-		return array_keys($this->all());
85
-	}
77
+    /**
78
+     * Returns the parameter keys.
79
+     * 
80
+     * @return array An array of parameter keys
81
+     */
82
+    public function keys()
83
+    {
84
+        return array_keys($this->all());
85
+    }
86 86
 	
87
-	/**
88
-	 * Replaces the current HTTP headers by a new set.
89
-	 * 
90
-	 * @param  array  $headers
91
-	 * 
92
-	 * @return void
93
-	 */
94
-	public function replace(array $headers = [])
95
-	{
96
-		$this->headers = [];
97
-		$this->add($headers);
98
-	}
87
+    /**
88
+     * Replaces the current HTTP headers by a new set.
89
+     * 
90
+     * @param  array  $headers
91
+     * 
92
+     * @return void
93
+     */
94
+    public function replace(array $headers = [])
95
+    {
96
+        $this->headers = [];
97
+        $this->add($headers);
98
+    }
99 99
 	
100
-	/**
101
-	 * Adds multiple header to the queue.
102
-	 * 
103
-	 * @param  array  $headers  The header name
104
-	 * 
105
-	 * @return mixed
106
-	 */
107
-	public function add(array $headers)
108
-	{
109
-		foreach ($headers as $key => $values)
110
-		{
111
-			$this->set($key, $values);
112
-		}
100
+    /**
101
+     * Adds multiple header to the queue.
102
+     * 
103
+     * @param  array  $headers  The header name
104
+     * 
105
+     * @return mixed
106
+     */
107
+    public function add(array $headers)
108
+    {
109
+        foreach ($headers as $key => $values)
110
+        {
111
+            $this->set($key, $values);
112
+        }
113 113
 		
114
-		return $this;
115
-	}
114
+        return $this;
115
+    }
116 116
 	
117
-	/**
118
-	 * Returns the headers, with original capitalizations.
119
-	 * 
120
-	 * @return array An array of headers
121
-	 */
122
-	public function allPreserveCase()
123
-	{
124
-		$headers = [];
117
+    /**
118
+     * Returns the headers, with original capitalizations.
119
+     * 
120
+     * @return array An array of headers
121
+     */
122
+    public function allPreserveCase()
123
+    {
124
+        $headers = [];
125 125
 		
126
-		foreach ($this->all() as $name => $value)
127
-		{
128
-			$headers[$name] = $value;
129
-		}
126
+        foreach ($this->all() as $name => $value)
127
+        {
128
+            $headers[$name] = $value;
129
+        }
130 130
 		
131
-		return $headers;
132
-	}
131
+        return $headers;
132
+    }
133 133
 	
134
-	/**
135
-	 * Gets a header value by name.
136
-	 *
137
-	 * @param  string  $key  The header name, or null for all headers
138
-	 * @param  string|null  $default  The default value
139
-	 * @param  bool  $option  Whether to return the option value or all header values (true by default)
140
-	 *
141
-	 * @return mixed
142
-	 */
143
-	public function get($key, $default =  null, $option = true)
144
-	{
145
-		$key = str_replace('_', '-', strtolower($key));
134
+    /**
135
+     * Gets a header value by name.
136
+     *
137
+     * @param  string  $key  The header name, or null for all headers
138
+     * @param  string|null  $default  The default value
139
+     * @param  bool  $option  Whether to return the option value or all header values (true by default)
140
+     *
141
+     * @return mixed
142
+     */
143
+    public function get($key, $default =  null, $option = true)
144
+    {
145
+        $key = str_replace('_', '-', strtolower($key));
146 146
 		
147
-		$headers = $this->all();
147
+        $headers = $this->all();
148 148
 		
149
-		if ( ! array_key_exists($key, $headers))
150
-		{
151
-			if (null === $default)
152
-			{
153
-				return $option ? null : [];
154
-			}
149
+        if ( ! array_key_exists($key, $headers))
150
+        {
151
+            if (null === $default)
152
+            {
153
+                return $option ? null : [];
154
+            }
155 155
 			
156
-			return $option ? $default : [$default];
157
-		}
156
+            return $option ? $default : [$default];
157
+        }
158 158
 		
159
-		if ($option)
160
-		{
161
-			return count($headers[$key]) ? $headers[$key][0] : $default;
162
-		}
159
+        if ($option)
160
+        {
161
+            return count($headers[$key]) ? $headers[$key][0] : $default;
162
+        }
163 163
 		
164
-		return $headers[$key];
165
-	}
164
+        return $headers[$key];
165
+    }
166 166
 
167
-	/**
168
-	 * Sets a header by name.
169
-	 * 
170
-	 * @param  string  $key  The header name
171
-	 * @param  string  $values  The value or an array of values
172
-	 * @param  bool  $replace  If you want to replace the value exists by the header, 
173
-	 * 					       it is not overwritten (true by default) / overwritten when it is false
174
-	 *
175
-	 * @return $this
176
-	 */
177
-	public function set($key, $values, $replace = true)
178
-	{
179
-		$key = str_replace('_', '-', strtolower($key));
167
+    /**
168
+     * Sets a header by name.
169
+     * 
170
+     * @param  string  $key  The header name
171
+     * @param  string  $values  The value or an array of values
172
+     * @param  bool  $replace  If you want to replace the value exists by the header, 
173
+     * 					       it is not overwritten (true by default) / overwritten when it is false
174
+     *
175
+     * @return $this
176
+     */
177
+    public function set($key, $values, $replace = true)
178
+    {
179
+        $key = str_replace('_', '-', strtolower($key));
180 180
 
181
-		if (is_array($values))
182
-		{
183
-			$values = array_values($values);
181
+        if (is_array($values))
182
+        {
183
+            $values = array_values($values);
184 184
 
185
-			if (true === $replace || ! isset($this->headers[$key]))
186
-			{
187
-				$this->headers[$key] = $values;
188
-			}
189
-			else
190
-			{
191
-				$this->headers[$key] = array_merge($this->headers[$key], $values);
192
-			}
193
-		}
194
-		else
195
-		{
196
-			if (true === $replace || ! isset($this->headers[$key]))
197
-			{
198
-				$this->headers[$key] = [$values];
199
-			}
200
-			else
201
-			{
202
-				$this->headers[$key][] = $values;
203
-			}
204
-		}
185
+            if (true === $replace || ! isset($this->headers[$key]))
186
+            {
187
+                $this->headers[$key] = $values;
188
+            }
189
+            else
190
+            {
191
+                $this->headers[$key] = array_merge($this->headers[$key], $values);
192
+            }
193
+        }
194
+        else
195
+        {
196
+            if (true === $replace || ! isset($this->headers[$key]))
197
+            {
198
+                $this->headers[$key] = [$values];
199
+            }
200
+            else
201
+            {
202
+                $this->headers[$key][] = $values;
203
+            }
204
+        }
205 205
 
206
-		return $this;
207
-	}
206
+        return $this;
207
+    }
208 208
 
209
-	/**
210
-	 * Returns true if the HTTP header is defined.
211
-	 * 
212
-	 * @param  string  $key  The HTTP header
213
-	 * 
214
-	 * @return bool  true if the parameter exists, false otherwise
215
-	 */
216
-	public function has($key)
217
-	{
218
-		return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
219
-	}
209
+    /**
210
+     * Returns true if the HTTP header is defined.
211
+     * 
212
+     * @param  string  $key  The HTTP header
213
+     * 
214
+     * @return bool  true if the parameter exists, false otherwise
215
+     */
216
+    public function has($key)
217
+    {
218
+        return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
219
+    }
220 220
 
221
-	/**
222
-	 * Removes a header.
223
-	 * 
224
-	 * @param  string  $name  The header name
225
-	 * 
226
-	 * @return mixed
227
-	 */
228
-	public function remove($key)
229
-	{
230
-		$key = str_replace('_', '-', strtolower($key));
221
+    /**
222
+     * Removes a header.
223
+     * 
224
+     * @param  string  $name  The header name
225
+     * 
226
+     * @return mixed
227
+     */
228
+    public function remove($key)
229
+    {
230
+        $key = str_replace('_', '-', strtolower($key));
231 231
 
232
-		unset($this->headers[$key]);
232
+        unset($this->headers[$key]);
233 233
 
234
-		if ('cache-control' === $key)
235
-		{
236
-			$this->cacheControl = [];
237
-		}
238
-	}
234
+        if ('cache-control' === $key)
235
+        {
236
+            $this->cacheControl = [];
237
+        }
238
+    }
239 239
 	
240
-	/**
241
-	 * Returns an iterator for headers.
242
-	 * 
243
-	 * @return \ArrayIterator An \ArrayIterator instance
244
-	 */
245
-	public function getIterator()
246
-	{
247
-		return new ArrayIterator($this->headers);
248
-	}
240
+    /**
241
+     * Returns an iterator for headers.
242
+     * 
243
+     * @return \ArrayIterator An \ArrayIterator instance
244
+     */
245
+    public function getIterator()
246
+    {
247
+        return new ArrayIterator($this->headers);
248
+    }
249 249
 	
250
-	/**
251
-	 * Returns the number of headers.
252
-	 * 
253
-	 * @return int The number of headers
254
-	 */
255
-	public function count()
256
-	{
257
-		return count($this->headers);
258
-	}
250
+    /**
251
+     * Returns the number of headers.
252
+     * 
253
+     * @return int The number of headers
254
+     */
255
+    public function count()
256
+    {
257
+        return count($this->headers);
258
+    }
259 259
 	
260
-	/**
261
-	 * Returns the headers as a string.
262
-	 * 
263
-	 * @return string The headers
264
-	 */
265
-	public function __toString()
266
-	{
267
-		if ( ! $headers = $this->all())
268
-		{
269
-			return '';
270
-		}
260
+    /**
261
+     * Returns the headers as a string.
262
+     * 
263
+     * @return string The headers
264
+     */
265
+    public function __toString()
266
+    {
267
+        if ( ! $headers = $this->all())
268
+        {
269
+            return '';
270
+        }
271 271
 		
272
-		ksort($headers);
273
-		$max     = max(array_map('strlen', array_keys($headers))) + 1;
274
-		$content = '';
272
+        ksort($headers);
273
+        $max     = max(array_map('strlen', array_keys($headers))) + 1;
274
+        $content = '';
275 275
 		
276
-		foreach ($headers as $name => $values)
277
-		{
278
-			$name = ucwords($name, '-');
276
+        foreach ($headers as $name => $values)
277
+        {
278
+            $name = ucwords($name, '-');
279 279
 			
280
-			foreach ($values as $value)
281
-			{
282
-				$content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
283
-			}
284
-		}
280
+            foreach ($values as $value)
281
+            {
282
+                $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
283
+            }
284
+        }
285 285
 
286
-		return $content;
287
-	}
286
+        return $content;
287
+    }
288 288
 }
289 289
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@
 block discarded – undo
140 140
 	 *
141 141
 	 * @return mixed
142 142
 	 */
143
-	public function get($key, $default =  null, $option = true)
143
+	public function get($key, $default = null, $option = true)
144 144
 	{
145 145
 		$key = str_replace('_', '-', strtolower($key));
146 146
 		
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -185,19 +185,16 @@
 block discarded – undo
185 185
 			if (true === $replace || ! isset($this->headers[$key]))
186 186
 			{
187 187
 				$this->headers[$key] = $values;
188
-			}
189
-			else
188
+			} else
190 189
 			{
191 190
 				$this->headers[$key] = array_merge($this->headers[$key], $values);
192 191
 			}
193
-		}
194
-		else
192
+		} else
195 193
 		{
196 194
 			if (true === $replace || ! isset($this->headers[$key]))
197 195
 			{
198 196
 				$this->headers[$key] = [$values];
199
-			}
200
-			else
197
+			} else
201 198
 			{
202 199
 				$this->headers[$key][] = $values;
203 200
 			}
Please login to merge, or discard this patch.
src/components/Http/Contributors/Parameters.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -34,158 +34,158 @@
 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  (null by default) 
105
-	 *
106
-	 * @return mixed
107
-	 */
108
-	public function get($key, $default = null)
109
-	{
110
-		if (Arr::exists($this->parameters, $key))
111
-		{
112
-			return $this->parameters[$key];
113
-		}
100
+    /**
101
+     * Get a parameter array item.
102
+     *
103
+     * @param  string  $key
104
+     * @param  string|null  $default  (null by default) 
105
+     *
106
+     * @return mixed
107
+     */
108
+    public function get($key, $default = null)
109
+    {
110
+        if (Arr::exists($this->parameters, $key))
111
+        {
112
+            return $this->parameters[$key];
113
+        }
114 114
 
115
-		return $default;
116
-	}
115
+        return $default;
116
+    }
117 117
 
118
-	/**
119
-	 * Check if a parameter array item exists.
120
-	 *
121
-	 * @param  string  $key
122
-	 *
123
-	 * @return mixed
124
-	 */
125
-	public function has($key)
126
-	{
127
-		return Arr::exists($this->parameters, $key);
128
-	}
118
+    /**
119
+     * Check if a parameter array item exists.
120
+     *
121
+     * @param  string  $key
122
+     *
123
+     * @return mixed
124
+     */
125
+    public function has($key)
126
+    {
127
+        return Arr::exists($this->parameters, $key);
128
+    }
129 129
 
130
-	/**
131
-	 * Set a parameter array item.
132
-	 *
133
-	 * @param  string  $key
134
-	 * @param  string  $value 
135
-	 *
136
-	 * @return mixed
137
-	 */
138
-	public function set($key, $value)
139
-	{
140
-		$this->parameters[$key] = $value;
141
-	}
130
+    /**
131
+     * Set a parameter array item.
132
+     *
133
+     * @param  string  $key
134
+     * @param  string  $value 
135
+     *
136
+     * @return mixed
137
+     */
138
+    public function set($key, $value)
139
+    {
140
+        $this->parameters[$key] = $value;
141
+    }
142 142
 
143
-	/**
144
-	 * Remove a parameter array item.
145
-	 *
146
-	 * @param  string  $key 
147
-	 *
148
-	 * @return void
149
-	 */
150
-	public function remove($key)
151
-	{
152
-		if ($this->has($key))
153
-		{
154
-			unset($this->parameters[$key]);
155
-		}
156
-	}
143
+    /**
144
+     * Remove a parameter array item.
145
+     *
146
+     * @param  string  $key 
147
+     *
148
+     * @return void
149
+     */
150
+    public function remove($key)
151
+    {
152
+        if ($this->has($key))
153
+        {
154
+            unset($this->parameters[$key]);
155
+        }
156
+    }
157 157
 
158
-	/*
158
+    /*
159 159
 	|-----------------------------------------------------------------
160 160
 	| IteratorAggregate Method
161 161
 	|-----------------------------------------------------------------
162 162
 	*/
163 163
 	
164
-	/**
165
-	 * Retrieve an external iterator.
166
-	 * 
167
-	 * @see    \IteratorAggregate::getIterator
168
-	 * 
169
-	 * @return new \ArrayIterator
170
-	 */
171
-	public function getIterator()
172
-	{
173
-		return new ArrayIterator($this->parameters);
174
-	}
164
+    /**
165
+     * Retrieve an external iterator.
166
+     * 
167
+     * @see    \IteratorAggregate::getIterator
168
+     * 
169
+     * @return new \ArrayIterator
170
+     */
171
+    public function getIterator()
172
+    {
173
+        return new ArrayIterator($this->parameters);
174
+    }
175 175
 	
176
-	/*
176
+    /*
177 177
 	|-----------------------------------------------------------------
178 178
 	| Countable Method
179 179
 	|-----------------------------------------------------------------
180 180
 	*/
181 181
 	
182
-	/**
183
-	 * Returns the number of parameters.
184
-	 * 
185
-	 * @return int The number of parameters
186
-	 */
187
-	public function count()
188
-	{
189
-		return count($this->parameters);
190
-	}
182
+    /**
183
+     * Returns the number of parameters.
184
+     * 
185
+     * @return int The number of parameters
186
+     */
187
+    public function count()
188
+    {
189
+        return count($this->parameters);
190
+    }
191 191
 }
192 192
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Translation/Translator.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -62,11 +62,11 @@
 block discarded – undo
62 62
      */
63 63
     protected $locale;
64 64
 
65
-     /**
66
-     * Boolean value whether the intl libraries exist on the system.
67
-     * 
68
-     * @var bool $intlSupport
69
-     */
65
+        /**
66
+         * Boolean value whether the intl libraries exist on the system.
67
+         * 
68
+         * @var bool $intlSupport
69
+         */
70 70
     protected $intlSupport = false;
71 71
 
72 72
     /**
Please login to merge, or discard this patch.
src/components/Translation/TranslationServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
      */
40 40
     public function register()
41 41
     {
42
-        $this->app->singleton('translator', function () {
42
+        $this->app->singleton('translator', function() {
43 43
             
44 44
             $locale = $this->app['config']['app.locale'];
45 45
             
Please login to merge, or discard this patch.
src/components/Console/Cli.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
  			throw new LenevorException(static::error("Invalid CLI foreground color: {$foreground}."));
211 211
  		}
212 212
 
213
- 		if ( $background !== null && ! Arr::exists(static::$backgroundColors, $background))
213
+ 		if ($background !== null && ! Arr::exists(static::$backgroundColors, $background))
214 214
  		{
215 215
  			throw new LenevorException(static::error("Invalid CLI background color: {$background}."));
216 216
  		}
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 
357 357
 			$first = true;
358 358
 
359
-			array_walk ($lines, function (&$line, $index) use ($pad_left, &$first) {
359
+			array_walk($lines, function(&$line, $index) use ($pad_left, &$first) {
360 360
 
361 361
 				if ( ! $first)
362 362
 				{
363
-					$line = str_repeat(' ', $pad_left) . $line;
363
+					$line = str_repeat(' ', $pad_left).$line;
364 364
 				}
365 365
 				else
366 366
 				{
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -361,8 +361,7 @@  discard block
 block discarded – undo
361 361
 				if ( ! $first)
362 362
 				{
363 363
 					$line = str_repeat(' ', $pad_left) . $line;
364
-				}
365
-				else
364
+				} else
366 365
 				{
367 366
 					$first = false;
368 367
 				}
@@ -595,8 +594,7 @@  discard block
 block discarded – undo
595 594
 			if ($default !== null)
596 595
 			{
597 596
 				$extra_output = ' [ Default: "'.$default.'" ]';
598
-			}
599
-			elseif ($options !== [])
597
+			} elseif ($options !== [])
600 598
 			{
601 599
 				$extra_output = ' [ '.implode(' | ', $options).' ]';
602 600
 			}
@@ -644,8 +642,7 @@  discard block
 block discarded – undo
644 642
  			{
645 643
  				unset(static::$options[$name]);
646 644
  			}
647
- 		}
648
- 		else
645
+ 		} else
649 646
  		{
650 647
  			static::$options[$name] = $value;
651 648
  		}
@@ -674,14 +671,12 @@  discard block
 block discarded – undo
674 671
  			}
675 672
 
676 673
  			static::write();
677
- 		}
678
- 		else
674
+ 		} else
679 675
  		{
680 676
  			if ($seconds = 0)
681 677
  			{
682 678
  				sleep($seconds);
683
- 			}
684
- 			else
679
+ 			} else
685 680
  			{
686 681
  				static::write(static::$waitMsg);
687 682
  				static::input();
Please login to merge, or discard this patch.
Indentation   +758 added lines, -758 removed lines patch added patch discarded remove patch
@@ -34,773 +34,773 @@
 block discarded – undo
34 34
  */
35 35
 class Cli
36 36
 {
37
-	/**
38
- 	 * Background color identifier.
39
- 	 *
40
- 	 * @var array $backgroundColors
41
- 	 */
42
- 	protected static $backgroundColors = [
43
- 		'black'      => '40',
44
- 		'red'        => '41',
45
- 		'green'      => '42',
46
- 		'yellow'     => '43',
47
- 		'blue'       => '44',
48
- 		'magenta'    => '45',
49
- 		'cyan'       => '46',
50
- 		'light_gray' => '47'
51
- 	];
52
-
53
-	/**
54
-	 * Foreground color identifier.
55
- 	 *
56
- 	 * @var array $foregroundColors
57
-	 */
58
-	protected static $foregroundColors = [
59
-		'black'         => '0;30',
60
-		'dark_gray'     => '1;30',
61
-		'blue'          => '0;34',
62
-		'dark_blue'     => '1;34',
63
-		'light_blue'    => '1;34',
64
-		'green'         => '0;32',
65
-		'light_green'   => '1;32',
66
-		'cyan'          => '0;36', 
67
-		'light_cyan'    => '1;36',
68
-		'red'           => '0;31',
69
-		'light_red'     => '1;31',
70
-		'purple'        => '0;35',
71
-		'light_purple'  => '1;35',
72
-		'light_yellow'  => '0;33',
73
-		'yellow'        => '1;33',
74
-		'light_gray'    => '0;37',
75
-		'white'         => '1;37'
76
- 	];
77
-
78
-	/**
79
-	 * Indicates that you do not use any color for foreground or background.
80
-	 *
81
-	 * @var bool $noColor
82
-	 */
83
-	public static $noColor = false;
84
-
85
-	/**
86
-	 * String of arguments to be used in console.
87
-	 *
88
-	 * @var array $options
89
-	 */
90
-	protected static $options = [];
91
-
92
-	/**
93
-	 * Readline Support for command line.
94
-	 *
95
-	 * @var bool $readlineSupport
96
-	 */
97
-	public static $readlineSupport = false;
98
-
99
-	/**
100
-	 * List of array segments.
101
-	 *
102
-	 * @var array $segments
103
-	 */
104
-	protected static $segments = [];
105
-
106
- 	/**
107
- 	 * The standar STDERR is where the application writes its error messages.
108
- 	 *
109
- 	 * @var string $stderr 
110
- 	 */
111
- 	protected static $stderr;
112
-
113
- 	/**
114
- 	 * The estandar STDOUT is where the application records its output messages.
115
- 	 *
116
- 	 * @var string $stdout
117
- 	 */
118
- 	protected static $stdout;
119
-
120
- 	/**
121
-	 * Message that tells the user that he is waiting to receive an order.
122
-	 *
123
-	 * @var string $waitMsg
124
-	 */
125
-	public static $waitMsg = 'Press any key to continue...';
126
-
127
-	/**
128
-	 * Static constructor. Parses all the CLI params.
129
-	 * 
130
-	 * @return string
131
-	 * 
132
-	 * @uses   \Syscodes\Contracts\Core\Lenevor
133
-	 * 
134
-	 * @throws \Exception
135
-	 */
136
- 	public static function initialize(Lenevor $core)
137
- 	{
138
- 		if ( ! $core->initCli())
139
- 		{
140
-			throw new Exception('Cli class cannot be used outside of the command line');
141
- 		}
142
-
143
- 		// Readline is an extension for PHP that makes interactive the command console
144
- 		static::$readlineSupport = extension_loaded('readline');
145
-
146
- 		// clear segments & options to keep testing clean
147
- 		static::$options  = [];
148
- 		static::$segments = [];
149
-
150
- 		static::parseCommandLine();
151
-
152
- 		// Writes its error messages
153
- 		static::$stderr = STDERR;
154
-
155
- 		// Records its output messages
156
- 		static::$stdout = STDOUT;
157
- 	}
158
-
159
- 	/**
160
- 	 * Beeps a certain number of times.
161
-	 *
162
-	 * @param  int  $num  The number of times to beep
163
-	 *
164
- 	 * @return int
165
- 	 */
166
- 	public static function bell(int $num = 1)
167
- 	{
168
- 		echo str_repeat("\x07", $num);
169
- 	}
170
-
171
- 	/**
172
- 	 * Clears the screen of output.
173
- 	 *
174
- 	 * @return void
175
- 	 */
176
- 	public static function clearScreen()
177
- 	{
178
- 		static::isWindows() 
179
-
180
- 			// Windows doesn't work for this, but their terminal is tiny so shove this in
181
- 			? static::newLine(40)
182
-
183
- 			// Anything with a flair of Unix will handle these magic characters
184
- 			: fwrite(static::$stdout, chr(27)."[H".chr(27)."[2J");
185
- 	}
186
-
187
- 	/**
188
- 	 * Returns the given text with the correct color codes for a foreground and
189
-	 * optionally a background color.
190
- 	 *
191
- 	 * @param  string  $text  The text to color
192
- 	 * @param  string  $foreground  The foreground color
193
- 	 * @param  string  $background  The background color
194
- 	 * @param  string  $format  Other formatting to apply. Currently only 'underline' is understood
195
- 	 *
196
- 	 * @return string  The color coded string
197
- 	 *
198
- 	 * @throws \Syscodes\Core\Exceptions\LenevorException
199
- 	 */
200
- 	public static function color(string $text, string $foreground, string $background = null, string $format = null)
201
- 	{
202
- 		if (static::$noColor)
203
- 		{
204
- 			return $text;
205
- 		}
206
-
207
- 		if ( ! Arr::exists(static::$foregroundColors, $foreground))
208
- 		{
209
- 			throw new LenevorException(static::error("Invalid CLI foreground color: {$foreground}."));
210
- 		}
211
-
212
- 		if ( $background !== null && ! Arr::exists(static::$backgroundColors, $background))
213
- 		{
214
- 			throw new LenevorException(static::error("Invalid CLI background color: {$background}."));
215
- 		}
216
-
217
- 		$string = "\033[".static::$foregroundColors[$foreground]."m";
218
-
219
- 		if ($background !== null)
220
- 		{
221
- 			$string .= "\033[".static::$backgroundColors[$background]."m";
222
- 		}
223
-
224
- 		if ($format === 'underline')
225
- 		{
226
- 			$string .= "\033[4m";
227
- 		}
228
-
229
- 		$string .= $text."\033[0m";
230
-
231
- 		return $string;
232
- 	}
233
-
234
- 	/**
235
- 	 * Get the number of characters in a string.
236
- 	 *
237
- 	 * @param  string  $string
238
- 	 *
239
- 	 * @return int
240
- 	 */
241
- 	public static function strlen(?string $string)
242
- 	{
243
- 		if (is_null($string))
244
- 		{
245
- 			return 0;
246
- 		}
247
-
248
- 		foreach (static::$foregroundColors as $color)
249
- 		{
250
- 			$string = strtr($string, ["\033[".$color.'m' => '']);
251
- 		}
252
-
253
- 		foreach (static::$backgroundColors as $color)
254
- 		{
255
- 			$string = strtr($string, ["\033[".$color.'m' => '']);
256
- 		}
257
-
258
- 		$string = strtr($string, ["\033[4m" => '', "\033[0m" => '']);
259
-
260
- 		return mb_strlen($string);
261
- 	}
262
-
263
- 	/**
264
- 	 * Outputs an error to the CLI using STDERR instead of STDOUT.
265
- 	 *
266
- 	 * @param  string|array  $text  The text to output, or array of errors
267
- 	 * @param  string  $foreground  The foreground color
268
- 	 * @param  string|null  $background  the background color
269
- 	 *
270
- 	 * @return string
271
- 	 */
272
- 	public static function error(string $text = '', string $foreground = 'light_red', string $background = null)
273
- 	{
274
-		if (is_array($text))
275
-		{
276
-			$text = implode(PHP_EOL, $text);
277
-		}
37
+    /**
38
+     * Background color identifier.
39
+     *
40
+     * @var array $backgroundColors
41
+     */
42
+        protected static $backgroundColors = [
43
+            'black'      => '40',
44
+            'red'        => '41',
45
+            'green'      => '42',
46
+            'yellow'     => '43',
47
+            'blue'       => '44',
48
+            'magenta'    => '45',
49
+            'cyan'       => '46',
50
+            'light_gray' => '47'
51
+        ];
52
+
53
+    /**
54
+     * Foreground color identifier.
55
+     *
56
+     * @var array $foregroundColors
57
+     */
58
+    protected static $foregroundColors = [
59
+        'black'         => '0;30',
60
+        'dark_gray'     => '1;30',
61
+        'blue'          => '0;34',
62
+        'dark_blue'     => '1;34',
63
+        'light_blue'    => '1;34',
64
+        'green'         => '0;32',
65
+        'light_green'   => '1;32',
66
+        'cyan'          => '0;36', 
67
+        'light_cyan'    => '1;36',
68
+        'red'           => '0;31',
69
+        'light_red'     => '1;31',
70
+        'purple'        => '0;35',
71
+        'light_purple'  => '1;35',
72
+        'light_yellow'  => '0;33',
73
+        'yellow'        => '1;33',
74
+        'light_gray'    => '0;37',
75
+        'white'         => '1;37'
76
+        ];
77
+
78
+    /**
79
+     * Indicates that you do not use any color for foreground or background.
80
+     *
81
+     * @var bool $noColor
82
+     */
83
+    public static $noColor = false;
84
+
85
+    /**
86
+     * String of arguments to be used in console.
87
+     *
88
+     * @var array $options
89
+     */
90
+    protected static $options = [];
91
+
92
+    /**
93
+     * Readline Support for command line.
94
+     *
95
+     * @var bool $readlineSupport
96
+     */
97
+    public static $readlineSupport = false;
98
+
99
+    /**
100
+     * List of array segments.
101
+     *
102
+     * @var array $segments
103
+     */
104
+    protected static $segments = [];
105
+
106
+        /**
107
+         * The standar STDERR is where the application writes its error messages.
108
+         *
109
+         * @var string $stderr 
110
+         */
111
+        protected static $stderr;
112
+
113
+        /**
114
+         * The estandar STDOUT is where the application records its output messages.
115
+         *
116
+         * @var string $stdout
117
+         */
118
+        protected static $stdout;
119
+
120
+        /**
121
+         * Message that tells the user that he is waiting to receive an order.
122
+         *
123
+         * @var string $waitMsg
124
+         */
125
+    public static $waitMsg = 'Press any key to continue...';
126
+
127
+    /**
128
+     * Static constructor. Parses all the CLI params.
129
+     * 
130
+     * @return string
131
+     * 
132
+     * @uses   \Syscodes\Contracts\Core\Lenevor
133
+     * 
134
+     * @throws \Exception
135
+     */
136
+        public static function initialize(Lenevor $core)
137
+        {
138
+            if ( ! $core->initCli())
139
+            {
140
+            throw new Exception('Cli class cannot be used outside of the command line');
141
+            }
142
+
143
+            // Readline is an extension for PHP that makes interactive the command console
144
+            static::$readlineSupport = extension_loaded('readline');
145
+
146
+            // clear segments & options to keep testing clean
147
+            static::$options  = [];
148
+            static::$segments = [];
149
+
150
+            static::parseCommandLine();
151
+
152
+            // Writes its error messages
153
+            static::$stderr = STDERR;
154
+
155
+            // Records its output messages
156
+            static::$stdout = STDOUT;
157
+        }
158
+
159
+        /**
160
+         * Beeps a certain number of times.
161
+         *
162
+         * @param  int  $num  The number of times to beep
163
+         *
164
+         * @return int
165
+         */
166
+        public static function bell(int $num = 1)
167
+        {
168
+            echo str_repeat("\x07", $num);
169
+        }
170
+
171
+        /**
172
+         * Clears the screen of output.
173
+         *
174
+         * @return void
175
+         */
176
+        public static function clearScreen()
177
+        {
178
+            static::isWindows() 
179
+
180
+                // Windows doesn't work for this, but their terminal is tiny so shove this in
181
+             ? static::newLine(40)
182
+
183
+                // Anything with a flair of Unix will handle these magic characters
184
+             : fwrite(static::$stdout, chr(27)."[H".chr(27)."[2J");
185
+        }
186
+
187
+        /**
188
+         * Returns the given text with the correct color codes for a foreground and
189
+         * optionally a background color.
190
+         *
191
+         * @param  string  $text  The text to color
192
+         * @param  string  $foreground  The foreground color
193
+         * @param  string  $background  The background color
194
+         * @param  string  $format  Other formatting to apply. Currently only 'underline' is understood
195
+         *
196
+         * @return string  The color coded string
197
+         *
198
+         * @throws \Syscodes\Core\Exceptions\LenevorException
199
+         */
200
+        public static function color(string $text, string $foreground, string $background = null, string $format = null)
201
+        {
202
+            if (static::$noColor)
203
+            {
204
+                return $text;
205
+            }
206
+
207
+            if ( ! Arr::exists(static::$foregroundColors, $foreground))
208
+            {
209
+                throw new LenevorException(static::error("Invalid CLI foreground color: {$foreground}."));
210
+            }
211
+
212
+            if ( $background !== null && ! Arr::exists(static::$backgroundColors, $background))
213
+            {
214
+                throw new LenevorException(static::error("Invalid CLI background color: {$background}."));
215
+            }
216
+
217
+            $string = "\033[".static::$foregroundColors[$foreground]."m";
218
+
219
+            if ($background !== null)
220
+            {
221
+                $string .= "\033[".static::$backgroundColors[$background]."m";
222
+            }
223
+
224
+            if ($format === 'underline')
225
+            {
226
+                $string .= "\033[4m";
227
+            }
228
+
229
+            $string .= $text."\033[0m";
230
+
231
+            return $string;
232
+        }
233
+
234
+        /**
235
+         * Get the number of characters in a string.
236
+         *
237
+         * @param  string  $string
238
+         *
239
+         * @return int
240
+         */
241
+        public static function strlen(?string $string)
242
+        {
243
+            if (is_null($string))
244
+            {
245
+                return 0;
246
+            }
247
+
248
+            foreach (static::$foregroundColors as $color)
249
+            {
250
+                $string = strtr($string, ["\033[".$color.'m' => '']);
251
+            }
252
+
253
+            foreach (static::$backgroundColors as $color)
254
+            {
255
+                $string = strtr($string, ["\033[".$color.'m' => '']);
256
+            }
257
+
258
+            $string = strtr($string, ["\033[4m" => '', "\033[0m" => '']);
259
+
260
+            return mb_strlen($string);
261
+        }
262
+
263
+        /**
264
+         * Outputs an error to the CLI using STDERR instead of STDOUT.
265
+         *
266
+         * @param  string|array  $text  The text to output, or array of errors
267
+         * @param  string  $foreground  The foreground color
268
+         * @param  string|null  $background  the background color
269
+         *
270
+         * @return string
271
+         */
272
+        public static function error(string $text = '', string $foreground = 'light_red', string $background = null)
273
+        {
274
+        if (is_array($text))
275
+        {
276
+            $text = implode(PHP_EOL, $text);
277
+        }
278 278
 		
279
-		if ($foreground || $background)
280
-		{
281
-			$text = static::color($text, $foreground, $background);
282
-		}
279
+        if ($foreground || $background)
280
+        {
281
+            $text = static::color($text, $foreground, $background);
282
+        }
283 283
 		
284
-		fwrite(static::$stderr, $text.PHP_EOL);
285
-	}
286
-
287
-	/**
288
-	 * Attempts to determine the width of the viewable CLI window.
289
-	 *
290
-	 * @param  int  $default
291
-	 *
292
-	 * @return int
293
-	 */
294
-	public static function getWidth(int $default = 80)
295
-	{
296
-		if (static::isWindows() || (int) shell_exec('tput cols') === 0)
297
-		{
298
-			return $default;
299
-		}
300
-
301
-		return (int) shell_exec('tput cols');
302
-	}
303
-
304
-	/**
305
-	 * Attempts to determine the height of the viewable CLI window.
306
-	 *
307
-	 * @param  int  $default
308
-	 *
309
-	 * @return int
310
-	 */
311
-	public static function getHeight(int $default = 32)
312
-	{
313
-		if (static::isWindows())
314
-		{
315
-			return $default;
316
-		}
317
-
318
-		return (int) shell_exec('tput lines');
319
-	}
320
-
321
-	/**
322
-	 * Takes a string and writes it to the command line, wrapping to a maximum width. 
323
-	 * If no maximum width is specified, will wrap to the window's max.
324
-	 *
325
-	 * @param  string  $string  (null by default)
326
-	 * @param  int  $max  (0 by default)
327
-	 * @param  int $padLeft  (0 by default)
328
-	 *
329
-	 * @return string
330
-	 */
331
-	public static function wrap(string $string = null, int $max = 0, int $padLeft = 0)
332
-	{
333
-		if (empty($string))
334
-		{
335
-			return '';
336
-		}
337
-
338
-		if ($max === 0)
339
-		{
340
-			$max = static::getWidth();
341
-		}
342
-
343
-		if (static::getWidth() < $max)
344
-		{
345
-			$max = static::getWidth();
346
-		}
347
-
348
-		$max = $max - $padLeft;
349
-
350
-		$lines = wordwrap($string, $max);
351
-
352
-		if ($pad_left > 0)
353
-		{
354
-			$lines = explode(PHP_EOL, $lines);
355
-
356
-			$first = true;
357
-
358
-			array_walk ($lines, function (&$line, $index) use ($pad_left, &$first) {
359
-
360
-				if ( ! $first)
361
-				{
362
-					$line = str_repeat(' ', $pad_left) . $line;
363
-				}
364
-				else
365
-				{
366
-					$first = false;
367
-				}
368
-
369
-			});
370
-
371
-			$lines = implode(PHP_EOL, $lines);
372
-		}
373
-
374
-		return $lines;
375
-	}
376
-
377
- 	/**
378
- 	 * Get input from the shell, using readline or the standard STDIN.
379
- 	 *
380
- 	 * @param  string|int  $prefix  The name of the option (int if unnamed)
381
- 	 *
382
- 	 * @return string
383
- 	 */
384
- 	public static function input($prefix = '')
385
- 	{
386
- 		if (static::$readlineSupport)
387
- 		{
388
- 			return readline($prefix);
389
- 		}
390
-
391
- 		echo $prefix;
392
-
393
- 		return fgets(STDIN);
394
- 	}
395
-
396
- 	/**
397
- 	 * If operating system === windows.
398
- 	 * 
399
- 	 * @return string
400
- 	 */
401
- 	public static function isWindows()
402
- 	{
403
- 		return 'win' === strtolower(substr(php_uname("s"), 0, 3));
404
- 	}
405
-
406
- 	/**
407
- 	 * Enter a number of empty lines.
408
- 	 * 
409
- 	 * @param  int  $num  Number of lines to output
410
- 	 *
411
- 	 * @return void
412
- 	 */
413
- 	public static function newLine(int $num = 1)
414
- 	{
415
- 		for ($i = 0; $i < $num; $i++)
416
- 		{			
417
- 			static::write();
418
- 		}
419
- 	}
420
-
421
- 	/**
422
-	 * Returns the option with the given name. You can also give the option number.
423
-	 *
424
-	 * @param  string|int  $name  The name of the option (int if unnamed)
425
-	 * @param  mixed  $default  The value to return if the option is not defined
426
-	 *
427
-	 * @return mixed
428
-	 * 
429
-	 * @uses   \Syscodes\Contract\Core\Lenevor
430
-	 */
431
- 	public static function option($name, $default = null)
432
- 	{
433
- 		if ( ! isset(static::$options[$name]))
434
- 		{
435
- 			return Lenevor::value($default);
436
- 		}
437
-
438
- 		return static::$options[$name];
439
-	}
440
-
441
-	/**
442
-	 * Parses the command line it was called from and collects all
443
-	 * options and valid segments.
444
-	 * 
445
-	 * @return bool
446
-	 */
447
-	protected static function parseCommandLine()
448
-	{
449
-		$options = false;
450
-
451
-		for ($i = 1; $i < $_SERVER['argc']; $i++)
452
-		{
453
-			if ( ! $options && mb_strpos($_SERVER['argv'][$i], '-') === false)
454
-			{
455
-				static::$segments[] = $_SERVER['argv'][$i];
456
-
457
-				continue;
458
-			}
459
-
460
-			$options = true;
461
-
462
-			$args  = str_replace('-', '', $_SERVER['argv'][$i]);
463
-			$value = null;
464
-
465
-			if (isset($_SERVER['argv'][$i + 1]) && mb_strpos($_SERVER['argv'][$i + 1], '-') !== 0)
466
-			{
467
-				$value = $_SERVER['argv'][$i + 1];
468
-				$i++;
469
-			}
470
-
471
-			static::$options[$args] = $value;
472
-
473
-			$options = false;
474
-		}
475
-	}
476
-
477
-	/**
478
-	 * Returns the command line string portions of the arguments, minus
479
-	 * any options, as a string.
480
-	 *
481
-	 * @return string
482
-	 */
483
-	public static function getURI()
484
-	{
485
-		return implode('/', static::$segments);
486
-	}
487
-
488
-	/**
489
-	 * Returns an individual segment.
490
-	 *
491
-	 * @param  int  $index
492
-	 * 
493
-	 * @return mixed|null
494
-	 */
495
-	public static function getSegment(int $index)
496
-	{
497
-		if ( ! isset(static::$segments[$index - 1]))
498
-		{
499
-			return null;
500
-		}
501
-
502
-		return static::$segments[$index - 1];
503
-	}
504
-
505
-	/**
506
-	 * Returns the raw array of segments found.
507
-	 *
508
-	 * @return array
509
-	 */
510
-	public static function getSegments()
511
-	{
512
-		return static::$segments;
513
-	}
514
-
515
- 	/**
516
- 	 * Asks the user for input.  This can have either 1 or 2 arguments.
517
-	 *
518
-	 * Usage:
519
-	 *
520
-	 * // Waits for any key press
521
-	 * Cli::prompt();
522
-	 *
523
-	 * // Takes any input
524
-	 * $color = Cli::prompt('What is your favorite color?');
525
-	 *
526
-	 * // Takes any input, but offers default
527
-	 * $color = Cli::prompt('What is your favourite color?', 'white');
528
-	 *
529
-	 * // Will only accept the options in the array
530
-	 * $ready = Cli::prompt('Are you ready?', array('y','n'));
531
-	 *
532
-	 * @return string The user input
533
-	 */
534
- 	public static function prompt()
535
- 	{
536
- 		$args = func_get_args();
537
-
538
-		$options = [];
539
-		$output  = '';
540
-		$default = null;
541
-
542
-		// How many we got
543
-		$arg_count = count($args);
544
-
545
-		// Is the last argument a boolean? True means required
546
-		$required = end($args) === true;
547
-
548
-		// Reduce the argument count if required was passed, we don't care about that anymore
549
-		$required === true and --$arg_count;
550
-
551
-		// This method can take a few crazy combinations of arguments, so lets work it out
552
-		switch ($arg_count)
553
-		{
554
-			case 2:
555
-
556
-				// E.g: $ready = Cli::prompt('Are you ready?', ['y','n']);
557
-				if (is_array($args[1]))
558
-				{
559
-					list($output, $options) = $args;
560
-				}
561
-
562
-				// E.g: $color = Cli::prompt('What is your favourite color?', 'white');
563
-				elseif (is_string($args[1]))
564
-				{
565
-					list($output, $default) = $args;
566
-				}
567
-
568
-			break;
569
-
570
-			case 1:
571
-
572
-				// No question (probably been asked already) so just show options
573
-				// E.g: $ready = Cli::prompt(array('y','n'));
574
-				if (is_array($args[0]))
575
-				{
576
-					$options = $args[0];
577
-				}
578
-
579
-				// Question without options
580
-				// E.g: $ready = Cli::prompt('What did you do today?');
581
-				elseif (is_string($args[0]))
582
-				{
583
-					$output = $args[0];
584
-				}
585
-
586
-			break;
587
-		}
588
-
589
-		// If a question has been asked with the read
590
-		if ($output !== '')
591
-		{
592
-			$extra_output = '';
593
-
594
-			if ($default !== null)
595
-			{
596
-				$extra_output = ' [ Default: "'.$default.'" ]';
597
-			}
598
-			elseif ($options !== [])
599
-			{
600
-				$extra_output = ' [ '.implode(' | ', $options).' ]';
601
-			}
602
-
603
-			fwrite(static::$stdout, $output.$extra_output.': ');
604
-		}
605
-
606
-		// Read the input from keyboard.
607
-		$input = trim(static::input()) ?: $default;
608
-
609
-		// No input provided and we require one (default will stop this being called)
610
-		if (empty($input) and $required === true)
611
-		{
612
-			static::write('This is required.');
613
-			static::newLine();
614
-
615
-			$input = forward_static_call_array([__CLASS__, 'prompt'], $args);
616
-		}
617
-
618
-		// If options are provided and the choice is not in the array, tell them to try again
619
-		if ( ! empty($options) and ! in_array($input, $options))
620
-		{
621
-			static::write('This is not a valid option. Please try again.');
622
-			static::newLine();
623
-
624
-			$input = forward_static_call_array([__CLASS__, 'prompt'], $args);
625
-		}
626
-
627
-		return $input;
628
- 	}
629
-
630
- 	/**
631
- 	 * Allows you to set a commandline option from code.
632
- 	 *
633
- 	 * @param  string|int  $name  The name of the option (int if unnamed)
634
-	 * @param  mixed|null  $value  The value to set, or null to delete the option
635
-	 *
636
-	 * @return mixed
637
-	 */
638
- 	public static function setOption($name, $value = null)
639
- 	{
640
- 		if ($value == null)
641
- 		{
642
- 			if (isset(static::$options[$name]))
643
- 			{
644
- 				unset(static::$options[$name]);
645
- 			}
646
- 		}
647
- 		else
648
- 		{
649
- 			static::$options[$name] = $value;
650
- 		}
651
- 	}
652
-
653
- 	/**
654
- 	 * Waits a certain number of seconds, optionally showing a wait message and
655
-	 * waiting for a key press.
656
- 	 *
657
- 	 * @param  int  $seconds  Number of seconds
658
- 	 * @param  bool  $countdown  Show a countdown or not
659
- 	 *
660
- 	 * @return string
661
- 	 */
662
- 	public static function wait(int $seconds = 0, bool $countdown = false)
663
- 	{
664
- 		if ($countdown === true)
665
- 		{
666
-			$time = $seconds;
667
-
668
- 			while ($time > 0)
669
- 			{
670
- 				fwrite(static::$stdout, $time.'... ');
671
- 				sleep(1);
672
- 				$time--;
673
- 			}
674
-
675
- 			static::write();
676
- 		}
677
- 		else
678
- 		{
679
- 			if ($seconds = 0)
680
- 			{
681
- 				sleep($seconds);
682
- 			}
683
- 			else
684
- 			{
685
- 				static::write(static::$waitMsg);
686
- 				static::input();
687
- 			}
688
- 		}
689
- 	}
690
-
691
- 	/**
692
- 	 * Outputs a string to the cli.	If you send an array it will implode them 
693
- 	 * with a line break.
694
- 	 * 
695
- 	 * @param  string|array  $text  The text to output, or array of lines
696
- 	 * @param  string|null  $foreground  The foreground color
697
- 	 * @param  string|null  $background  The background color
698
- 	 *
699
- 	 * @return string
700
- 	 */
701
- 	public static function write(string $text = '', string $foreground = null, string $background = null)
702
- 	{
703
- 		if (is_array($text))
704
- 		{
705
- 			$text = implode(PHP_EOL, $text);
706
- 		}
707
-
708
- 		if ($foreground OR $background)
709
- 		{
710
- 			$text = static::color($text, $foreground, $background);
711
- 		}
712
-
713
- 		fwrite(static::$stdout, $text.PHP_EOL);
714
- 	}
715
-
716
- 	/**
717
- 	 * Returns a well formatted table.
718
- 	 *
719
- 	 * @param  array  $tbody  List of rows
720
- 	 * @param  array  $thead  List of columns
721
- 	 *
722
- 	 * @return void
723
- 	 */
724
- 	public static function table(array $tbody, array $thead = [])
725
- 	{
726
- 		$rows = [];
727
-
728
- 		if ( ! empty($thead))
729
- 		{
730
- 			$rows[] = array_values($thead);
731
- 		}
732
-
733
- 		foreach ($tbody as $tr)
734
- 		{
735
- 			$rows[] = count($rows);
736
- 		}
737
-
738
- 		$totalRows = count($rows);
739
-
740
- 		// Store all columns lengths
741
- 		$allColsLengths = [];
742
-
743
- 		// Store maximum lengths by column
744
- 		$maxColsLengths = [];
745
-
746
- 		for ($row = 0; $row < $totalRows; $row++)
747
- 		{
748
- 			$column = 0;
749
-
750
- 			foreach ($rows[$row] as $col)
751
- 			{
752
- 				$allColsLengths[$row][$column] = static::strlen($col);
753
-
754
- 				if ( ! isset($maxColsLengths[$column]) || $allColsLengths[$row][$column] > $maxColsLengths[$column])
755
- 				{
756
- 					$maxColsLengths[$column] = $allColsLengths[$row][$column];
757
- 				}
758
-
759
- 				$column++;
760
- 			}
761
- 		}
762
-
763
- 		for ($row = 0; $row < $totalRows; $row++)
764
- 		{
765
- 			$column = 0;
766
-
767
- 			foreach ($rows[$row] as $col)
768
- 			{
769
- 				$diverse = $maxColsLengths[$column] - static::strlen($col);
284
+        fwrite(static::$stderr, $text.PHP_EOL);
285
+    }
286
+
287
+    /**
288
+     * Attempts to determine the width of the viewable CLI window.
289
+     *
290
+     * @param  int  $default
291
+     *
292
+     * @return int
293
+     */
294
+    public static function getWidth(int $default = 80)
295
+    {
296
+        if (static::isWindows() || (int) shell_exec('tput cols') === 0)
297
+        {
298
+            return $default;
299
+        }
300
+
301
+        return (int) shell_exec('tput cols');
302
+    }
303
+
304
+    /**
305
+     * Attempts to determine the height of the viewable CLI window.
306
+     *
307
+     * @param  int  $default
308
+     *
309
+     * @return int
310
+     */
311
+    public static function getHeight(int $default = 32)
312
+    {
313
+        if (static::isWindows())
314
+        {
315
+            return $default;
316
+        }
317
+
318
+        return (int) shell_exec('tput lines');
319
+    }
320
+
321
+    /**
322
+     * Takes a string and writes it to the command line, wrapping to a maximum width. 
323
+     * If no maximum width is specified, will wrap to the window's max.
324
+     *
325
+     * @param  string  $string  (null by default)
326
+     * @param  int  $max  (0 by default)
327
+     * @param  int $padLeft  (0 by default)
328
+     *
329
+     * @return string
330
+     */
331
+    public static function wrap(string $string = null, int $max = 0, int $padLeft = 0)
332
+    {
333
+        if (empty($string))
334
+        {
335
+            return '';
336
+        }
337
+
338
+        if ($max === 0)
339
+        {
340
+            $max = static::getWidth();
341
+        }
342
+
343
+        if (static::getWidth() < $max)
344
+        {
345
+            $max = static::getWidth();
346
+        }
347
+
348
+        $max = $max - $padLeft;
349
+
350
+        $lines = wordwrap($string, $max);
351
+
352
+        if ($pad_left > 0)
353
+        {
354
+            $lines = explode(PHP_EOL, $lines);
355
+
356
+            $first = true;
357
+
358
+            array_walk ($lines, function (&$line, $index) use ($pad_left, &$first) {
359
+
360
+                if ( ! $first)
361
+                {
362
+                    $line = str_repeat(' ', $pad_left) . $line;
363
+                }
364
+                else
365
+                {
366
+                    $first = false;
367
+                }
368
+
369
+            });
370
+
371
+            $lines = implode(PHP_EOL, $lines);
372
+        }
373
+
374
+        return $lines;
375
+    }
376
+
377
+        /**
378
+         * Get input from the shell, using readline or the standard STDIN.
379
+         *
380
+         * @param  string|int  $prefix  The name of the option (int if unnamed)
381
+         *
382
+         * @return string
383
+         */
384
+        public static function input($prefix = '')
385
+        {
386
+            if (static::$readlineSupport)
387
+            {
388
+                return readline($prefix);
389
+            }
390
+
391
+            echo $prefix;
392
+
393
+            return fgets(STDIN);
394
+        }
395
+
396
+        /**
397
+         * If operating system === windows.
398
+         * 
399
+         * @return string
400
+         */
401
+        public static function isWindows()
402
+        {
403
+            return 'win' === strtolower(substr(php_uname("s"), 0, 3));
404
+        }
405
+
406
+        /**
407
+         * Enter a number of empty lines.
408
+         * 
409
+         * @param  int  $num  Number of lines to output
410
+         *
411
+         * @return void
412
+         */
413
+        public static function newLine(int $num = 1)
414
+        {
415
+            for ($i = 0; $i < $num; $i++)
416
+            {			
417
+                static::write();
418
+            }
419
+        }
420
+
421
+        /**
422
+         * Returns the option with the given name. You can also give the option number.
423
+         *
424
+         * @param  string|int  $name  The name of the option (int if unnamed)
425
+         * @param  mixed  $default  The value to return if the option is not defined
426
+         *
427
+         * @return mixed
428
+         * 
429
+         * @uses   \Syscodes\Contract\Core\Lenevor
430
+         */
431
+        public static function option($name, $default = null)
432
+        {
433
+            if ( ! isset(static::$options[$name]))
434
+            {
435
+                return Lenevor::value($default);
436
+            }
437
+
438
+            return static::$options[$name];
439
+    }
440
+
441
+    /**
442
+     * Parses the command line it was called from and collects all
443
+     * options and valid segments.
444
+     * 
445
+     * @return bool
446
+     */
447
+    protected static function parseCommandLine()
448
+    {
449
+        $options = false;
450
+
451
+        for ($i = 1; $i < $_SERVER['argc']; $i++)
452
+        {
453
+            if ( ! $options && mb_strpos($_SERVER['argv'][$i], '-') === false)
454
+            {
455
+                static::$segments[] = $_SERVER['argv'][$i];
456
+
457
+                continue;
458
+            }
459
+
460
+            $options = true;
461
+
462
+            $args  = str_replace('-', '', $_SERVER['argv'][$i]);
463
+            $value = null;
464
+
465
+            if (isset($_SERVER['argv'][$i + 1]) && mb_strpos($_SERVER['argv'][$i + 1], '-') !== 0)
466
+            {
467
+                $value = $_SERVER['argv'][$i + 1];
468
+                $i++;
469
+            }
470
+
471
+            static::$options[$args] = $value;
472
+
473
+            $options = false;
474
+        }
475
+    }
476
+
477
+    /**
478
+     * Returns the command line string portions of the arguments, minus
479
+     * any options, as a string.
480
+     *
481
+     * @return string
482
+     */
483
+    public static function getURI()
484
+    {
485
+        return implode('/', static::$segments);
486
+    }
487
+
488
+    /**
489
+     * Returns an individual segment.
490
+     *
491
+     * @param  int  $index
492
+     * 
493
+     * @return mixed|null
494
+     */
495
+    public static function getSegment(int $index)
496
+    {
497
+        if ( ! isset(static::$segments[$index - 1]))
498
+        {
499
+            return null;
500
+        }
501
+
502
+        return static::$segments[$index - 1];
503
+    }
504
+
505
+    /**
506
+     * Returns the raw array of segments found.
507
+     *
508
+     * @return array
509
+     */
510
+    public static function getSegments()
511
+    {
512
+        return static::$segments;
513
+    }
514
+
515
+        /**
516
+         * Asks the user for input.  This can have either 1 or 2 arguments.
517
+         *
518
+         * Usage:
519
+         *
520
+         * // Waits for any key press
521
+         * Cli::prompt();
522
+         *
523
+         * // Takes any input
524
+         * $color = Cli::prompt('What is your favorite color?');
525
+         *
526
+         * // Takes any input, but offers default
527
+         * $color = Cli::prompt('What is your favourite color?', 'white');
528
+         *
529
+         * // Will only accept the options in the array
530
+         * $ready = Cli::prompt('Are you ready?', array('y','n'));
531
+         *
532
+         * @return string The user input
533
+         */
534
+        public static function prompt()
535
+        {
536
+            $args = func_get_args();
537
+
538
+        $options = [];
539
+        $output  = '';
540
+        $default = null;
541
+
542
+        // How many we got
543
+        $arg_count = count($args);
544
+
545
+        // Is the last argument a boolean? True means required
546
+        $required = end($args) === true;
547
+
548
+        // Reduce the argument count if required was passed, we don't care about that anymore
549
+        $required === true and --$arg_count;
550
+
551
+        // This method can take a few crazy combinations of arguments, so lets work it out
552
+        switch ($arg_count)
553
+        {
554
+            case 2:
555
+
556
+                // E.g: $ready = Cli::prompt('Are you ready?', ['y','n']);
557
+                if (is_array($args[1]))
558
+                {
559
+                    list($output, $options) = $args;
560
+                }
561
+
562
+                // E.g: $color = Cli::prompt('What is your favourite color?', 'white');
563
+                elseif (is_string($args[1]))
564
+                {
565
+                    list($output, $default) = $args;
566
+                }
567
+
568
+            break;
569
+
570
+            case 1:
571
+
572
+                // No question (probably been asked already) so just show options
573
+                // E.g: $ready = Cli::prompt(array('y','n'));
574
+                if (is_array($args[0]))
575
+                {
576
+                    $options = $args[0];
577
+                }
578
+
579
+                // Question without options
580
+                // E.g: $ready = Cli::prompt('What did you do today?');
581
+                elseif (is_string($args[0]))
582
+                {
583
+                    $output = $args[0];
584
+                }
585
+
586
+            break;
587
+        }
588
+
589
+        // If a question has been asked with the read
590
+        if ($output !== '')
591
+        {
592
+            $extra_output = '';
593
+
594
+            if ($default !== null)
595
+            {
596
+                $extra_output = ' [ Default: "'.$default.'" ]';
597
+            }
598
+            elseif ($options !== [])
599
+            {
600
+                $extra_output = ' [ '.implode(' | ', $options).' ]';
601
+            }
602
+
603
+            fwrite(static::$stdout, $output.$extra_output.': ');
604
+        }
605
+
606
+        // Read the input from keyboard.
607
+        $input = trim(static::input()) ?: $default;
608
+
609
+        // No input provided and we require one (default will stop this being called)
610
+        if (empty($input) and $required === true)
611
+        {
612
+            static::write('This is required.');
613
+            static::newLine();
614
+
615
+            $input = forward_static_call_array([__CLASS__, 'prompt'], $args);
616
+        }
617
+
618
+        // If options are provided and the choice is not in the array, tell them to try again
619
+        if ( ! empty($options) and ! in_array($input, $options))
620
+        {
621
+            static::write('This is not a valid option. Please try again.');
622
+            static::newLine();
623
+
624
+            $input = forward_static_call_array([__CLASS__, 'prompt'], $args);
625
+        }
626
+
627
+        return $input;
628
+        }
629
+
630
+        /**
631
+         * Allows you to set a commandline option from code.
632
+         *
633
+         * @param  string|int  $name  The name of the option (int if unnamed)
634
+         * @param  mixed|null  $value  The value to set, or null to delete the option
635
+         *
636
+         * @return mixed
637
+         */
638
+        public static function setOption($name, $value = null)
639
+        {
640
+            if ($value == null)
641
+            {
642
+                if (isset(static::$options[$name]))
643
+                {
644
+                    unset(static::$options[$name]);
645
+                }
646
+            }
647
+            else
648
+            {
649
+                static::$options[$name] = $value;
650
+            }
651
+        }
652
+
653
+        /**
654
+         * Waits a certain number of seconds, optionally showing a wait message and
655
+         * waiting for a key press.
656
+         *
657
+         * @param  int  $seconds  Number of seconds
658
+         * @param  bool  $countdown  Show a countdown or not
659
+         *
660
+         * @return string
661
+         */
662
+        public static function wait(int $seconds = 0, bool $countdown = false)
663
+        {
664
+            if ($countdown === true)
665
+            {
666
+            $time = $seconds;
667
+
668
+                while ($time > 0)
669
+                {
670
+                    fwrite(static::$stdout, $time.'... ');
671
+                    sleep(1);
672
+                    $time--;
673
+                }
674
+
675
+                static::write();
676
+            }
677
+            else
678
+            {
679
+                if ($seconds = 0)
680
+                {
681
+                    sleep($seconds);
682
+                }
683
+                else
684
+                {
685
+                    static::write(static::$waitMsg);
686
+                    static::input();
687
+                }
688
+            }
689
+        }
690
+
691
+        /**
692
+         * Outputs a string to the cli.	If you send an array it will implode them 
693
+         * with a line break.
694
+         * 
695
+         * @param  string|array  $text  The text to output, or array of lines
696
+         * @param  string|null  $foreground  The foreground color
697
+         * @param  string|null  $background  The background color
698
+         *
699
+         * @return string
700
+         */
701
+        public static function write(string $text = '', string $foreground = null, string $background = null)
702
+        {
703
+            if (is_array($text))
704
+            {
705
+                $text = implode(PHP_EOL, $text);
706
+            }
707
+
708
+            if ($foreground OR $background)
709
+            {
710
+                $text = static::color($text, $foreground, $background);
711
+            }
712
+
713
+            fwrite(static::$stdout, $text.PHP_EOL);
714
+        }
715
+
716
+        /**
717
+         * Returns a well formatted table.
718
+         *
719
+         * @param  array  $tbody  List of rows
720
+         * @param  array  $thead  List of columns
721
+         *
722
+         * @return void
723
+         */
724
+        public static function table(array $tbody, array $thead = [])
725
+        {
726
+            $rows = [];
727
+
728
+            if ( ! empty($thead))
729
+            {
730
+                $rows[] = array_values($thead);
731
+            }
732
+
733
+            foreach ($tbody as $tr)
734
+            {
735
+                $rows[] = count($rows);
736
+            }
737
+
738
+            $totalRows = count($rows);
739
+
740
+            // Store all columns lengths
741
+            $allColsLengths = [];
742
+
743
+            // Store maximum lengths by column
744
+            $maxColsLengths = [];
745
+
746
+            for ($row = 0; $row < $totalRows; $row++)
747
+            {
748
+                $column = 0;
749
+
750
+                foreach ($rows[$row] as $col)
751
+                {
752
+                    $allColsLengths[$row][$column] = static::strlen($col);
753
+
754
+                    if ( ! isset($maxColsLengths[$column]) || $allColsLengths[$row][$column] > $maxColsLengths[$column])
755
+                    {
756
+                        $maxColsLengths[$column] = $allColsLengths[$row][$column];
757
+                    }
758
+
759
+                    $column++;
760
+                }
761
+            }
762
+
763
+            for ($row = 0; $row < $totalRows; $row++)
764
+            {
765
+                $column = 0;
766
+
767
+                foreach ($rows[$row] as $col)
768
+                {
769
+                    $diverse = $maxColsLengths[$column] - static::strlen($col);
770 770
  				
771
- 				if ($diverse)	
772
- 				{
773
- 					$rows[$row][$column] = $rows[$row][$column].str_repeat(' ', $diverse);
774
- 				}
771
+                    if ($diverse)	
772
+                    {
773
+                        $rows[$row][$column] = $rows[$row][$column].str_repeat(' ', $diverse);
774
+                    }
775 775
 
776
- 				$column++;
777
- 			} 			
778
- 		}
776
+                    $column++;
777
+                } 			
778
+            }
779 779
 
780
- 		$table = '';
780
+            $table = '';
781 781
 
782
- 		for ($row = 0; $row < $rows; $row++)
783
- 		{
784
- 			if (0 === $row)
785
- 			{
786
- 				$cols = '+';
782
+            for ($row = 0; $row < $rows; $row++)
783
+            {
784
+                if (0 === $row)
785
+                {
786
+                    $cols = '+';
787 787
 
788
- 				foreach ($rows[$row] as $col) 
789
- 				{
790
- 					$cols .= str_repeat('-', static::strlen($col) + 2).'+';
791
- 				}
788
+                    foreach ($rows[$row] as $col) 
789
+                    {
790
+                        $cols .= str_repeat('-', static::strlen($col) + 2).'+';
791
+                    }
792 792
 
793
- 				$table .= $cols.PHP_EOL;
794
- 			}
793
+                    $table .= $cols.PHP_EOL;
794
+                }
795 795
 
796
- 			$table .= '| '.implode('-', $rows[$row]).' |'.PHP_EOL;
796
+                $table .= '| '.implode('-', $rows[$row]).' |'.PHP_EOL;
797 797
 
798
- 			if (0 === $row && ! empty($thead) || $row + 1 === $rows)
799
- 			{
800
- 				$table .= $cols.PHP_EOL;
801
- 			}
802
- 		}
798
+                if (0 === $row && ! empty($thead) || $row + 1 === $rows)
799
+                {
800
+                    $table .= $cols.PHP_EOL;
801
+                }
802
+            }
803 803
 
804
- 		fwrite(static::$stdout, $table);
805
- 	}
804
+            fwrite(static::$stdout, $table);
805
+        }
806 806
 }
807 807
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Console/Application.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -35,59 +35,59 @@
 block discarded – undo
35 35
  */
36 36
 class Application implements ApplicationContracts
37 37
 {
38
-	/**
39
-	 * Get the Lenevor class instance.
40
-	 * 
41
-	 * @var \Syscodes\Contracts\Core\Lenevor $core
42
-	 */
43
-	protected $core;
38
+    /**
39
+     * Get the Lenevor class instance.
40
+     * 
41
+     * @var \Syscodes\Contracts\Core\Lenevor $core
42
+     */
43
+    protected $core;
44 44
 
45
-	/**
46
-	 * Console constructor. Initialize the console of Lenevor.
47
-	 *
48
-	 * @param  \Syscodes\Contracts\Core\Lenevor  $core
49
-	 * 
50
-	 * @return void
51
-	 */
52
-	public function __construct(Lenevor $core)
53
-	{		
54
-		// Initialize the Cli
55
-		if ($core->initCli())
56
-		{
57
-			Cli::initialize($core);
58
-		}
45
+    /**
46
+     * Console constructor. Initialize the console of Lenevor.
47
+     *
48
+     * @param  \Syscodes\Contracts\Core\Lenevor  $core
49
+     * 
50
+     * @return void
51
+     */
52
+    public function __construct(Lenevor $core)
53
+    {		
54
+        // Initialize the Cli
55
+        if ($core->initCli())
56
+        {
57
+            Cli::initialize($core);
58
+        }
59 59
 
60
-		$this->core = $core;
61
-	}
60
+        $this->core = $core;
61
+    }
62 62
 
63
-	/**
64
-	 * Runs the current command discovered on the CLI.
65
-	 *
66
-	 * @return void
67
-	 */
68
-	public function run()
69
-	{
70
-		Cli::getURI();
63
+    /**
64
+     * Runs the current command discovered on the CLI.
65
+     *
66
+     * @return void
67
+     */
68
+    public function run()
69
+    {
70
+        Cli::getURI();
71 71
 
72 72
 		
73
-	}
73
+    }
74 74
 
75
-	/**
76
-	 * Displays basic information about the Console.
77
-	 *
78
-	 * @return void
79
-	 *
80
-	 * @uses   Version::PRODUCT
81
-	 * @uses   Version::RELEASE 
82
-	 */
83
-	public function showHeader()
84
-	{		
85
-		Cli::write(Version::PRODUCT.' '
86
-			.Cli::color(Version::RELEASE, 'cyan').' | '
87
-			.'Server Time: '.Cli::color(date('Y/m/d H:i:sa'), 'light_yellow').' | '
88
-			.cli::color('['.PHP_OS.']', 'light_purple')
89
-		);
75
+    /**
76
+     * Displays basic information about the Console.
77
+     *
78
+     * @return void
79
+     *
80
+     * @uses   Version::PRODUCT
81
+     * @uses   Version::RELEASE 
82
+     */
83
+    public function showHeader()
84
+    {		
85
+        Cli::write(Version::PRODUCT.' '
86
+            .Cli::color(Version::RELEASE, 'cyan').' | '
87
+            .'Server Time: '.Cli::color(date('Y/m/d H:i:sa'), 'light_yellow').' | '
88
+            .cli::color('['.PHP_OS.']', 'light_purple')
89
+        );
90 90
 
91
-		Cli::newLine(1);
92
-	}
91
+        Cli::newLine(1);
92
+    }
93 93
 }
94 94
\ No newline at end of file
Please login to merge, or discard this patch.