1 | <?php |
||
9 | class Installer extends LibraryInstaller |
||
10 | { |
||
11 | /** |
||
12 | * List of supported package types for this plugin. |
||
13 | * View all available types: https://github.com/composer/composer/blob/master/doc/04-schema.md#type |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | public static $supportedTypes = [ |
||
18 | 'git-hook', |
||
19 | 'library' |
||
20 | ]; |
||
21 | |||
22 | private $supportedHooks = [ |
||
23 | 'applypatch-msg', |
||
24 | 'pre-applypatch', |
||
25 | 'post-applypatch', |
||
26 | 'pre-commit', |
||
27 | 'prepare-commit-msg', |
||
28 | 'commit-msg', |
||
29 | 'post-commit', |
||
30 | 'pre-rebase', |
||
31 | 'post-checkout', |
||
32 | 'post-merge', |
||
33 | 'pre-push', |
||
34 | 'pre-receive', |
||
35 | 'update', |
||
36 | 'post-receive', |
||
37 | 'post-update', |
||
38 | 'push-to-checkout', |
||
39 | 'pre-auto-gc', |
||
40 | 'post-rewrite', |
||
41 | 'sendemail-validate' |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 5 | public function supports($packageType) |
|
51 | |||
52 | /** |
||
53 | * Determines the install path for git hooks, |
||
54 | * |
||
55 | * The installation path is the standard git hooks directory documented here: |
||
56 | * https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks |
||
57 | * |
||
58 | * @param PackageInterface $package |
||
59 | * |
||
60 | * @return string a path relative to the root of the composer.json that is being installed. |
||
61 | */ |
||
62 | 3 | public function getInstallPath(PackageInterface $package) |
|
63 | { |
||
64 | 3 | if (!$this->supports($package->getType())) { |
|
65 | 1 | throw new \InvalidArgumentException( |
|
66 | 'Unable to install package, git-hook packages only ' |
||
67 | . 'support "git-hook", "library" type packages.' |
||
68 | 1 | ); |
|
69 | } |
||
70 | |||
71 | // Allow to LibraryInstaller to resolve the installPath for other packages. |
||
72 | 2 | if ($package->getType() !== 'git-hook') { |
|
73 | 1 | return parent::getInstallPath($package); |
|
74 | } |
||
75 | |||
76 | 1 | return $this->getHooksInstallationPath(); |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Install the plugin to the git hooks path |
||
81 | * |
||
82 | * Note: This method installs the plugin into a temporary directory and then only copy the git-hook |
||
83 | * related files into the git hooks directory to avoid colision with other plugins. |
||
84 | */ |
||
85 | public function install(InstalledRepositoryInterface $repo, PackageInterface $package) |
||
101 | |||
102 | /** |
||
103 | * Return the git hooks path. |
||
104 | */ |
||
105 | 1 | protected function getGitHooksPath() |
|
114 | |||
115 | 1 | protected function getHooksInstallationPath() |
|
119 | |||
120 | /** |
||
121 | * @return array |
||
122 | */ |
||
123 | private function getSupportedHooks() |
||
127 | } |
||
128 |