Skip to content

Commit

Permalink
Fix bootstrap (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiiliveext committed Aug 15, 2021
1 parent 8c77bdd commit 1971eae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
10 changes: 9 additions & 1 deletion composer.json
Expand Up @@ -141,7 +141,15 @@
"providers-console.php"
],
"routes": "routes.php",
"bootstrap": "bootstrap.php"
"bootstrap": "bootstrap.php",
"bootstrap-web": [
"$bootstrap",
"bootstrap-web.php"
],
"bootstrap-console": [
"$bootstrap",
"bootstrap-console.php"
]
},
"installer-types": [
"npm-asset"
Expand Down
5 changes: 5 additions & 0 deletions config/bootstrap-console.php
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

return [];
5 changes: 5 additions & 0 deletions config/bootstrap-web.php
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

return [];
6 changes: 4 additions & 2 deletions src/ApplicationRunner.php
Expand Up @@ -60,10 +60,12 @@ public function run(): void

$container = $container->get(ContainerInterface::class);

$bootstrapList = $config->get('bootstrap');
$bootstrapList = $config->get('bootstrap-web');
foreach ($bootstrapList as $callback) {
if (!(is_callable($callback))) {
throw new \RuntimeException('Bootstrap callback must be callable.');
$type = is_object($callback) ? get_class($callback) : gettype($callback);

throw new \RuntimeException("Bootstrap callback must be callable, $type given.");
}
$callback($container);
}
Expand Down
10 changes: 10 additions & 0 deletions yii
Expand Up @@ -26,6 +26,16 @@ $container = new Container(
/** @var ContainerInterface $container */
$container = $container->get(ContainerInterface::class);

$bootstrapList = $config->get('bootstrap-console');
foreach ($bootstrapList as $callback) {
if (!(is_callable($callback))) {
$type = is_object($callback) ? get_class($callback) : gettype($callback);

throw new \RuntimeException("Bootstrap callback must be callable, $type given.");
}
$callback($container);
}

$application = $container->get(Application::class);
$exitCode = 1;

Expand Down

0 comments on commit 1971eae

Please sign in to comment.