Hi,
I’m trying to apply this guide https://www.yiiframework.com/doc/guide/2.0/en/structure-extensions#bootstrapping-classes to an extension in order to load internationalization files of my extension during bootstrap. The problem is that the bootstrap method is never called.
If I add the created class to the bootstrap configuration property of my application the bootstrap method is correctly called.
Here my implementation:
From 2cb21d9fca6214df7cd6905078b142d6e902901b Mon Sep 17 00:00:00 2001
From: Liviu Calin <liviu.calin@yetopen.it>
Date: Mon, 29 Nov 2021 12:10:53 +0100
Subject: [PATCH] Bootstrap test
---
Bootstrap.php | 23 +++++++++++++++++++++++
composer.json | 3 +++
dictionaries/UnitMeasureDictionary.php | 4 ++++
messages/it/yohelpers.php | 1 +
4 files changed, 31 insertions(+)
create mode 100644 Bootstrap.php
diff --git a/Bootstrap.php b/Bootstrap.php
new file mode 100644
index 0000000..96f620d
--- /dev/null
+++ b/Bootstrap.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace yetopen\helpers;
+
+use yii\base\BootstrapInterface;
+
+class Bootstrap implements BootstrapInterface
+{
+ public function bootstrap($app)
+ {
+ \Yii::setAlias('@yohelpers', '@vendor/yetopen/yii2-helpers');
+ if (empty(\Yii::$app->i18n->translations['yohelpers'])) {
+ \Yii::$app->i18n->translations['yohelpers'] = [
+ 'class' => 'yii\i18n\PhpMessageSource',
+ 'basePath' => '@yohelpers/messages',
+ 'fileMap' => [
+ 'yohelpers' => 'yohelpers.php',
+ ],
+ ];
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 3567b53..6d59bfa 100644
--- a/composer.json
+++ b/composer.json
@@ -12,5 +12,8 @@
"psr-4": {
"yetopen\\helpers\\": ""
}
+ },
+ "extra": {
+ "bootstrap": "yetopen\\helpers\\Bootstrap"
}
}
--
GitLab
I’ve done composer update
of the extension in the main application in order to get the modifications loaded through composer itself.
Am I missing something in order to get bootstrapping code being executed without the use of the configuration property?