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 SebastianFeldmann\CaptainHook\Runner\Action; |
11
|
|
|
|
12
|
|
|
use SebastianFeldmann\CaptainHook\Config; |
13
|
|
|
use SebastianFeldmann\CaptainHook\Console\IO; |
14
|
|
|
use SebastianFeldmann\CaptainHook\Exception; |
15
|
|
|
use SebastianFeldmann\CaptainHook\Hook\Action; |
16
|
|
|
use SebastianFeldmann\Cli\Processor\ProcOpen as Processor; |
17
|
|
|
use SebastianFeldmann\Git\Repository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Cli |
21
|
|
|
* |
22
|
|
|
* @package CaptainHook |
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
24
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
25
|
|
|
* @since Class available since Release 0.9.0 |
26
|
|
|
*/ |
27
|
|
|
class Cli implements Action |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Execute the configured action. |
31
|
|
|
* |
32
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config $config |
33
|
|
|
* @param \SebastianFeldmann\CaptainHook\Console\IO $io |
34
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
35
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config\Action $action |
36
|
|
|
* @throws \Exception |
37
|
|
|
*/ |
38
|
3 |
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action) |
39
|
|
|
{ |
40
|
3 |
|
$processor = new Processor(); |
41
|
3 |
|
$result = $processor->run($action->getAction()); |
42
|
|
|
|
43
|
3 |
|
if (!$result->isSuccessful()) { |
44
|
1 |
|
throw Exception\ActionFailed::withMessage($result->getStdOut() . PHP_EOL . $result->getStdErr()); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
$io->write($result->getStdOut()); |
48
|
2 |
|
} |
49
|
|
|
} |
50
|
|
|
|