Skip to content

Commit 98ff4fc

Browse files
Allowed passing multiple hooks for installation (hook argument) via comma.
Changed hooksToHandle property type to array and work with it correspondingly.
1 parent 728fe38 commit 98ff4fc

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/Runner/Installer.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class Installer extends RepositoryAware
5959
/**
6060
* Hook that should be handled.
6161
*
62-
* @var string
62+
* @var array
6363
*/
64-
protected $hookToHandle;
64+
protected $hooksToHandle;
6565

6666
/**
6767
* Hook template
@@ -138,10 +138,23 @@ public function setMoveExistingTo(string $backup): Installer
138138
*/
139139
public function setHook(string $hook): Installer
140140
{
141-
if (!empty($hook) && !HookUtil::isInstallable($hook)) {
142-
throw new Exception\InvalidHookName('Invalid hook name \'' . $hook . '\'');
141+
if (!empty($hook)) {
142+
$hooks = explode(',', $hook);
143+
if ($hooks === false) {
144+
throw new Exception\InvalidHookName('Invalid hook name \'' . $hook . '\'');
145+
}
146+
$hooksValidationCallback = static function (string $hook): bool {
147+
return !HookUtil::isInstallable($hook);
148+
};
149+
if (!empty(($invalidHooks = array_filter($hooks, $hooksValidationCallback)))) {
150+
throw new Exception\InvalidHookName(
151+
'Invalid hook name \'' . implode(',', $invalidHooks) . '\''
152+
);
153+
}
154+
155+
$this->hooksToHandle = $hooks;
143156
}
144-
$this->hookToHandle = $hook;
157+
145158
return $this;
146159
}
147160

@@ -178,9 +191,9 @@ public function getHooksToInstall(): array
178191
return true;
179192
};
180193
// if a specific hook is set, the use has actively chosen it, so don't ask for permission anymore
181-
return empty($this->hookToHandle)
194+
return empty($this->hooksToHandle)
182195
? array_map($callback, Hooks::nativeHooks())
183-
: [$this->hookToHandle => false];
196+
: array_map(static function (): bool { return false; }, array_flip($this->hooksToHandle));
184197
}
185198

186199
/**

0 commit comments

Comments
 (0)