jchook/phpp
Composer 安装命令:
composer require jchook/phpp
包简介
PHP Pre-processor that enables C-like #include directives
README 文档
README
Write PHP templates with #include directives similar to those processed by
the C preprocessor.
Also optionally evaluates <?php ?> blocks.
Install
If you want to use composer:
composer require-dev jchook/phpp
or download the phar and include it in your project
Example
Make a file that can contain cpp-like #include directives and/or PHP templating.
Dockerfile.in
FROM alpine:3.14 #include "php.dockerfile" #include "runit.dockerfile"
Then run the script to build it, similar to cpp.
phpp -o Dockerfile Dockerfile.in
Command-Line Usage
USAGE
phpp [options] PATH...
OPTIONS
-h, --help Show this help info
-o PATH Output processed file to PATH. (multi)
-I PATH Look here for included files (multi)
--ext Look for files with this extension (multi)
--eval Evaluate PHP in included files
-v Verbose mode
Options labeled (multi) can be invoked multiple times.
PHP Interface
See the source code for more info. Here's a simple example:
<?php use Jchook\Phpp\Preprocessor; $pre = new Preprocessor(); $pre->makeFile('Dockerfile.in');
Motivation
Dockerfiles do not allow you to INCLUDE other Dockerfiles. This is a
known and embraced limitation.
Folks have suggested using cpp to translate #include directives, but this has critical issues:
- Cannot use normal # comments, as ccp will throw an error
- The cpp manual warns against using it for non-C code
This tool leverages PHP (a powerful, turing-complete templating language) to provide a complete templating solution with a familiar #include shortcut.
Why not use plain ol' PHP?
Consider these two examples in a Dockerfile side-by-side:
# PHP include: #<?php include __DIR__ . '/thing.dockerfile' ?> # CPP-like include #include "thing.dockerfile"
Using "just PHP" presents some awkward quirks:
-
Ideally you can comment out the include line to avoid raising syntax errors or strange highlighting issues in your code editors / IDE.
-
Commenting out the include line means the first line of the included file is commented out.
-
No automatic paper trail showing which code came from which include in the output file(s).
-
More cumbersome syntax, requiring more explicit include paths.
Caveat
If your Dockerfile or similar code contains the string <?php you PHP will
interpret that. If you do not want this behavior, be sure to escape at least
one of the characters or disable eval mode.
jchook/phpp 适用场景与选型建议
jchook/phpp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 08 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jchook/phpp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jchook/phpp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-28