The bottom line is that the project is closely tied to one vendor, does not leave stable releases. It is necessary to connect this component from this folder (example: app / vendor_name), saving the old namespace. The component is connected in the config / web, in the modules section. How can this be implemented?
1 answer
I will show on the example of the kartik-v/yii2-widget-datepicker . We will remove this module from the vendor folder to the common/modules folder.
1) Remove the string from the require section in composer.json which is responsible for the module that we submit. That is, in our example, we delete the line "kartik-v/yii2-widget-datepicker": "@dev",
2) Open the file vendor/composer/autoload_psr4.php and find inside it the line responsible for the module to be 'kartik\\date\\' => array($vendorDir . '/kartik-v/yii2-widget-datepicker'), (in our example this line is 'kartik\\date\\' => array($vendorDir . '/kartik-v/yii2-widget-datepicker'), ).
3) Create inside composer.json on the same level with the require and require-dev sections a new autoload section (if not). Inside this section we create another psr-4 section and inside it we put the newly found line from the file vendor/composer/autoload_psr4.php with minor changes (you need to replace $vendorDir with the path to the folder where the module will be located and some other changes).
An example of the resulting section:
"autoload": { "psr-4": { "kartik\\date\\": "common/modules/kartik-v/yii2-widget-datepicker" } } 4) Open the file vendor/yiisoft/extensions.php and find in it a block with our module. In our case, the block looks like this:
'kartik-v/yii2-widget-datepicker' => array ( 'name' => 'kartik-v/yii2-widget-datepicker', 'version' => '9999999-dev', 'alias' => array ( '@kartik/date' => $vendorDir . '/kartik-v/yii2-widget-datepicker', ), ), 5) Open the configuration file ( common/config/main.php or config/web.php ). Inside the file, on the same level as components and modules create a new section extensions and attach the newly found array block (with a slight change, similar to step 3 , that is, replace $vendorDir with the path to the folder where the module will be located) to the same file from of which we copied it (this way the meeting may not understand this step, but with the experience of making the modules, understanding will come).
An example of the resulting section:
'extensions' => yii\helpers\ArrayHelper::merge( require( dirname(__DIR__) . '/vendor/yiisoft/extensions.php'), 'kartik-v/yii2-widget-datepicker' => array ( 'name' => 'kartik-v/yii2-widget-datepicker', 'version' => '9999999-dev', 'alias' => array ( '@kartik/date' => 'common/modules/kartik-v/yii2-widget-datepicker', ), ), ), 6) Make composer update and enjoy the result. Now this module is in our project, and we can change its code without worrying about the fact that the changes will disappear after updating the composer.
It looks complicated, but in fact it takes 2 minutes. Good luck.
- Should package dependencies be added to composer.json? And why add a package to the
extensionssection? - pa3py6aka