1
|
<?php
|
2
|
|
3
|
namespace Illuminate\Console;
|
4
|
|
5
|
use Closure;
|
6
|
|
7
|
trait ConfirmableTrait
|
8
|
{
|
9
|
/**
|
10
|
* Confirm before proceeding with the action.
|
11
|
*
|
12
|
* @param string $warning
|
13
|
* @param \Closure|bool|null $callback
|
14
|
* @return bool
|
15
|
*/
|
16
|
public function confirmToProceed($warning = 'Application In Production!', $callback = null)
|
17
|
{
|
18
|
$callback = is_null($callback) ? $this->getDefaultConfirmCallback() : $callback;
|
19
|
|
20
|
$shouldConfirm = $callback instanceof Closure ? call_user_func($callback) : $callback;
|
21
|
|
22
|
if ($shouldConfirm) {
|
23
|
if ($this->option('force')) {
|
24
|
return true;
|
25
|
}
|
26
|
|
27
|
$this->comment(str_repeat('*', strlen($warning) + 12));
|
28
|
$this->comment('* '.$warning.' *');
|
29
|
$this->comment(str_repeat('*', strlen($warning) + 12));
|
30
|
$this->output->writeln('');
|
31
|
|
32
|
$confirmed = $this->confirm('Do you really wish to run this command?');
|
33
|
|
34
|
if (! $confirmed) {
|
35
|
$this->comment('Command Cancelled!');
|
36
|
|
37
|
return false;
|
38
|
}
|
39
|
}
|
40
|
|
41
|
return true;
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Get the default confirmation callback.
|
46
|
*
|
47
|
* @return \Closure
|
48
|
*/
|
49
|
protected function getDefaultConfirmCallback()
|
50
|
{
|
51
|
return function () {
|
52
|
return $this->getLaravel()->environment() == 'production';
|
53
|
};
|
54
|
}
|
55
|
}
|