winbox/args
Composer 安装命令:
composer require winbox/args
包简介
Windows command-line formatter
README 文档
README
A PHP function to escape command-line arguments, which replaces escapeshellarg with more robust methods for both Windows and non-Windows platforms. Install from Packagist and use it like this:
$escaped = Winbox\Args::escape($argument);
Alternatively, you can just copy the code into your own project (but please keep the license attribution and documentation link).
What it does on the Windows platform
The following transformations are made:
- Double-quotes are escaped with a backslash, with any preceeding backslashes doubled up.
- The argument is only enclosed in double-quotes if it contains whitespace or is empty.
- Trailing backslashes are doubled up if the argument is enclosed in double-quotes.
See How Windows parses the command-line if you would like to know why.
By default, cmd.exe meta characters are also escaped:
- by caret-escaping the transformed argument (if it contains internal double-quotes or
%...%syntax). - or by enclosing the argument in double-quotes.
There are some limitations:
- If cmd is started with DelayedExpansion enabled,
!...!syntax could expand environment variables. - If the program name requires caret-escaping and contains whitespace, cmd will not recognize it.
- If an argument contain a newline
\ncharacter, this will not be escaped.
See How cmd.exe parses a command and Implementing a solution for more information.
What it does on non-Windows platforms
The argument is enclosed is single-quotes, with internal single-quotes escaped.
Is that it?
Yup. An entire repo for a tiny function. However, it needs quite a lot of explanation because:
- the command-line parsing rules in Windows are not immediately obvious.
- PHP generally uses cmd.exe to execute programs and this applies a different set of rules.
- there is no simple solution.
Full details explaining the different parsing rules, potential pitfalls and limitations can be found in the Wiki.
License
Winbox-Args is licensed under the MIT License - see the LICENSE file for details.
winbox/args 适用场景与选型建议
winbox/args 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 719.76k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2016 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「command」 「windows」 「Escape」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 winbox/args 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 winbox/args 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 winbox/args 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Wrapper for exec and it's results
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Symfony bundle to monitor and execute commands
Shell command module for PHP.
Auto escaping plugin for CakePHP
PHP library for using ANSI escape codes in the terminal
统计信息
- 总下载量: 719.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 18
- 依赖项目数: 40
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-04