Turn any PHP class into cli application

July 4, 2019, 9:15 p.m.

How to turn any PHP class into cli commands without writing a line of code? Use cli-maker and you won't have to write any additional code, just simple config array.

Cli-maker is powerful and easy to use library that allows you to generate cli commands from given PHP classes. Before we move forward you must be aware that cli-maker works only with PHP 7 and above.


composer require wilgucki/cli-maker


On the root level of your application create cli-maker.php file. Future version of this library will allow you to choose location of this file.

Add all class names you want to access from command line into this file. Currently library requires all class names to be unique (even if classes are using different namespaces). This will change in future version.

// cli-maker.php

return [

To list all available commands run

./vendor/bin/cli-maker .

To run single command simply add it after cli-maker script.

./vendor/bin/cli-maker foo:bar

If converted method accepts parameters, you can add them in the same order as they were defined in your method. If you want to check those parameters you can use --help option.

./vendor/bin/cli-maker foo:bar --help