application_name = 'cli'; $this->name = 'cli'; } parent::__construct($container); if (!($container->input instanceof \Awf\Input\Cli)) { // Create an input object $cgiMode = false; if (!defined('STDOUT') || !defined('STDIN') || !isset($_SERVER['argv'])) { $cgiMode = true; } if ($cgiMode) { $query = ""; if (!empty($_GET)) { foreach ($_GET as $k => $v) { $query .= " $k"; if ($v != "") { $query .= "=$v"; } } } $query = ltrim($query); $argv = explode(' ', $query); $argc = count($argv); $_SERVER['argv'] = $argv; } unset($container['input']); $container['input'] = new \Awf\Input\Cli(); try { } catch (\Exception $e) { } } self::$instances['cli'] = $this; } /** * Execute the application. * * @return void * * @since 11.1 */ public function execute() { // Trigger the onBeforeExecute event. if (method_exists($this, 'onBeforeExecute')) { $this->onBeforeExecute(); } $this->container->eventDispatcher->trigger('onBeforeExecute', array(&$this)); // Perform application routines. $this->doExecute(); // Trigger the onAfterExecute event. if (method_exists($this, 'onAfterExecute')) { $this->onAfterExecute(); } $this->container->eventDispatcher->trigger('onAfterExecute', array(&$this)); } /** * 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 Cli Instance of $this to allow chaining. */ public function out($text = '', $nl = true) { fwrite(STDOUT, $text . ($nl ? "\n" : null)); return $this; } /** * Get a value from standard input. * * @return string The input string from standard input. */ public function in() { return rtrim(fread(STDIN, 8192), "\n"); } /** * 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. * * @return void */ abstract protected function doExecute(); }