Skip to content

Commit

Permalink
Merge branch 'master' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ivanov committed Mar 7, 2020
2 parents 7a20b9b + 6829f54 commit 5642da8
Show file tree
Hide file tree
Showing 35 changed files with 551 additions and 248 deletions.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ $array = array_except_value($array, ['bar', 'baz']);

#### `multiarray_set()`

Set a value for each item of the multidimensional array using "dot" notation:
Set value for each item of the multidimensional array using "dot" notation:

```php
$array = [
Expand All @@ -129,7 +129,7 @@ multiarray_set($array, 'details.country', 'Germany');
#### `multiarray_sort_by()`
Sort the multidimensional array by few fields:
Sort the multidimensional array by several fields:
```php
$array = [
Expand Down Expand Up @@ -171,15 +171,15 @@ $sorted = multiarray_sort_by($array, 'name', SORT_ASC, 'model', SORT_DESC);
#### `call_in_background()`
Call artisan console command in the background. Code execution continues immediately, without waiting for results.
Call the given artisan console command in background. Code execution continues immediately, without waiting for results.
```php
call_in_background('report');
// "php artisan report" would be called in background
```
Optional `before` and `after` sub-commands can be set as a second and third parameter:
Optional `before` and `after` sub-commands could be provided:
```php
call_in_background('report:monthly subscriptions', 'sleep 0.3');
Expand All @@ -191,7 +191,7 @@ call_in_background('report:monthly subscriptions', 'sleep 0.3');
#### `db_is_sqlite()`
Check if the default database connection driver is `sqlite` or not:
Check whether the default database connection driver is `sqlite` or not:
```php
if (db_is_sqlite()) {
Expand All @@ -201,7 +201,7 @@ if (db_is_sqlite()) {
#### `db_is_mysql()`
Check if the default database connection driver is `mysql` or not:
Check whether the default database connection driver is `mysql` or not:
```php
if (db_is_mysql()) {
Expand All @@ -211,7 +211,7 @@ if (db_is_mysql()) {
#### `db_mysql_now()`
Get database datetime, using `mysql` connection:
Get the current MySQL datetime:
```php
$now = db_mysql_now();
Expand All @@ -221,7 +221,7 @@ $now = db_mysql_now();
#### `db_mysql_variable()`
Get the value of specified `mysql` variable, or `false` if the variable doesn't exist:
Get value of the specified MySQL variable:
```php
$hostname = db_mysql_variable('hostname');
Expand All @@ -233,7 +233,7 @@ $hostname = db_mysql_variable('hostname');
#### `to_default_timezone()`
Convert passed datetime string to the default timezone, which is `app.timezone` config setting:
Convert datetime to the default timezone (`app.timezone` config parameter):
```php
$date = to_default_timezone('2017-02-28T14:05:01Z');
Expand All @@ -257,7 +257,7 @@ $backtrace = backtrace_as_string();
#### `minimized_backtrace_as_string()`
Get minimized backtrace as a string:
Get minimized backtrace, as a string:
```php
$backtrace = minimized_backtrace_as_string();
Expand All @@ -271,7 +271,7 @@ $backtrace = minimized_backtrace_as_string();
#### `is_email()`
Check if the specified string is a valid email address or not:
Check whether the given string is an email address or not:
```php
$isEmail = is_email('[email protected]');
Expand All @@ -281,7 +281,7 @@ $isEmail = is_email('[email protected]');
#### `to_rfc2822_email()`
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:
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:
```php
$address = to_rfc2822_email([
Expand All @@ -292,7 +292,7 @@ $address = to_rfc2822_email([
// John Doe <[email protected]>, [email protected]
```
Also supports simplified syntax for single address item:
Also supports simplified syntax for single address:
```php
$address = to_rfc2822_email(['address' => '[email protected]', 'name' => 'John Doe']);
Expand All @@ -302,7 +302,7 @@ $address = to_rfc2822_email(['address' => '[email protected]', 'name' => 'Joh
#### `to_swiftmailer_emails()`
Convert addresses data to format, which is suitable for [SwiftMailer library](http://swiftmailer.org/docs/messages.html):
Convert addresses data to [SwiftMailer-suitable format](https://swiftmailer.org/docs/messages.html):
```php
$addresses = to_swiftmailer_emails([
Expand All @@ -313,7 +313,7 @@ $addresses = to_swiftmailer_emails([
// ["[email protected]" => "John Doe", "[email protected]"]
```
Also supports simplified syntax for single address item:
Also supports simplified syntax for single address:
```php
$address = to_swiftmailer_emails(['address' => '[email protected]', 'name' => 'John Doe']);
Expand All @@ -325,7 +325,7 @@ $address = to_swiftmailer_emails(['address' => '[email protected]', 'name' =>
#### `relative_path()`
Get the relative path for two directories:
Get relative path for the given folders:
```php
$path = relative_path('/var/www/htdocs', '/var/www/htdocs/example')
Expand All @@ -345,7 +345,7 @@ $path = relative_path('/var/www/htdocs/example/public/../../', '/var/')
#### `get_dump()`
Get nicely formatted string representation of the variable, using [Symfony VarDumper Component](http://symfony.com/doc/current/components/var_dumper/introduction.html):
Get nicely formatted string representation of the variable, using [Symfony VarDumper Component](https://symfony.com/doc/current/components/var_dumper/introduction.html):
```php
$array = [
Expand All @@ -368,7 +368,7 @@ $dump = get_dump($array);
#### `format_bytes()`
Format bytes into kilobytes, megabytes, gigabytes or terabytes, with specified precision:
Format bytes into kilobytes, megabytes, gigabytes or terabytes:
```php
$formatted = format_bytes(3333333);
Expand Down Expand Up @@ -407,15 +407,15 @@ $formatted = format_xml('<?xml version="1.0"?><root><task priority="low"><to>Joh
#### `is_json()`
Check if specified variable is a valid JSON-encoded string or not:
Check whether the given value is a valid JSON-encoded string or not:
```php
$isJson = is_json('{"foo":1,"bar":2,"baz":3}');
// true
```
It can return decoded JSON if you pass the second argument as `true`:
It returns decoded JSON if you pass `true` as a second argument:
```php
$decoded = is_json('{"foo":1,"bar":2,"baz":3}', true);
Expand All @@ -427,7 +427,7 @@ $decoded = is_json('{"foo":1,"bar":2,"baz":3}', true);
#### `str_lower()`
Convert string to lowercase, using `mb_strtolower` in `UTF-8` encoding:
Convert string to lowercase, assuming it's using the `UTF-8` encoding:
```php
$lower = str_lower('TeSt');
Expand All @@ -437,7 +437,7 @@ $lower = str_lower('TeSt');
#### `str_upper()`
Convert string to uppercase, using `mb_strtoupper` in `UTF-8` encoding:
Convert string to uppercase, assuming it's using the `UTF-8` encoding:
```php
$upper = str_upper('TeSt');
Expand All @@ -449,7 +449,7 @@ $upper = str_upper('TeSt');
#### `is_windows_os()`
Check if PHP is running on Windows OS or not:
Check whether the operating system is Windows or not:
```php
$isWindowsOs = is_windows_os();
Expand All @@ -461,7 +461,7 @@ $isWindowsOs = is_windows_os();
#### `xml_to_array()`
Convert XML string to the array:
Convert XML string to array:
```php
$array = xml_to_array('<?xml version="1.0"?>
Expand Down Expand Up @@ -495,11 +495,11 @@ $array = xml_to_array('<?xml version="1.0"?>
// ]
```
Alternatively, you can pass an instance of a `SimpleXMLElement` object, to get the same results.
Alternatively, you can pass an instance of `SimpleXMLElement` as a first argument.
#### `array_to_xml()`
Convert array to XML string using [spatie/array-to-xml](https://github.com/spatie/array-to-xml) package:
Convert array to XML string:
```php
$array = [
Expand Down
112 changes: 112 additions & 0 deletions src/Helpers/Artisan/BackgroundCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Illuminated\Helpers\Artisan;

use Illuminate\Support\Collection;
use Symfony\Component\Process\PhpExecutableFinder;

class BackgroundCommand
{
/**
* The artisan command.
*
* @var string
*/
private $command;

/**
* The command which should be executed before.
*
* @var string
*/
private $before;

/**
* The command which should be executed after.
*
* @var string
*/
private $after;

/**
* Create background command by the given parameters.
*
* @param string $command
* @param string $before
* @param string $after
* @return \Illuminated\Helpers\Artisan\BackgroundCommand
*/
public static function factory(string $command, string $before = '', string $after = '')
{
return new self($command, $before, $after);
}

/**
* Create a new instance of the background command.
*
* @param string $command
* @param string $before
* @param string $after
* @return void
*/
public function __construct(string $command, string $before = '', string $after = '')
{
$this->command = $command;
$this->before = $before;
$this->after = $after;
}

/**
* Run the command in background.
*
* @return void
*/
public function run()
{
$command = $this->composeCommand();

$command = is_windows_os()
? "start /B {$command}"
: "({$command}) > /dev/null 2>&1 &";

exec($command);
}

/**
* Compose the command.
*
* @return string
*/
protected function composeCommand()
{
return collect()
->when($this->before, function (Collection $collection) {
return $collection->push($this->before);
})
->push("{$this->getPhpExecutable()} {$this->getArtisan()} {$this->command}")
->when($this->after, function (Collection $collection) {
return $collection->push($this->after);
})
->implode(' && ');
}

/**
* Get the path to PHP executable.
*
* @return string
*/
protected function getPhpExecutable()
{
return (new PhpExecutableFinder)->find();
}

/**
* Get the path to artisan.
*
* @return string
*/
protected function getArtisan()
{
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
}
}
Loading

0 comments on commit 5642da8

Please sign in to comment.