kael-shipman / philer
Requires
- ext-mbstring: *
- kael-shipman/php-executables: ~0.5.0
- laktak/hjson: ^2.0.0
- nategood/commando: ~0.2.9
README
Philer 是又一个尝试简化 phar 编译器的项目。我前几天需要自己制作第一个 phar 文件,于是开始研究如何实现。我发现了一些库,但它们都涉及到奇怪的 PHP 构建文件等。
我决定借鉴 Composer,将此编译器基于包根目录中的 json(实际上是 hjson)配置文件实现,该文件名为 philer.hjson
,用于定义如何创建 phar。
(项目名称来自 PHar CompILER。)
使用方法
使用方法非常简单。只需创建您的配置文件,然后从您仓库的根目录执行 philer compile
。根据您的配置,这将将一个或多个 phar 文件放入您选择的构建目录。
安装
我坚信对于工作来说,选择正确的包管理器非常重要,并且由于这个编译器打算作为系统级可执行文件,所以正确的包管理器就是您的操作系统提供的(apt、yum、brew 等)。
但是,到目前为止,我唯一制作的操作系统包是 deb 包,您可以从我的 包仓库 获取。对于其他操作系统,您可以直接下载构建好的 phar(通过 GitHub 发布页面或直接从本仓库下载 build/philer
)并将其放置在您的路径中。
技术上,您也可以通过 Composer(它会在 vendor/bin/philer
中出现)按项目安装它。这很酷,但我更喜欢全局二进制。
从源代码编译
可以从源代码编译 philer
,只需从仓库根目录运行 composer install && php ./src/bootstrap.php compile
即可。
配置
配置文件都是一样的,无论是全局的还是局部的。如上所述,所有配置文件都使用 hjson 编写,并且应该以 .hjson
结尾。然而,hjson 与 json 兼容,因此如果您愿意,可以像使用普通 json 一样编写它们。
配置文件位于以下位置
/etc/philer/config.hjson
-- 可选的机器全局配置,适用于全局忽略等。/etc/philer/config.d/
-- 可选的机器全局配置片段(按字母顺序排列)/home/$USER/.config/philer/config.hjson
-- 可选的用户特定配置$REPO/philer.hjson
-- 必要的主要配置文件
最终配置是通过将以下所有配置从 4 合并到 1,其中配置值 4 覆盖 3 中的值等。
以下是一个示例配置文件,应该可以给您提供一个如何使用此系统的概念
{
// Debug levels go from 1 (Emergency) to 7 (Debug)
log-level: 7
// log-identifier is the string that shows up in your syslog file. You won't normally
// set this yourself, though some crazies might like to just to assert their authority
// over their machines.
log-identifier: Philer
// Items in the ignore list follow standard globbing. However, NEGATION IS NOT SUPPORTED
ignore: [
*.git*
*test*
*/docs/*
*.sw[op]
]
// Files in the "optional" list won't throw errors if they're specified in executable
// profiles, but aren't found in the project. (This isn't very useful, but is there
// just in case.)
optional: [
config-defaults.local.php
]
// The `executables` key holds an array of specifications for building executables.
// Each executable spec has a name, a bootstrap file, and a phar-spec that defines
// which files exist in the phar and what their sources are in the project folder.
executables: [
{
// The name of the executable
name: my-app
// The bootstrap file (this is called by the phar stub to kick off the executable)
bootstrap-file: src/bootstrap-main.php
// Keys are paths within the phar, while values are paths in the filesystem. (Paths
// in `values` are copied to the path `key` in the phar archive.)
phar-spec: {
src: src
vendor: vendor
config-defaults.php: configs/main-defaults.php
config-defaults.local.php: config-defaults.local.php
}
}
{
name: my-app-debug
bootstrap-file: src/bootstrap-debug.php
phar-spec: {
src: src
vendor: vendor
config-defaults.php: configs/debug-defaults.php
config-defaults.local.php: config-debug-defaults.local.php
}
// You can have `optional` and `ignore` keys in executable specifications, too
optional: [
config-debug-defaults.local.php
]
}
]
}
以下是演示配置键的简要说明
- 日志级别: 一个整数级别(0-7),对应于您想要记录的syslog严重性级别。7(
LOG_DEBUG
)的值记录一切,而0(LOG_EMERG
)的值仅记录最严重的事件(在philer
的情况下没有)。默认值: 3(LOG_ERR
) - 日志标识符: philer日志文件中显示的名称。(您更改它的理由不多;这只是为那些非常挑剔的人提供的。)默认值:
Philer
。 - 忽略: 要忽略的模式的数组(适用于标准shell通配符)
- 可选: 定义可选文件的数组(也适用于标准shell通配符)。这实际上只是为了那些像上面演示的情况,您可能希望允许构建者使用可选的自定义编译时配置或类似情况。
- 可执行文件: 包含以下子配置的可执行规格数组
- 名称: 编译后可执行文件的最后名称
- 引导文件: 启动您的可执行文件的文件路径(在phar内部)(相当于
index.php
文件) - phar规范: phar路径到源路径的映射。(应按以下方式阅读:“这个phar文件来自那个源文件。”)
待办事项
- 实现至少部分配置的命令行选项覆盖。
- 源级文档
- 操作系统软件包