|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of CaptainHook |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Hook\UserInput; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Config; |
|
15
|
|
|
use CaptainHook\App\Console\IO; |
|
16
|
|
|
use CaptainHook\App\Hook\Action; |
|
17
|
|
|
use CaptainHook\App\Hook\EventSubscriber; |
|
18
|
|
|
use SebastianFeldmann\Git\Repository; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Debug hook to test hook triggering that fails the hook execution |
|
22
|
|
|
* |
|
23
|
|
|
* @package CaptainHook |
|
24
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
25
|
|
|
* @link https://github.com/captainhookphp/captainhook |
|
26
|
|
|
* @since Class available since Release 5.20.1 |
|
27
|
|
|
*/ |
|
28
|
|
|
class AskConfirmation implements Action, EventSubscriber |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Default question to ask the user |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private static string $defaultMessage = 'Do you want to continue? [yes|no]'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Executes the action |
|
39
|
|
|
* |
|
40
|
|
|
* @param \CaptainHook\App\Config $config |
|
41
|
|
|
* @param \CaptainHook\App\Console\IO $io |
|
42
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
|
43
|
|
|
* @param \CaptainHook\App\Config\Action $action |
|
44
|
|
|
* @return void |
|
45
|
|
|
* @throws \Exception |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action): void |
|
48
|
|
|
{ |
|
49
|
|
|
// this action is just registering some event handler, so nothing to see here |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns a list of event handlers |
|
54
|
|
|
* |
|
55
|
|
|
* @param \CaptainHook\App\Config\Action $action |
|
56
|
|
|
* @return array<string, array<int, \CaptainHook\App\Event\Handler>> |
|
57
|
|
|
* @throws \Exception |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public static function getEventHandlers(Config\Action $action): array |
|
60
|
|
|
{ |
|
61
|
1 |
|
$msg = $action->getOptions()->get('message', self::$defaultMessage); |
|
62
|
1 |
|
$default = (bool) $action->getOptions()->get('default', false); |
|
63
|
1 |
|
return [ |
|
64
|
1 |
|
'onHookSuccess' => [new EventHandler\AskConfirmation($msg, $default)] |
|
65
|
1 |
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|