20

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 documentation (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?

5
  • 1
    what about no framework at all. Commented Aug 25, 2011 at 20:17
  • 3
    Framework to do what? You've walked into a hardware store and told the clerk "I need a tool" - not very helpful. Commented Aug 25, 2011 at 20:18
  • Maybe you should look for one by searching after features. Albeit I couldn't think of anything CLI-esque apart from getopt handling and path/exec wrappers. Commented Aug 25, 2011 at 20:21
  • "but I don't know if it's too generic"... well, a framework is generic... Commented Aug 25, 2011 at 20:27
  • 1
    I think it's not a bad idea to use a micro-framework for a CLI task, just to have a well organized code (kind of standardized). I'm talking about a micro-framework, and not about a complete framework. Of course I can go on without it, but I think some reasons that are good for choosing to go on with a framework in a web based applications are valid for a CLI based application: debugging ready, code readability, clean design... Commented Aug 25, 2011 at 21:56

8 Answers 8

19

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hei, that's perfect. Exactly it is what I was looking for. Thank you, Devin.
Symfony is hardly a micro-framework, if anything it's a gargantuan-framework with over 30,000 lines of PHP line-count.herokuapp.com/symfony/Console
7

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

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

1 Comment

That as well look promising :), even if it seems more a library helper than a framework
6

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.

2 Comments

Yes, the best one I know. And it includes the Symfony Console component... For me the best answer.
Aren't there many deployment tool so that you don't need your deployment scripts... But for all other scripts I think its a good choice.
3

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

1 Comment

The command line tool Artisan is as far as I know nothing more than a Cilex. Or better it based on the same Symfony components like Cilex and behaves the same. Cilex is nearly the standalone Artisan Project.
3

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.

zsh completion generator

Comments

1

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.

Comments

1

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.

Comments

1

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

3 Comments

o, I haven't tried it. Finally I chose the Symfony2 Console Component and it was quite good. But thanks for this alternative.
The link no longer works, seems like the project died.
Yes. It seems to be dead now. I couldn't find any repo for it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.