开发者

PHP cli micro-framework?

I want to program a little CLI script in PHP, basically with two possible arguments to do two different things. Very easy. But I would like to do in an elegant way.

I was wondering if it exists some PHP micro-framework functionaly in CLI mode (note that I say micro-framework and not framework). I want to use PHP because I'll include some PHP already programmed classes.

I have found CLImax, that is an specific CLI micro-framework and seems good, but it lacks a good documentation.

Do you know any place where I can found a good CLImax documentatio开发者_StackOverflow中文版n (I haven't found anything, but its source code poorly documented)?

Or maybe do you know another option? Alloy seems as well a lightweight PHP framework, and has CLI "mode", but I don't know if it's too generic, as it's as well for web servers. Have you used it?


Check out the Symfony Console component. Here's an introduction to using it. It may take a little bit of work to get it to function with an older version of PHP (without namespaces), and you need a couple other components from Symfony, but I've used it quite successfully.


I've found this one: php-cli-tools

It's definitely micro and brings everything you'd have with sh or windows batch.


It doesn't have great documentation from what I can see, but Cilex describes itself as:-

"a lightweight framework for creating PHP CLI scripts inspired by Silex"

Might be worth a look, I am thinking of using it myself to replace the bash deployment scripts I have written.


Laravel has a command line tool called Artisan which it allows you to extend quite easily;

Artisan is the name of the command-line interface included with Laravel.... [Artisan Development] In addition to the commands provided with Artisan, you may also build your own custom commands for working with your application.

See the documentation for Artisan development here


Check out https://github.com/c9s/CLIFramework

CLIFramework is a full-stack framework for command-line tools, unlike Symfony/Console, it has a concise API for building lightweight command-line application.

It allows you to define few options and argument info to generate a help document rapidly.

The most important part is that CLIFramework can generate zsh completion script automatically, so you don't need to write zsh script for every command line application.

PHP cli micro-framework?


You might be interested in my php cli framework: https://github.com/b-b3rn4rd/Terminalor Terminalor - is a php library for creating portable php cli files. It provides essential functionality to work under cli interface and can be used as a wrapper for external libraries. It allows rapidly create documented cli commands with arguments using closures and phpdoc comments. Later this commands can be compiled into single independent portable file.


I don' think many of the suggestions above are micro-frameworks - even though many of the suggestions are great frameworks - and properbly better in many use-cases than my suggestion: https://github.com/diversen/minimal-cli-framework

It is much faster than the above frameworks (though it is rare that you need speed from a CLI-framework). It lets you add sub-commands using class objects. It generates help and command-definitions from a single method. You will only need to implement two methods to an existing class to use it with the minimal-cli-framework (getCommand - definition of the command and runCommand - the execution of the command).

Disclaminer: I wrote the package.


Did you try Seagull? It looks like it too natively supports projects that are specifically meant to be used in the CLI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜