SwatObject
└─SiteObject
└─SiteApplication
└─SiteCommandLineApplication
public abstract class SiteCommandLineApplication
extends SiteApplication
| Field Summary | |
|---|---|
| final mixed | Verbosity level for showing all actions. |
| final mixed | Verbosity level for showing error messages. |
| final mixed | Verbosity level for showing nothing. |
| protected array | An array of SiteCommandLineArgument objects used by this application. |
| protected string | Text describing the purpose of this application. |
| protected resource | The opened lock file. |
| protected string | The title of this application. |
| protected integer | The level of verbosity to use. |
| Fields inherited from Site.SiteApplication | |
|---|---|
| VAR_COOKIE, VAR_ENV, VAR_FILES, VAR_GET, VAR_POST, VAR_REQUEST, VAR_SERVER, VAR_SESSION, default_time_zone, id, locale, modules, modules_by_provides | |
| Constructor Summary | |
|---|---|
SiteCommandLineApplication(string id, string config_filename, string title, string documentation) Creates a new command line application. |
|
| Method Summary | |
|---|---|
| void | addCommandLineArgument(SiteCommandLineArgument argument) Adds a command line argument to this application. |
| protected void | debug(string string, boolean bold) Displays output at the verbosity level SiteCommandLineApplication::VERBOSITY_ALL. |
| void | displayArgumentUsage(SiteCommandLineArgument argument) Displays usage information for a single command line argument. |
| void | Displays usage information for this command line application. |
| protected void | error(string string, boolean bold) Displays output at the verbosity level SiteCommandLineApplication::VERBOSITY_ERRORS. |
| protected void | |
| string | Gets an absolute path to the directory in which the currently running script resides. |
| protected void | lock() Locks this application, preventing more than one instance from running. |
| protected void | output(string string, integer verbosity, boolean bold) Displays a string based on the verbosity level of this application. |
| protected void | Automatically parses and interprets command line arguments of this application. |
| void | setApplicationDirectory(string directory) Sets the application directory. |
| void | setVerbosity(integer verbosity) Sets the level of verbosity to use for this application. |
| protected void | terminate(string string, integer verbosity, integer error_code) Terminates this application and displays the specified error message. |
| protected void | unlock() Unlocks this application, allowing more than one instance to run. |
| Methods inherited from Site.SiteApplication | |
|---|---|
| addConfigDefinitions, addDefaultModule, addDefaultModules, addModule, configure, configureErrorHandling, getCountry, getDefaultModuleList, getInstance, getInstanceId, getLocale, getModule, hasModule, initModules, initVar, postInitConfigure, run | |
public final mixed VERBOSITY_ALL = 2
Verbosity level for showing all actions
public final mixed VERBOSITY_ERRORS = 1
Verbosity level for showing error messages.
public final mixed $VERBOSITY_NONE
Verbosity level for showing nothing.
protected array $arguments = array()
An array of SiteCommandLineArgument objects used by this
application
protected string $documentation
Text describing the purpose of this application
This is displayed in usage information.
protected resource $lock_file
The opened lock file
protected string $title
The title of this application
The title is displayed in error messages and in usage information.
protected integer $verbosity
The level of verbosity to use
This controls the output of SiteCommandLineApplication::output().
public SiteCommandLineApplication(string id, string config_filename, string title, string documentation)
Creates a new command line application
By default, the 'help' and 'verbosity' command line arguments are added. This 'help' argument is set to display usage information and the 'verbosity' argument sets the level of debug output.
id - a unique identifier for this application.config_filename - the filename of the configuration file. If specified as null, no configuration module is created and no special configuration is performed.title - the title of this application.documentation - optional text describing the purpose of this application.public void addCommandLineArgument(SiteCommandLineArgument argument)
Adds a command line argument to this application
Command line arguments may be added either when the class is used or in the class definition.
For example, to create a command line argument accepting either '-f' or '--foo' that runs the foo() method, use the following:
<?php
$foo_argument = new SiteCommandLineArgument(array('-f', '--foo'), 'foo',
'Runs the foo() method.');
$app->addCommandLineArgument($foo_argument);
?>
argument - the command line argument to add.protected void debug(string string, boolean bold)
Displays output at the verbosity level
SiteCommandLineApplication::VERBOSITY_ALL
string - the string to display.bold - optional. Whether or not to display the string using a bold font on supported terminals. Defaults to false.public void displayArgumentUsage(SiteCommandLineArgument argument)
Displays usage information for a single command line argument
argument - the command line argument for which to display usage information.public void displayUsage()
Displays usage information for this command line application
protected void error(string string, boolean bold)
Displays output at the verbosity level
SiteCommandLineApplication::VERBOSITY_ERRORS
string - the string to display.bold - optional. Whether or not to display the string using a bold font on supported terminals. Defaults to false.protected void getLockFilename()
public string getScriptDirectory()
Gets an absolute path to the directory in which the currently running script resides
protected void lock()
Locks this application, preventing more than one instance from running
protected void output(string string, integer verbosity, boolean bold)
Displays a string based on the verbosity level of this application
string - the string to display.verbosity - the verbosity level to display at. If this application's verbosity is less than this level, the string is not displayed.bold - optional. Whether or not to display the string using a bold font on supported terminals. Defaults to false.protected void parseCommandLineArguments()
Automatically parses and interprets command line arguments of this application
public void setApplicationDirectory(string directory)
Sets the application directory
directory - the directory to use.public void setVerbosity(integer verbosity)
Sets the level of verbosity to use for this application
verbosity - the level of verbosity to use.protected void terminate(string string, integer verbosity, integer error_code)
Terminates this application and displays the specified error message
Program execution ceases after this method is run. Code present in object destructors will still run.
string - the string to dipslay.verbosity - optional. the verbosity level to display at. If this application's verbosity is less than this level, the string is not displayed. Defaults to {@link SiteCommandLineApplication::VERBOSITY_ERRORS}.error_code - optional. The error code with which to terminate execution. If not specified, 1 is used.protected void unlock()
Unlocks this application, allowing more than one instance to run
An application designed to run on the command line
This class handles the creating and parsing of command line arguments and has the ability to display usage information.
Command line applications must implement the
SiteApplication::run()method.