diff --git a/.tools/bootstrap.php b/.tools/bootstrap.php index 424bf33536..55310c7b68 100644 --- a/.tools/bootstrap.php +++ b/.tools/bootstrap.php @@ -12,3 +12,5 @@ // use original error handlers of the tools ErrorHandler::unregister(); + +return $project; diff --git a/.tools/phpstan/console.php b/.tools/phpstan/console.php index 25d2fac840..ca4519b35d 100644 --- a/.tools/phpstan/console.php +++ b/.tools/phpstan/console.php @@ -3,11 +3,9 @@ use Redaxo\Core\Console\Application; use Redaxo\Core\Console\CommandLoader; -if (!defined('REX_MIN_PHP_VERSION')) { - require dirname(__DIR__) . '/bootstrap.php'; -} +$project = require dirname(__DIR__) . '/bootstrap.php'; -$application = new Application(); +$application = new Application($project); $application->setCommandLoader(new CommandLoader()); return $application; diff --git a/boot/addons.php b/boot/addons.php index a8fa33ec3c..aee8c3f4a3 100644 --- a/boot/addons.php +++ b/boot/addons.php @@ -1,11 +1,17 @@ enlist(); } +$this->enlist(); + // now we actually include the addons logic Timer::measure('packages_boot', static function () use ($packageOrder) { foreach ($packageOrder as $packageId) { @@ -31,3 +39,5 @@ // ----- all addons configs included Extension::registerPoint(new ExtensionPoint('PACKAGES_INCLUDED')); + +$this->boot(); diff --git a/boot/console.php b/boot/console.php index 16ec593756..a14b580c83 100644 --- a/boot/console.php +++ b/boot/console.php @@ -1,5 +1,6 @@ enlist(); } + + $this->enlist(); } $application->setCommandLoader(new CommandLoader()); diff --git a/src/AbstractProject.php b/src/AbstractProject.php index 019ec1d3d5..a86a9decb3 100644 --- a/src/AbstractProject.php +++ b/src/AbstractProject.php @@ -5,6 +5,9 @@ use Override; use Redaxo\Core\Exception\LogicException; use Redaxo\Core\Filesystem\DefaultPathProvider; +use Redaxo\Core\Filesystem\Path; +use Redaxo\Core\Translation\I18n; +use Redaxo\Core\View\Fragment; use ReflectionObject; use Symfony\Component\Runtime\RunnerInterface; use Throwable; @@ -12,6 +15,7 @@ use function dirname; use function sprintf; +use const DIRECTORY_SEPARATOR; use const STDERR; abstract class AbstractProject implements RunnerInterface @@ -54,6 +58,8 @@ public function __construct( public readonly string $environment, ) {} + public function boot(): void {} + final public function bootCore(): void { if ('console' === $this->environment) { @@ -81,6 +87,18 @@ final public function bootAddons(): void require dirname(__DIR__) . '/boot/addons.php'; } + final public function enlist(): void + { + $folder = Path::base('/'); + + if (is_readable($folder . 'lang')) { + I18n::addDirectory($folder . 'lang'); + } + if (is_readable($folder . 'fragments')) { + Fragment::addDirectory($folder . 'fragments' . DIRECTORY_SEPARATOR); + } + } + #[Override] final public function run(): int { diff --git a/src/Console/Application.php b/src/Console/Application.php index 024fc212da..46d1b9d251 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -6,6 +6,7 @@ use Exception; use Override; use ParseError; +use Redaxo\Core\AbstractProject; use Redaxo\Core\Addon\Addon; use Redaxo\Core\Console\Command\AbstractCommand; use Redaxo\Core\Console\Command\OnlySetupAddonsInterface; @@ -31,8 +32,9 @@ class Application extends SymfonyApplication { - public function __construct() - { + public function __construct( + private readonly AbstractProject $project, + ) { parent::__construct('REDAXO', Core::getVersion()); } @@ -117,6 +119,8 @@ private function loadPackages(AbstractCommand $command): void } Extension::registerPoint(new ExtensionPoint('PACKAGES_INCLUDED')); + + $this->project->boot(); } private function checkConsoleUser(InputInterface $input, OutputInterface $output): void