class \mpf\ConsoleApp

class \mpf\ConsoleApp

Default class used for terminal applications created with MPF Framework. Most of the times this will be used for the cronjobs that are required by the project.

To execute a terminal application you need the following command:

php /path/to/app/folder/php/run.php command action --extraParam=value

The command part represents the class name of an extended \mpf\cli\Command class. They can be find, by default, in php/commands/ folder. Each command can have multiple actions that should be name like this: "actionName" . When this is called only the "name" part is used.

In the example that I used above, it will call the actionAction() method inside the Command class. Also, if the actionAction() method has a parameter with the name $extraParam then it will use "value" for it when calling the method.

More details about this process can be found on the \mpf\cli\Command class description page.

You can run a ConsoleApp similar to any other app:

'startTime' => microtime(true),
'autoload' => $autoload

It will offer access to the same components that \mpf\base\App offers.

public array $commandAliases = {"dev":"\\mpf\\cli\\dev\\Command"}

List of aliases for different commands aliasName => className

public string $commandsNamespace = "commands"

Name of namespace&folder for commands, relative to php folder from the application;

public string $notFoundCommand = "\mpf\cli\NotFound"

Name of the command that will be executed if the called one was not found


protected mixed start ()

This is the main method called when the application is executed.

It will first check for the command arguments and if none are found it will call the not found command.

private string[] getServerArguments ()

Reads and returns a list with all arguments. Return structure:

     'command' => 'COMAND_NAME',
     'action' => 'ACTION_NAME'
     'params' => [

private string[] parseArgs (string[] $args)

  • $args

    -no description found-

Receives a list of strings and extracts the command, action and parameters from that list.

public bool setSignalCallback (int $sigNumber, callable $handler, bool $restart_syscall = true)

  • $sigNumber

    -no description found-

  • $handler

    -no description found-

  • $restart_syscall

    -no description found-

Set a callable method for when a signal it's sent to this process.

public string getCommandClassFromNameAndModule (string $command, string $module)

  • $command

    Name of the command

  • $module

    Name of the module

Returns full namespace and classname for selected command. Command name is modified with ucfirst() method. Also 'app' it's added as a vendor name in namespace and $this->commandsNamespace as part of the namespace. In case of modules, if there are no aliases for selected module then $modulesNamespace it's added and then module name plus $commandsNamespace, in case an alias it's found, then that alias it's used instead of 'app', modulesNamespace and module name .

Examples: Command: home Module : - Result : \app\commands\Home

Command: home Module: admin Result: \app\modules\admin\commands\Home

Command: home Module: chat Alias for chat: outsidevendor\chatModule Result: \outsidevender\chatModule\commands\Home

private \mpf\cli\Command loadCommand (string $class)

  • $class

    -no description found-

Instantiate command and check if class is correct;

A critical error will be generated if it's an invalid class(doesn't extend \mpf\cli\Command)!