futuretek / yii2-composer
Yii 扩展安装程序的 composer 插件
2.0.0
2021-10-22 13:39 UTC
This package is auto-updated.
Last update: 2024-09-22 20:27:59 UTC
README
这是 Yii 2 扩展的 composer 安装程序。它实现了一个名为 yii2-extension
的新 composer 包类型,如果它们作为 composer 包分发,所有 Yii 2 扩展都应该使用此类型。
用法
要使用 Yii 2 composer 安装程序,只需在您的 composer.json
文件中将包的 type
设置为 yii2-extension
,如下所示
{ "type": "yii2-extension", "require": { "yiisoft/yii2": "~2.0.0" }, ... }
您可以在 extra
部分指定一个引导类。每次 Yii 2 应用程序响应请求时,都会执行该类的 init()
方法。例如
{ "type": "yii2-extension", ..., "extra": { "bootstrap": "yii\\jui\\Extension" } }
Installer
类还实现了一个静态方法 postCreateProject()
,可以在通过 post-create-project-cmd
composer 脚本创建 Yii 2 项目之后调用。还有一个类似的方法可以在每次调用 composer install
后运行任务,即 postInstall()
。这些方法允许运行其他 Installer
类方法,如 setPermission()
或 generateCookieValidationKey()
,具体取决于在 composer.json
文件的 extra
部分中设置的相应参数。例如
{ "name": "yiisoft/yii2-app-basic", "type": "project", ... "scripts": { "post-create-project-cmd": [ "futuretek\\composer\\Installer::postCreateProject" ], "post-install-cmd": [ "futuretek\\composer\\Installer::postInstall" ] }, "extra": { "futuretek\\composer\\Installer::postCreateProject": { "setPermission": [ { "runtime": "0777", "web/assets": "0777", "yii": "0755" } ] }, "futuretek\\composer\\Installer::postInstall": { "copyFiles": [ { "config/templates/console-local.php": "config/console-local.php", "config/templates/web-local.php": "config/web-local.php", "config/templates/db-local.php": "config/db-local.php", "config/templates/cache.json": ["runtime/cache.json", true] } ], "generateCookieValidationKey": [ "config/web-local.php" ] } } }
新增功能
- 自动注册扩展到主应用 PHPMessageSource 的翻译
- 扩展可以通过
/vendor/futuretek/*.php
文件将设置传播到 yii 配置
待办事项
- 更好的文档