Skip to content

Commit 6829f54

Browse files
committed
PSR-12 changes, doc blocks, refactorings here and there
1 parent b521cc8 commit 6829f54

35 files changed

+551
-248
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ $array = array_except_value($array, ['bar', 'baz']);
109109

110110
#### `multiarray_set()`
111111

112-
Set a value for each item of the multidimensional array using "dot" notation:
112+
Set value for each item of the multidimensional array using "dot" notation:
113113

114114
```php
115115
$array = [
@@ -129,7 +129,7 @@ multiarray_set($array, 'details.country', 'Germany');
129129
130130
#### `multiarray_sort_by()`
131131
132-
Sort the multidimensional array by few fields:
132+
Sort the multidimensional array by several fields:
133133
134134
```php
135135
$array = [
@@ -171,15 +171,15 @@ $sorted = multiarray_sort_by($array, 'name', SORT_ASC, 'model', SORT_DESC);
171171
172172
#### `call_in_background()`
173173
174-
Call artisan console command in the background. Code execution continues immediately, without waiting for results.
174+
Call the given artisan console command in background. Code execution continues immediately, without waiting for results.
175175
176176
```php
177177
call_in_background('report');
178178
179179
// "php artisan report" would be called in background
180180
```
181181
182-
Optional `before` and `after` sub-commands can be set as a second and third parameter:
182+
Optional `before` and `after` sub-commands could be provided:
183183
184184
```php
185185
call_in_background('report:monthly subscriptions', 'sleep 0.3');
@@ -191,7 +191,7 @@ call_in_background('report:monthly subscriptions', 'sleep 0.3');
191191
192192
#### `db_is_sqlite()`
193193
194-
Check if the default database connection driver is `sqlite` or not:
194+
Check whether the default database connection driver is `sqlite` or not:
195195
196196
```php
197197
if (db_is_sqlite()) {
@@ -201,7 +201,7 @@ if (db_is_sqlite()) {
201201
202202
#### `db_is_mysql()`
203203
204-
Check if the default database connection driver is `mysql` or not:
204+
Check whether the default database connection driver is `mysql` or not:
205205
206206
```php
207207
if (db_is_mysql()) {
@@ -211,7 +211,7 @@ if (db_is_mysql()) {
211211
212212
#### `db_mysql_now()`
213213
214-
Get database datetime, using `mysql` connection:
214+
Get the current MySQL datetime:
215215
216216
```php
217217
$now = db_mysql_now();
@@ -221,7 +221,7 @@ $now = db_mysql_now();
221221
222222
#### `db_mysql_variable()`
223223
224-
Get the value of specified `mysql` variable, or `false` if the variable doesn't exist:
224+
Get value of the specified MySQL variable:
225225
226226
```php
227227
$hostname = db_mysql_variable('hostname');
@@ -233,7 +233,7 @@ $hostname = db_mysql_variable('hostname');
233233
234234
#### `to_default_timezone()`
235235
236-
Convert passed datetime string to the default timezone, which is `app.timezone` config setting:
236+
Convert datetime to the default timezone (`app.timezone` config parameter):
237237
238238
```php
239239
$date = to_default_timezone('2017-02-28T14:05:01Z');
@@ -257,7 +257,7 @@ $backtrace = backtrace_as_string();
257257
258258
#### `minimized_backtrace_as_string()`
259259
260-
Get minimized backtrace as a string:
260+
Get minimized backtrace, as a string:
261261
262262
```php
263263
$backtrace = minimized_backtrace_as_string();
@@ -271,7 +271,7 @@ $backtrace = minimized_backtrace_as_string();
271271
272272
#### `is_email()`
273273
274-
Check if the specified string is a valid email address or not:
274+
Check whether the given string is an email address or not:
275275
276276
```php
277277
$isEmail = is_email('[email protected]');
@@ -281,7 +281,7 @@ $isEmail = is_email('[email protected]');
281281
282282
#### `to_rfc2822_email()`
283283
284-
Convert addresses data to [RFC 2822](http://www.faqs.org/rfcs/rfc2822.html) string, suitable for PHP [mail()](http://ua2.php.net/manual/en/function.mail.php) function:
284+
Convert addresses data to [RFC 2822](http://faqs.org/rfcs/rfc2822.html) string, suitable for PHP [mail()](https://php.net/manual/en/function.mail.php) function:
285285
286286
```php
287287
$address = to_rfc2822_email([
@@ -292,7 +292,7 @@ $address = to_rfc2822_email([
292292
293293
```
294294
295-
Also supports simplified syntax for single address item:
295+
Also supports simplified syntax for single address:
296296
297297
```php
298298
$address = to_rfc2822_email(['address' => '[email protected]', 'name' => 'John Doe']);
@@ -302,7 +302,7 @@ $address = to_rfc2822_email(['address' => '[email protected]', 'name' => 'Joh
302302
303303
#### `to_swiftmailer_emails()`
304304
305-
Convert addresses data to format, which is suitable for [SwiftMailer library](http://swiftmailer.org/docs/messages.html):
305+
Convert addresses data to [SwiftMailer-suitable format](https://swiftmailer.org/docs/messages.html):
306306
307307
```php
308308
$addresses = to_swiftmailer_emails([
@@ -313,7 +313,7 @@ $addresses = to_swiftmailer_emails([
313313
// ["[email protected]" => "John Doe", "[email protected]"]
314314
```
315315
316-
Also supports simplified syntax for single address item:
316+
Also supports simplified syntax for single address:
317317
318318
```php
319319
$address = to_swiftmailer_emails(['address' => '[email protected]', 'name' => 'John Doe']);
@@ -325,7 +325,7 @@ $address = to_swiftmailer_emails(['address' => '[email protected]', 'name' =>
325325
326326
#### `relative_path()`
327327
328-
Get the relative path for two directories:
328+
Get relative path for the given folders:
329329
330330
```php
331331
$path = relative_path('/var/www/htdocs', '/var/www/htdocs/example')
@@ -345,7 +345,7 @@ $path = relative_path('/var/www/htdocs/example/public/../../', '/var/')
345345
346346
#### `get_dump()`
347347
348-
Get nicely formatted string representation of the variable, using [Symfony VarDumper Component](http://symfony.com/doc/current/components/var_dumper/introduction.html):
348+
Get nicely formatted string representation of the variable, using [Symfony VarDumper Component](https://symfony.com/doc/current/components/var_dumper/introduction.html):
349349
350350
```php
351351
$array = [
@@ -368,7 +368,7 @@ $dump = get_dump($array);
368368
369369
#### `format_bytes()`
370370
371-
Format bytes into kilobytes, megabytes, gigabytes or terabytes, with specified precision:
371+
Format bytes into kilobytes, megabytes, gigabytes or terabytes:
372372
373373
```php
374374
$formatted = format_bytes(3333333);
@@ -407,15 +407,15 @@ $formatted = format_xml('<?xml version="1.0"?><root><task priority="low"><to>Joh
407407
408408
#### `is_json()`
409409
410-
Check if specified variable is a valid JSON-encoded string or not:
410+
Check whether the given value is a valid JSON-encoded string or not:
411411
412412
```php
413413
$isJson = is_json('{"foo":1,"bar":2,"baz":3}');
414414
415415
// true
416416
```
417417
418-
It can return decoded JSON if you pass the second argument as `true`:
418+
It returns decoded JSON if you pass `true` as a second argument:
419419
420420
```php
421421
$decoded = is_json('{"foo":1,"bar":2,"baz":3}', true);
@@ -427,7 +427,7 @@ $decoded = is_json('{"foo":1,"bar":2,"baz":3}', true);
427427
428428
#### `str_lower()`
429429
430-
Convert string to lowercase, using `mb_strtolower` in `UTF-8` encoding:
430+
Convert string to lowercase, assuming it's using the `UTF-8` encoding:
431431
432432
```php
433433
$lower = str_lower('TeSt');
@@ -437,7 +437,7 @@ $lower = str_lower('TeSt');
437437
438438
#### `str_upper()`
439439
440-
Convert string to uppercase, using `mb_strtoupper` in `UTF-8` encoding:
440+
Convert string to uppercase, assuming it's using the `UTF-8` encoding:
441441
442442
```php
443443
$upper = str_upper('TeSt');
@@ -449,7 +449,7 @@ $upper = str_upper('TeSt');
449449
450450
#### `is_windows_os()`
451451
452-
Check if PHP is running on Windows OS or not:
452+
Check whether the operating system is Windows or not:
453453
454454
```php
455455
$isWindowsOs = is_windows_os();
@@ -461,7 +461,7 @@ $isWindowsOs = is_windows_os();
461461
462462
#### `xml_to_array()`
463463
464-
Convert XML string to the array:
464+
Convert XML string to array:
465465
466466
```php
467467
$array = xml_to_array('<?xml version="1.0"?>
@@ -495,11 +495,11 @@ $array = xml_to_array('<?xml version="1.0"?>
495495
// ]
496496
```
497497
498-
Alternatively, you can pass an instance of a `SimpleXMLElement` object, to get the same results.
498+
Alternatively, you can pass an instance of `SimpleXMLElement` as a first argument.
499499
500500
#### `array_to_xml()`
501501
502-
Convert array to XML string using [spatie/array-to-xml](https://github.com/spatie/array-to-xml) package:
502+
Convert array to XML string:
503503
504504
```php
505505
$array = [
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
namespace Illuminated\Helpers\Artisan;
4+
5+
use Illuminate\Support\Collection;
6+
use Symfony\Component\Process\PhpExecutableFinder;
7+
8+
class BackgroundCommand
9+
{
10+
/**
11+
* The artisan command.
12+
*
13+
* @var string
14+
*/
15+
private $command;
16+
17+
/**
18+
* The command which should be executed before.
19+
*
20+
* @var string
21+
*/
22+
private $before;
23+
24+
/**
25+
* The command which should be executed after.
26+
*
27+
* @var string
28+
*/
29+
private $after;
30+
31+
/**
32+
* Create background command by the given parameters.
33+
*
34+
* @param string $command
35+
* @param string $before
36+
* @param string $after
37+
* @return \Illuminated\Helpers\Artisan\BackgroundCommand
38+
*/
39+
public static function factory(string $command, string $before = '', string $after = '')
40+
{
41+
return new self($command, $before, $after);
42+
}
43+
44+
/**
45+
* Create a new instance of the background command.
46+
*
47+
* @param string $command
48+
* @param string $before
49+
* @param string $after
50+
* @return void
51+
*/
52+
public function __construct(string $command, string $before = '', string $after = '')
53+
{
54+
$this->command = $command;
55+
$this->before = $before;
56+
$this->after = $after;
57+
}
58+
59+
/**
60+
* Run the command in background.
61+
*
62+
* @return void
63+
*/
64+
public function run()
65+
{
66+
$command = $this->composeCommand();
67+
68+
$command = is_windows_os()
69+
? "start /B {$command}"
70+
: "({$command}) > /dev/null 2>&1 &";
71+
72+
exec($command);
73+
}
74+
75+
/**
76+
* Compose the command.
77+
*
78+
* @return string
79+
*/
80+
protected function composeCommand()
81+
{
82+
return collect()
83+
->when($this->before, function (Collection $collection) {
84+
return $collection->push($this->before);
85+
})
86+
->push("{$this->getPhpExecutable()} {$this->getArtisan()} {$this->command}")
87+
->when($this->after, function (Collection $collection) {
88+
return $collection->push($this->after);
89+
})
90+
->implode(' && ');
91+
}
92+
93+
/**
94+
* Get the path to PHP executable.
95+
*
96+
* @return string
97+
*/
98+
protected function getPhpExecutable()
99+
{
100+
return (new PhpExecutableFinder)->find();
101+
}
102+
103+
/**
104+
* Get the path to artisan.
105+
*
106+
* @return string
107+
*/
108+
protected function getArtisan()
109+
{
110+
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
111+
}
112+
}

0 commit comments

Comments
 (0)