jkribeiro/composer-hydration
Composer 安装命令:
composer require jkribeiro/composer-hydration
包简介
Provides a Composer script to project skeleton hydration by placeholders replacements.
README 文档
README
composer-hydration
Introduction
composer-hydration is a simple package that provides a Composer Script to be used as placeholder replacement, mostly used by 'skeletons' projects.
Example:
composer run-script hydrate -- --replace={FRUIT}:"apple",{INGREDIENT}:"cinnamon"
The script will search for the placeholders in file content, file names and folders.
Before:
$ /path/composer/project/{FRUIT}.txt
"I love {FRUIT} with {INGREDIENT}, is a good combination!"
After:
$ /path/composer/project/apple.txt
"I love apple with cinnamon, is a good combination!"
Installation
Install Composer
Since composer-hydration is a Composer script, you need to install composer first.
Note: The instructions below refer to the global composer installation. You might need to replace
composerwithphp composer.phar(or similar) for your setup.
Add package dependency
Add composer-hydration as package dependency of your project, updating your composer.json:
"require": {
...
"jkribeiro/composer-hydration": "~1"
}
Define the Composer Script
Define the Composer script, adding this entry to your composer.json:
"scripts": {
"hydrate": "Jkribeiro\\Composer\\ComposerHydration::meatOnBones"
}
Install Project
composer install
Usage
There are some ways that you can execute this script:
Execute the command manually
After have the package installed, you can run the command manually to have your values placed.
composer run-script hydrate -- --replace={SEARCH}:{REPLACE},..."
Hydrate during the Composer Events
Composer fires some events during its execution process, useful to define on which step/event it will perform the hydration process.
In the example below, the hydration process will occur after the project installation:
"scripts": {
"hydrate": "Jkribeiro\\Composer\\ComposerHydration::meatOnBones",
"post-install-cmd": "@composer run-script hydrate -- --replace={{PROJECT_NAMESPACE}}:{%BASENAME%}"
}
Variables as Replacement values
Sometimes we need to use dynamic replacement values on composer.json, not only hardcoded values like {FRUIT}:banana, for these cases, there are two possibilities:
Environment Variables
composer.json allows environment variables as replacement placeholder value, like {{PROJECT_NAMESPACE}}:$PROJECT_NAME", $PROJECT_NAME is the variable name. You must define the variables before execute the Composer commands.
Example:
composer.json
...
"scripts": {
"hydrate": "Jkribeiro\\Composer\\ComposerHydration::meatOnBones",
"post-install-cmd": "@composer run-script hydrate -- --replace={{PROJECT_NAMESPACE}}:$PROJECT_NAME"
}
Execution
$ export PROJECT_NAME="My Project"
$ composer install
"Magic Constants"
Using the same idea of PHP Magic constants, composer-hydration provides some Magic constants too.
-
{%BASENAME%}: Returns the base folder name where the script is being executed, normally is the name of the project. -
{%UCFIRST_BASENAME%}: Returns the base folder name with the first character capitalized. -
{%UPPER_CAMEL_CASE_BASENAME%},{%LOWER_CAMEL_CASE_BASENAME%}: Returns the base folder name using the upper/lower camel case format. Only the folder name separators '-', '_' are allowed.Example:
$ ~/Projects/myproject: composer run-script hydrate -- --replace={{PROJECT_NAMESPACE}}:{%BASENAME%}"Placeholders with
{{PROJECT_NAMESPACE}}will be replaced bymyproject.
jkribeiro/composer-hydration 适用场景与选型建议
jkribeiro/composer-hydration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 245.07k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 06 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「placeholder」 「scaffold」 「skel」 「replace」 「wildcard」 「hydrate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jkribeiro/composer-hydration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jkribeiro/composer-hydration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jkribeiro/composer-hydration 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Extend Laravel's generators scaffold.
A plugin which generates an invisible SVG of specific dimensions for use when lazyloading images in Craft CMS templates.
Provides a Composer script to project skeleton hydration by placeholders replacements.
Module for ProcessWire which automatically generates Blurhashs.
Allows you to defined CMS form structure via config.yml
The PDO wrapper with comfortable API for placeholders
统计信息
- 总下载量: 245.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-22