Skip to content

Commit 112843b

Browse files
committed
feature: Allow registering a post-installation hook
1 parent e38387c commit 112843b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Sail.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/**
99
* @method static self setBaseTemplate(string $stub)
1010
* @method static self addService(string $service, ?string $stubPath = null, ?bool $persistent = null, ?bool $default = null, ?bool $dependency = null, ?Closure $configuringEnv = null, ?Closure $afterInstall = null)
11+
* @method static self registerInstallHook(Closure $closure)
1112
* @method static self registerPublishHook(Closure $closure)
1213
* @method static string getBaseTemplate()
1314
* @method static array availableServices(bool $default = false)

src/Services.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class Services
5959
*/
6060
protected string $composeStub = __DIR__ . '/../stubs/docker-compose.stub';
6161

62+
/**
63+
* Hooks to be run after all services are configured
64+
*
65+
* @var Closure[]
66+
*/
67+
protected array $afterInstall = [];
68+
6269
/**
6370
* Hooks to be run during the publish command
6471
*
@@ -237,6 +244,19 @@ public function addService(string $service,
237244
return $this;
238245
}
239246

247+
/**
248+
* Add a hook to the pipeline executed during the installation command.
249+
*
250+
* @param Closure $closure
251+
* @return $this
252+
*/
253+
public function registerInstallHook(Closure $closure): self
254+
{
255+
$this->afterInstall[] = $closure;
256+
257+
return $this;
258+
}
259+
240260
/**
241261
* Add a hook to the pipeline executed during the publish command.
242262
*
@@ -328,7 +348,7 @@ public function replaceEnvVariables(string $environment, array $services): strin
328348
}
329349

330350
/**
331-
* Execute hooks for the requested services.
351+
* Execute hooks set for the installation command.
332352
*
333353
* @param Command $command
334354
* @param array $services
@@ -342,6 +362,9 @@ public function runInstallHooks(Command $command, array $services, string $appSe
342362
$this->services[$service]['after_install']($command, $services, $appService);
343363
}
344364
}
365+
foreach ($this->afterInstall as $hook) {
366+
$hook($command, $services, $appService);
367+
}
345368
}
346369

347370
/**

0 commit comments

Comments
 (0)