Skip to content

Commit a8656ce

Browse files
committed
Allow registering a post-installation hook
1 parent 4b1f72f commit a8656ce

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 baseTemplate()
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
*
@@ -245,6 +252,19 @@ public function addService(string $service,
245252
return $this;
246253
}
247254

255+
/**
256+
* Add a hook to the pipeline executed during the installation command.
257+
*
258+
* @param Closure $closure
259+
* @return $this
260+
*/
261+
public function registerInstallHook(Closure $closure): self
262+
{
263+
$this->afterInstall[] = $closure;
264+
265+
return $this;
266+
}
267+
248268
/**
249269
* Add a hook to the pipeline executed during the publish command.
250270
*
@@ -336,7 +356,7 @@ public function replaceEnvVariables(string $environment, array $services): strin
336356
}
337357

338358
/**
339-
* Execute hooks for the requested services.
359+
* Execute hooks set for the installation command.
340360
*
341361
* @param Command $command
342362
* @param array $services
@@ -350,6 +370,9 @@ public function runInstallHooks(Command $command, array $services, string $appSe
350370
$this->services[$service]['after_install']($command, $services, $appService);
351371
}
352372
}
373+
foreach ($this->afterInstall as $hook) {
374+
$hook($command, $services, $appService);
375+
}
353376
}
354377

355378
/**

0 commit comments

Comments
 (0)