1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\Initializer; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use MadWeb\Initializer\Contracts\Runner; |
7
|
|
|
|
8
|
|
|
class Run implements Runner |
9
|
|
|
{ |
10
|
|
|
protected $commands = []; |
11
|
|
|
|
12
|
24 |
|
public function artisan(string $command, array $arguments = []): Runner |
13
|
|
|
{ |
14
|
24 |
|
$this->pushCommand(__FUNCTION__, $command, $arguments); |
15
|
|
|
|
16
|
24 |
|
return $this; |
17
|
|
|
} |
18
|
|
|
|
19
|
6 |
|
public function external(string $command, ...$arguments): Runner |
20
|
|
|
{ |
21
|
6 |
|
$this->pushCommand(__FUNCTION__, $command, $arguments); |
22
|
|
|
|
23
|
6 |
|
return $this; |
24
|
|
|
} |
25
|
|
|
|
26
|
3 |
|
public function callable(callable $function, ...$arguments): Runner |
27
|
|
|
{ |
28
|
3 |
|
$this->pushCommand(__FUNCTION__, $function, $arguments); |
29
|
|
|
|
30
|
3 |
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
24 |
|
public function dispatch($job): Runner |
34
|
|
|
{ |
35
|
24 |
|
$this->pushCommand(__FUNCTION__, $job); |
36
|
|
|
|
37
|
24 |
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
6 |
|
public function dispatchNow($job): Runner |
41
|
|
|
{ |
42
|
6 |
|
$this->pushCommand(__FUNCTION__, $job); |
43
|
|
|
|
44
|
6 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
24 |
|
public function publish($providers): Runner |
48
|
|
|
{ |
49
|
24 |
|
if (is_string($providers)) { |
50
|
3 |
|
$this->artisan('vendor:publish', ['--provider' => $providers]); |
51
|
21 |
|
} elseif (is_array($providers)) { |
52
|
18 |
|
foreach ($providers as $provider => $tag) { |
53
|
18 |
|
$arguments = []; |
54
|
|
|
|
55
|
18 |
|
$arguments['--provider'] = is_numeric($provider) ? $tag : $provider; |
56
|
|
|
|
57
|
18 |
|
if (! is_numeric($provider) and is_string($tag)) { |
|
|
|
|
58
|
12 |
|
$arguments['--tag'] = $tag; |
59
|
|
|
} |
60
|
|
|
|
61
|
18 |
|
$this->artisan('vendor:publish', $arguments); |
62
|
|
|
} |
63
|
|
|
} else { |
64
|
3 |
|
throw new InvalidArgumentException('Invalid publishable argument.'); |
65
|
|
|
} |
66
|
|
|
|
67
|
21 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
60 |
|
protected function pushCommand(string $type, $command, array $arguments = []) |
71
|
|
|
{ |
72
|
60 |
|
$this->commands[] = compact('type', 'command', 'arguments'); |
73
|
60 |
|
} |
74
|
|
|
|
75
|
60 |
|
public function getCommands(): array |
76
|
|
|
{ |
77
|
60 |
|
return $this->commands; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.