forked from rodrigopedra/laravel-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShellCommand.php
64 lines (55 loc) · 1.39 KB
/
ShellCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App;
use Illuminate\Support\Str;
class ShellCommand
{
/**
* The shell command.
*
* @var string
*/
public $command;
/**
* Create a new shell command instance.
*
* @param string $command
* @return void
*/
public function __construct($command)
{
$this->command = $command;
}
/**
* Determine if the given server can run the build command.
*
* @param \App\Server $server
* @return bool
*/
public function appliesTo($server)
{
return $server->runsCommand($this->command);
}
/**
* Determine if the command is prefixed with the given false.
*
* @param string $prefix
* @return bool
*/
public function prefixed($prefix)
{
return $prefix ? Str::startsWith($this->command, $prefix) : false;
}
/**
* Convert the command to a formatted string.
*
* @return string
*/
public function trim()
{
$command = $this->command;
$command = Str::startsWith($command, 'once:') ? Str::replaceFirst('once:', '', $command) : $command;
$command = Str::startsWith($command, 'web:') ? Str::replaceFirst('web:', '', $command) : $command;
$command = Str::startsWith($command, 'worker:') ? Str::replaceFirst('worker:', '', $command) : $command;
return trim($command);
}
}