|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace CaptainHook\App\Hook\Template; |
|
15
|
|
|
|
|
16
|
|
|
use CaptainHook\App\Config; |
|
17
|
|
|
use CaptainHook\App\Console\Runtime\Resolver; |
|
18
|
|
|
use CaptainHook\App\Hook\Template; |
|
19
|
|
|
use CaptainHook\App\Hook\Template\Local\PHP; |
|
20
|
|
|
use CaptainHook\App\Hook\Template\Local\Shell; |
|
21
|
|
|
use CaptainHook\App\Hook\Template\Local\WSL; |
|
22
|
|
|
use RuntimeException; |
|
23
|
|
|
use SebastianFeldmann\Git\Repository; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Builder class |
|
27
|
|
|
* |
|
28
|
|
|
* Creates git hook Template objects regarding some provided input. |
|
29
|
|
|
* |
|
30
|
|
|
* @package CaptainHook |
|
31
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
32
|
|
|
* @link https://github.com/captainhookphp/captainhook |
|
33
|
|
|
* @since Class available since Release 4.3.0 |
|
34
|
|
|
*/ |
|
35
|
|
|
abstract class Builder |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Creates a template that is responsible for the git hook sourcecode |
|
39
|
|
|
* |
|
40
|
|
|
* @param \CaptainHook\App\Config $config |
|
41
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
|
42
|
|
|
* @param \CaptainHook\App\Console\Runtime\Resolver $resolver |
|
43
|
|
|
* @return \CaptainHook\App\Hook\Template |
|
44
|
|
|
*/ |
|
45
|
17 |
|
public static function build(Config $config, Repository $repository, Resolver $resolver): Template |
|
46
|
|
|
{ |
|
47
|
17 |
|
$pathInfo = new PathInfo($repository->getRoot(), $config->getPath(), $resolver->getExecutable()); |
|
48
|
16 |
|
$bootstrapPath = dirname($config->getPath()) . '/' . $config->getBootstrap(); |
|
49
|
|
|
|
|
50
|
16 |
|
if (!file_exists($bootstrapPath)) { |
|
51
|
1 |
|
throw new RuntimeException('bootstrap file not found: \'' . $bootstrapPath . '\''); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
15 |
|
switch ($config->getRunConfig()->getMode()) { |
|
55
|
|
|
case Template::DOCKER: |
|
56
|
2 |
|
return new Docker( |
|
57
|
2 |
|
$pathInfo, |
|
58
|
2 |
|
$config |
|
59
|
2 |
|
); |
|
60
|
|
|
case Template::PHP: |
|
61
|
1 |
|
return new PHP( |
|
62
|
1 |
|
$pathInfo, |
|
63
|
1 |
|
$config, |
|
64
|
1 |
|
$resolver->isPharRelease() |
|
65
|
1 |
|
); |
|
66
|
|
|
case Template::WSL: |
|
67
|
1 |
|
return new WSL( |
|
68
|
1 |
|
$pathInfo, |
|
69
|
1 |
|
$config, |
|
70
|
1 |
|
$resolver->isPharRelease() |
|
71
|
1 |
|
); |
|
72
|
|
|
default: |
|
73
|
11 |
|
return new Shell( |
|
74
|
11 |
|
$pathInfo, |
|
75
|
11 |
|
$config, |
|
76
|
11 |
|
$resolver->isPharRelease() |
|
77
|
11 |
|
); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|