Console (CLI)

Application Command Line Interface (CLI)

CLI stands for Command Line Interface. CLI applications are executed from the command line or a shell prompt. One of the benefits of CLI applications is that they do not have a view layer (only potentially echoing output on screen) and can be run more than one at a time. Some of the common usages are cron job tasks, manipulation scripts, import data scripts, command utilities and more.

Requirements

You must use the Zemit CLI. If it doesn't exist, create a new file named zemit with the following content

#!/usr/bin/env php
<?php
use App\Bootstrap;

$loader = require 'loader.php';
echo (new Bootstrap('cli'))->run();

You must allow execution

# Add execution permission to the Zemit CLI bootstrap.
chmod +x ./zemit

Usage

# Basic usage
./zemit <module> <task> <action> <params>

# Advanced usage
./zemit <module> <task> [<action>] [--help | --quiet | --verbose] [--debug] [--format=<format>] [<params>...]
./zemit (-h | --help)
./zemit (-v | --version)
./zemit (-i | --info)

Options:
  -h --help               show this help message
  -v --version            print version number
  -i --info               print information
  -q --quiet              suppress output
  -V --verbose            increase verbosity
  -d --debug              enable debug mode
  --format=<format>       change output returned value format (json, xml, serialized, raw, dump)

We add the console service in the di so you can access it whenever you need it.

// if the class is aware of injections
$console = $this->console;

// if the container is present
$console = $this->di->get('console');

// from outside
$console = Di::getDefault()->get('console');

API References

Phalcon\Cli

Zemit\Cli

Sources

Last updated