简体   繁体   English

分发php命令行工具

[英]distributing a php command line tool

I have a php command line tool that I would like to share with the world. 我有一个php命令行工具,我想与世界分享。 Well, actually I plan to write it, and it is a tool for loading design documents into couchdb, but that's not really the point. 好吧,实际上我打算写它,它是一个将设计文档加载到couchdb的工具,但这不是重点。

Anyway, is there a best practice for packaging php scripts so that they can be distributed for easy installation? 无论如何,是否有最佳实践来打包php脚本,以便分发它们以便于安装? I'm thinking something along the lines of the good old "./configure & make & make install", but what to do for a php script? 我正在思考好旧的“./configure&make&make install”,但是如何处理php脚本呢? I have read about phar, but it seems that it is intended mainly for libraries. 我读过有关phar的内容,但它似乎主要用于库。 So any ideas? 那么任何想法? Or examples of how other projects have done this? 或其他项目如何做到这一点的例子?

Composer is a good example of how to package up the tool, both as a stand-alone set of source code, and code that can be run. Composer是如何打包工具的一个很好的例子,既可以作为独立的源代码集,也可以作为可以运行的代码。 I installed it as a phar and now can just run it anywhere as ' composer --options args ' 我安装它作为一个phar,现在可以在任何地方运行它作为' composer --options args '

There's composer or the good old PEAR that's still widely used, especially for CLI tools. 还有作曲家或仍然广泛使用的好老PEAR ,特别是对于CLI工具。 To create your own PEAR channel, Pirum by SensioLabs (the Symfony guys) comes in handy. 为了创建自己的PEAR频道, SensioLabs (Symfony人)的Pirum派上用场。

For further reading, Stuart Herbert has a great series on component based development . 为了进一步阅读,Stuart Herbert 在基于组件的开发方面有很多系列

Check out CLIFramework it handles subcommands, argument validation, option values (multiple, flag, optional, default) and a powerful zsh/bash completion generator. 查看CLIFramework它处理子命令,参数验证,选项值(多个,标志,可选,默认)和强大的zsh / bash完成生成器。

A compile command is also out-of-box to help you compile your console application into a phar file for distributing. 编译命令也是开箱即用的,可帮助您将控制台应用程序编译为phar文件以进行分发。 (phpbrew uses this way to distribute the application to the world) (phpbrew使用这种方式将应用程序分发给世界)

Here is a screencast of using zsh completion generator (it completes arguments and options): 这是一个使用zsh完成生成器的截屏视图(它完成了参数和选项):

zsh完成生成器

There are also many popular applications using CLIFramework and GetOptionKit. 使用CLIFramework和GetOptionKit也有许多流行的应用程序。 eg, PHPBrew , LazyRecord 例如, PHPBrewLazyRecord

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM