Skip to content

Commit 97de8bb

Browse files
committed
refactor: move code from spark to Boot class
1 parent c1ca7b7 commit 97de8bb

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

spark

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,41 +80,5 @@ $paths = new Config\Paths();
8080

8181
// LOAD THE FRAMEWORK BOOTSTRAP FILE
8282
require $paths->systemDirectory . '/Boot.php';
83-
CodeIgniter\Boot::BootSpark($paths);
8483

85-
/*
86-
* ---------------------------------------------------------------
87-
* GRAB OUR CODEIGNITER INSTANCE
88-
* ---------------------------------------------------------------
89-
*/
90-
91-
$app = Config\Services::codeigniter();
92-
$app->initialize();
93-
94-
/*
95-
* ---------------------------------------------------------------
96-
* GRAB OUR CONSOLE
97-
* ---------------------------------------------------------------
98-
*/
99-
100-
$console = new CodeIgniter\CLI\Console();
101-
102-
// SHOW HEADER
103-
// Show basic information before we do anything else.
104-
if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) {
105-
unset($_SERVER['argv'][$suppress]); // @codeCoverageIgnore
106-
$suppress = true;
107-
}
108-
109-
$console->showHeader($suppress);
110-
111-
/*
112-
*---------------------------------------------------------------
113-
* EXECUTE THE COMMAND
114-
*---------------------------------------------------------------
115-
*/
116-
117-
// fire off the command in the main framework.
118-
$exit = $console->run();
119-
120-
exit(is_int($exit) ? $exit : EXIT_SUCCESS);
84+
exit(CodeIgniter\Boot::BootSpark($paths));

system/Boot.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CodeIgniter;
1515

1616
use CodeIgniter\Cache\FactoriesCache;
17+
use CodeIgniter\CLI\Console;
1718
use CodeIgniter\Config\DotEnv;
1819
use Config\Autoload;
1920
use Config\Cache;
@@ -73,8 +74,10 @@ public static function bootWeb(Paths $paths): int
7374

7475
/**
7576
* Used by `spark`
77+
*
78+
* @return int Exit code.
7679
*/
77-
public static function bootSpark(Paths $paths): void
80+
public static function bootSpark(Paths $paths): int
7881
{
7982
static::definePathConstants($paths);
8083
if (! defined('APP_NAMESPACE')) {
@@ -90,6 +93,11 @@ public static function bootSpark(Paths $paths): void
9093
static::loadAutoloader();
9194
static::setExceptionHandler();
9295
static::initializeKint();
96+
97+
static::initializeCodeIgniter();
98+
$console = static::initializeConsole();
99+
100+
return static::runCommand($console);
93101
}
94102

95103
/**
@@ -299,4 +307,27 @@ protected static function saveConfigCache(FactoriesCache $factoriesCache): void
299307
{
300308
$factoriesCache->save('config');
301309
}
310+
311+
protected static function initializeConsole(): Console
312+
{
313+
$console = new Console();
314+
315+
// Show basic information before we do anything else.
316+
// @phpstan-ignore-next-line
317+
if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) {
318+
unset($_SERVER['argv'][$suppress]); // @phpstan-ignore-line
319+
$suppress = true;
320+
}
321+
322+
$console->showHeader($suppress);
323+
324+
return $console;
325+
}
326+
327+
protected static function runCommand(Console $console): int
328+
{
329+
$exit = $console->run();
330+
331+
return is_int($exit) ? $exit : EXIT_SUCCESS;
332+
}
302333
}

0 commit comments

Comments
 (0)