index0h / yii2-phar
此包已被弃用且不再维护。未建议替代包。
基于 Yii2 的 Phar 构建器
0.0.3
2014-03-01 22:53 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: dev-master
- yiisoft/yii2-composer: dev-master
Requires (Dev)
- codeception/codeception: 1.8.2
This package is not auto-updated.
Last update: 2020-01-24 15:18:58 UTC
README
此模块为 Yii2 应用程序提供构建 Phar 归档的命令行界面。
安装
通过 composer 安装此扩展是首选方式。
php composer.phar require --prefer-dist index0h/yii2-phar "*"
或向 composer.json
的 require 部分添加以下行
"index0h/yii2-phar": "*"
独立使用
- 安装
php composer.phar global require index0h/yii2-phar:*
- 运行
yii2-phar
# Or with external configuration
yii2-phar phar/build myConfiguration.php
使用
安装模块后,请按以下方式修改您的应用程序配置
return [ 'modules' => [ 'phar' => 'index0h\\phar\\Module', ... ], ... ];
您可以通过控制台访问 yii2-phar 模块
yii phar/build
选项
- compress - 压缩算法数组,\Phar::GZ, \Phar::BZ2。创建压缩后的主 Phar 文件。
- files - 要编译的文件列表。
- folders - 要编译的目录列表。
- ignore - 忽略构建时必须忽略的正则表达式模式列表。这意味着如果任何文件与任何模式匹配,则将其忽略。
- path - Phar 文件保存路径。
- pharName - Phar 名称。
- signature - Phar 签名算法之一。如果是 Phar::OPENSSL,则 openSSLPrivateKeyAlias 是必需的。
- openSSLPrivateKeyAlias - OpenSSL 证书的别名,应在 \Phar::OPENSSL 签名设置中。
- stub - 模块的别名,如果为 false 则不会设置。
组件
组件 - 对 Phar 归档中文件进行修改的 PHP 类。组件配置类似于 yii 应用程序组件,例如
return [ 'modules' => [ 'phar' => [ 'class' => 'index0h\\phar\\Module', 'components' => [ 'fixer' => [ 'class' => 'index0h\\phar\\components\\php\\Fixer', 'match' => '/.*\.php/' ] ] ] ... ], ... ];
可用组件
Fixer
Fixer 修改了在 Phar 中不工作的文件中的 realpath 函数。
- match - 必须修改的文件的正则表达式列表。
- replace - 用于文件修改的 [from] => [to] 正则表达式数组。
Minimize
使用 php_strip_whitespace 从 PHP 文件中删除所有空白字符。
- match - 必须修改的文件的正则表达式列表。
编写自己的组件
只需创建一个扩展 index0h\phar\base\Component 并实现 processFile 方法的类。
例如最小化组件
namespace index0h\phar\components\php; use index0h\phar\base\Component; use index0h\phar\base\FileEvent; /** * Removes whitespace and comments from php files. */ class Minimize extends Component { /** * For all php files without suffix Controller (because help command parses comments). */ protected $match = ['/(?<!Controller)\.php/us']; /** * Modification of file. * * @param FileEvent $event Event with file information. */ public function processFile(FileEvent $event) { file_put_contents($event->realPath, php_strip_whitespace($event->realPath)); } }
FileEvent 结构
- realPath - 临时文件的路径。
- relativePath - Phar 文件中的路径。
测试
从 IDE 运行测试(以 PhpStorm 为例)
- 选择“运行/调试配置” -> “编辑配置”
- 选择“添加新配置” -> “PHP 脚本”
- 类型
- 文件:/path/to/yii2-phar/.test.php
- 运行参数:run --coverage --html
- OK
从IDE运行测试(以PhpStorm为例)在phar存档内
- 选择“运行/调试配置” -> “编辑配置”
- 选择“添加新配置” -> “PHP 脚本”
- 类型
- 文件:/path/to/yii2-phar/.test.phar.php
- 运行参数:run --no-exit
- OK
从控制台运行测试
make test-all