Revision: Fri, 31 May 2024 16:10:39 GMT
v1.0 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.12
Edit this page

Custom Commands

You can add any custom commands to your own application or even module by simply making sure that command class can be loaded (i.e. located in tokenizer directories) and then executeconsole:reload to find and index your command.

You can also add command manually into your console config.

To generate blank command execute create:command name (spiral/scaffolder module is required), as result following class will be created for us (based on scaffolder settings):

class SomeCommand extends Command
    const NAME        = 'some';
    const DESCRIPTION = '';

    const ATTRIBUTES = [];
    const OPTIONS    = [];

     * Perform command
    protected function perform()

You would still be able to use native Symfony commands.

Arguments and Options

Spiral's Command class makes easy to define needed arguments and options:

const ARGUMENTS = [
    ['argument', InputArgument::REQUIRED, 'Argument name.']
const OPTIONS = [
    ['option', 'c', InputOption::VALUE_NONE, 'Some option.']

Perform method are executed using Container and support method injection.

To get user's data via arguments and/or options, you can make use of $this->argument("argName") or $this->option("optName").