Skip to content

Command Autoloading

Yo-An Lin edited this page Jul 13, 2015 · 8 revisions

CLIFramework let you register your commands in the init method. However, if you have many commands, and some commands are from elsewhere, e.g. external packages. You might want to take a look at the command autoloading feature.

Command autoloading let you not to write command registration code. It scans the files under a specific namespace directory, translate class names into command names and register them to their parent command automatically.

To enable command autoloading, simply add a property protected $commandAutoloadEnabled; in your CLIFramework\Application class:

namespace MyApp;
use CLIFramework\Application;
class Console extends Application {
    protected $commandAutoloadEnabled = true;
}

Then the init method from CLIFramework\Application will work for you, here is the init method in CLIFramework\Application:

    public function init()
    {
        if ($this->isCommandAutoloadEnabled())
            $this->autoloadCommands();
    }

There are two methods you can change the property, they are:

$app->enableCommandAutoload();
$app->disableCommandAutoload();
Clone this wiki locally