Source for file cli.php
Documentation is available at cli.php
* @package Joomla.Platform
* @subpackage Application
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Base class for a Joomla! command line application.
* @package Joomla.Platform
* @subpackage Application
* @var JRegistry The application configuration object.
* @var JApplicationCli The application instance.
protected static $instance;
* @param mixed $input An optional argument to provide dependency injection for the application's
* input object. If the argument is a JInputCli object that object will become
* the application's input object, otherwise a default input object is created.
* @param mixed $config An optional argument to provide dependency injection for the application's
* config object. If the argument is a JRegistry object that object will become
* the application's config object, otherwise a default config object is created.
* @param mixed $dispatcher An optional argument to provide dependency injection for the application's
* event dispatcher. If the argument is a JEventDispatcher object that object will become
* the application's event dispatcher, if it is null then the default event dispatcher
* will be created based on the application's loadDispatcher() method.
* @see JApplicationBase::loadDispatcher()
public function __construct(JInputCli $input =
null, JRegistry $config =
null, JEventDispatcher $dispatcher =
null)
// Close the application if we are not executed from the command line.
// @codeCoverageIgnoreStart
if (!defined('STDOUT') ||
!defined('STDIN') ||
!isset
($_SERVER['argv']))
// @codeCoverageIgnoreEnd
// If a input object is given use it.
// Create the input based on the application logic.
$this->input =
new JInputCLI;
// If a config object is given use it.
// Instantiate a new configuration object.
// Load the configuration object.
// Set the execution datetime and timestamp;
$this->set('execution.datetime', gmdate('Y-m-d H:i:s'));
$this->set('execution.timestamp', time());
// Set the current directory.
* Returns a property of the object or the default value if the property is not set.
* @param string $key The name of the property.
* @param mixed $default The default value (optional) if none is set.
* @return mixed The value of the configuration.
public function get($key, $default =
null)
* Returns a reference to the global JApplicationCli object, only creating it if it doesn't already exist.
* This method must be invoked as: $cli = JApplicationCli::getInstance();
* @param string $name The name (optional) of the JApplicationCli class to instantiate.
* @return JApplicationCli
// Only create the object if it doesn't exist.
if (empty(self::$instance))
if (class_exists($name) &&
(is_subclass_of($name, 'JApplicationCli')))
self::$instance =
new $name;
self::$instance =
new JApplicationCli;
* Execute the application.
// Trigger the onBeforeExecute event.
// Perform application routines.
// Trigger the onAfterExecute event.
* Load an object or array into the application configuration object.
* @param mixed $data Either an array or object to be loaded into the configuration object.
* @return JApplicationCli Instance of $this to allow chaining.
// Load the data into the configuration object.
* Write a string to standard output.
* @param string $text The text to display.
* @param boolean $nl True (default) to append a new line at the end of the output string.
* @return JApplicationCli Instance of $this to allow chaining.
public function out($text =
'', $nl =
true)
fwrite(STDOUT, $text .
($nl ?
"\n" :
null));
* Get a value from standard input.
* @return string The input string from standard input.
* Modifies a property of the object, creating it if it does not already exist.
* @param string $key The name of the property.
* @param mixed $value The value of the property to set (optional).
* @return mixed Previous value of the property
public function set($key, $value =
null)
* Method to load a PHP configuration class file based on convention and return the instantiated data object. You
* will extend this method in child classes to provide configuration data from whatever data source is relevant
* for your specific application.
* @param string $file The path and filename of the configuration file. If not provided, configuration.php
* in JPATH_BASE will be used.
* @param string $class The class name to instantiate.
* @return mixed Either an array or object to be loaded into the configuration object.
// Instantiate variables.
if (empty($file) &&
defined('JPATH_BASE'))
// Applications can choose not to have any configuration data
// by not implementing this method and not having a config file.
throw
new RuntimeException('Configuration class does not exist.');
* Method to run the application routines. Most likely you will want to instantiate a controller
* and execute it, or perform some sort of task directly.
// Your application routines go here.
Documentation generated on Tue, 19 Nov 2013 14:55:45 +0100 by phpDocumentor 1.4.3