imanghafoori/php-search-replace
Composer 安装命令:
composer require imanghafoori/php-search-replace
包简介
Smart search replace functionality for php source code
关键字:
README 文档
README
It is much easier than using regex.
Installation:
composer require imanghafoori/php-search-replace
Usage:
1- Lets say you want to remove double semi-colon occurances like these:
$user = 1;; $user = 2; ; $user = 3; ;
Then you can define a pattern like this:
$pattern = [';;' => ['replace' => ';']];
This will catch all the 3 cases above since the neutral php whitespaces are ignored while searching.
Placeholders:
Here is a copmerehensive list of placeholders you can use:
<var>or<variable>: for variables like:$user<str>or<string>: for hard coded strings:'hello'or "hello"<class_ref>: for class references:\App\User::where(...,User::where<full_class_ref>: only for full references:\App\User::<until>: to capture all the code until you reach a certain character.<comment>: for commands (does not capture doc-blocks)<doc_block>: for doc-blocks<statement>: to capture a whole php statement."<name:nam1,nam2>"or<name>: for method or function names.->whereor::where<white_space>: for whitespace blocks<not_whitespace>: for non-whitespace<bool>or'<boolean>': for true or false (acts case-insensetive)<number>: for numeric values<cast>: for type-casts like:(array) $a;<int>or<integer>: for integer values<visibility>: for public, protected, private<float>: for floating point number"<global_func_call:func1,func2>": to detect global function calls.<in_between>: to capture code within a pair of{...}or(...)or[...]<any>: captures any token.- You can also define your own keywords if needed!
You just define a class for your new keyword and append the class path to the end of Finder::$keywords[] = MyKeyword::class property.
Just like the default keywords.
Example:
lets say you want to remove the optional comma from arrays:
$a = [ '1', '2', ]; $b = ['1','2',];
Then you can define a pattern like this:
$pattern = [',<whitespace>?]' => ['replace' => '"<1>"]']];
Here the <whitespace>? mean an optional whitespace may reside there, and the "<1>" means the value that matches the first placeholder should be put there.
imanghafoori/php-search-replace 适用场景与选型建议
imanghafoori/php-search-replace 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 516.4k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2021 年 07 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php-search-replace」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 imanghafoori/php-search-replace 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imanghafoori/php-search-replace 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 516.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 32
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-28