10 defined(
'JPATH_PLATFORM') or die;
54 if (!defined(
'STDOUT') || !defined(
'STDIN') || !isset($_SERVER[
'argv']))
61 if ($input instanceof
JInput)
63 $this->input = $input;
68 if (class_exists(
'JInput'))
70 $this->input =
new JInputCLI;
77 $this->config = $config;
82 $this->config =
new JRegistry;
85 $this->loadDispatcher($dispatcher);
88 $this->loadConfiguration($this->fetchConfigurationData());
91 $this->
set(
'execution.datetime', gmdate(
'Y-m-d H:i:s'));
92 $this->
set(
'execution.timestamp', time());
95 $this->
set(
'cwd', getcwd());
108 public function get($key, $default = null)
110 return $this->config->get($key, $default);
124 public static function getInstance($name = null)
127 if (empty(self::$instance))
129 if (class_exists($name) && (is_subclass_of($name,
'JApplicationCli')))
131 self::$instance =
new $name;
139 return self::$instance;
149 public function execute()
152 $this->triggerEvent(
'onBeforeExecute');
158 $this->triggerEvent(
'onAfterExecute');
170 public function loadConfiguration($data)
175 $this->config->loadArray($data);
177 elseif (is_object($data))
179 $this->config->loadObject($data);
196 public function out($text =
'', $nl =
true)
198 fwrite(STDOUT, $text . ($nl ?
"\n" : null));
213 return rtrim(fread(STDIN, 8192),
"\n");
226 public function set($key, $value = null)
228 $previous = $this->config->get($key);
229 $this->config->set($key, $value);
247 protected function fetchConfigurationData($file =
'', $class =
'JConfig')
252 if (empty($file) && defined(
'JPATH_BASE'))
254 $file = JPATH_BASE .
'/configuration.php';
258 if (!file_exists($file))
268 if (class_exists($class))
270 $config =
new $class;
274 throw new RuntimeException(
'Configuration class does not exist.');
290 protected function doExecute()