1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of CaptainHook. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace CaptainHook\App\Hook; |
11
|
|
|
|
12
|
|
|
use CaptainHook\App\Config; |
13
|
|
|
use CaptainHook\App\Console\IO; |
14
|
|
|
use CaptainHook\App\Exception\ActionFailed; |
15
|
|
|
use SebastianFeldmann\Git\Repository; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Debug hook to test hook triggering |
19
|
|
|
* |
20
|
|
|
* @package CaptainHook |
21
|
|
|
* @author Sebastian Feldmann <[email protected]> |
22
|
|
|
* @link https://github.com/captainhookphp/captainhook |
23
|
|
|
* @since Class available since Release 4.0.4 |
24
|
|
|
*/ |
25
|
|
|
class Debug implements Action |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Executes the action |
29
|
|
|
* |
30
|
|
|
* @param \CaptainHook\App\Config $config |
31
|
|
|
* @param \CaptainHook\App\Console\IO $io |
32
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
33
|
|
|
* @param \CaptainHook\App\Config\Action $action |
34
|
|
|
* @return void |
35
|
|
|
* @throws \Exception |
36
|
|
|
*/ |
37
|
1 |
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action) : void |
38
|
|
|
{ |
39
|
1 |
|
$originalHookArguments = $io->getArguments(); |
40
|
1 |
|
$currentGitTag = $repository->getInfoOperator()->getCurrentTag(); |
41
|
|
|
|
42
|
1 |
|
$io->write('<info>Executing Dummy action</info>'); |
43
|
1 |
|
$io->write($this->getArgumentOutput($originalHookArguments)); |
44
|
1 |
|
$io->write(' Current git-tag: <comment>' . $currentGitTag . '</comment>'); |
45
|
|
|
|
46
|
1 |
|
throw ActionFailed::withMessage( |
47
|
|
|
'The \'Debug\' action is only for debugging purposes, ' . |
48
|
1 |
|
'please remove the \'Debug\' action from your config' |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Format output to display original hook arguments |
54
|
|
|
* |
55
|
|
|
* @param array $args |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
1 |
|
protected function getArgumentOutput(array $args) : string |
59
|
|
|
{ |
60
|
1 |
|
$out = ' Original arguments:' . PHP_EOL; |
61
|
1 |
|
foreach ($args as $name => $value) { |
62
|
1 |
|
$out .= ' ' . $name . ' => <comment>' . $value . '</comment>' . PHP_EOL; |
63
|
|
|
} |
64
|
1 |
|
return $out; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|