net_bazzline/php_component_command
Composer 安装命令:
composer require net_bazzline/php_component_command
包简介
free as in freedom php component command is a thin and generic wrapper to easy up using system (shell) command usage
关键字:
README 文档
README
This free as in freedom project aims to deliver a easy to use php command component.
The build status of the current master branch is tracked by Travis CI:
Take a look on openhub.net.
The current change log can be found here.
Usage
You can find a lot of examples here.
class Zip extends Command { /** * @param string $archiveName * @param array $items * @return array * @throws RuntimeException */ public function __invoke($archiveName, array $items) { return $this->zip($archiveName, $items); } /** * @param string $archiveName * @param array $items * @return array * @throws RuntimeException * @todo implement parameter validation */ public function zip($archiveName, array $items) { $command = '/usr/bin/zip -r ' . $archiveName . ' ' . implode(' ' , $items); return $this->execute($command); } /** * @param string $pathToArchive * @param null|string $outputPath * @return array * @throws RuntimeException * @todo implement parameter validation */ public function unzip($pathToArchive, $outputPath = null) { if (!is_null($outputPath)) { $command = '/usr/bin/unzip ' . $pathToArchive . ' -d ' . $outputPath; } else { $command = '/usr/bin/unzip ' . $pathToArchive; } return $this->execute($command); } /** * @param string $pathToArchive * @return array * @throws RuntimeException * @todo implement parameter validation */ public function listContent($pathToArchive) { $command = '/usr/bin/unzip -l ' . $pathToArchive; return $this->execute($command); } /** * @throws InvalidSystemEnvironmentException */ public function validateSystemEnvironment() { if (!is_executable('/usr/bin/zip')) { throw new InvalidSystemEnvironmentException( '/usr/bin/zip is mandatory' ); } if (!is_executable('/usr/bin/unzip')) { throw new InvalidSystemEnvironmentException( '/usr/bin/unzip is mandatory' ); } } } $zip = new Zip(); $pathToZipArchive = '/tmp/my.zip'; $zip->validateSystemEnvironment(); echo 'list archive content' . PHP_EOL; $lines = $zip->listContent($pathToZipArchive); foreach ($lines as $line) { echo $line . PHP_EOL; } echo 'unzip archive' . PHP_EOL; $zip->unzip($pathToZipArchive, '/tmp/my_directory'); echo 'zip directory' . PHP_EOL; //also valid call since we implemented __invoke //$zip($pathToZipArchive, array('/tmp/my_directory')); $zip->zip($pathToZipArchive, array('/tmp/my_directory'));
Install
By Hand
mkdir -p vendor/net_bazzline/php_component_command
cd vendor/net_bazzline/php_component_command
git clone https://github.com/bazzline/php_component_command .
With Composer
composer require net_bazzline/php_component_command:dev-master
Benefits
- easy and robust way of dealing with system commands
- return value validation by using exceptions
- hopefully the thinnest possible layer between system commands
API
API is available at bazzline.net.
Final Words
Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it :-D.
net_bazzline/php_component_command 适用场景与选型建议
net_bazzline/php_component_command 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.07k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「command」 「shell」 「wrapper」 「component」 「job」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 net_bazzline/php_component_command 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 net_bazzline/php_component_command 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 net_bazzline/php_component_command 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Shell command module for PHP.
PHP library for the MUMSYS project
Library with classes to help you do batch.
统计信息
- 总下载量: 10.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 25
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2014-12-11