Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php -q
- <?php
- /**
- * @version $Id$
- * @package Joomla.Example
- * @subpackage CLI
- * @copyright Copyright (C) 2008 - 2009 Louis Landry. All rights reserved.
- * @license GNU General Public License, <http://www.gnu.org/copyleft/gpl.html>
- */
- // We are a valid Joomla entry point.
- define('_JEXEC', 1);
- define('JPATH_BASE', dirname(__FILE__) );
- define( 'DS', DIRECTORY_SEPARATOR );
- require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
- require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
- jimport('joomla.application.application');
- /**
- * Simple command line interface application class for quick bootstrapping
- things to test.
- *
- * @package Joomla.Example
- * @subpackage CLI
- * @version 1.0
- */
- class JApplicationCLI extends JApplication
- {
- /**
- * The name of the application
- *
- * @var array
- */
- public $_name = 'JApplicationCLI';
- /**
- * The current working directory of the application.
- *
- * @var string
- * @since 1.0
- */
- public $cwd = null;
- /**
- * The application argument values.
- *
- * @var array
- * @since 1.0
- */
- public $argv = array();
- /**
- * The application argument options.
- *
- * The options are populated automatically by the private _initializeOptions
- function
- * which sets each command line argument as a member of the options object.
- *
- * @var object
- * @since 1.0
- */
- public $options = null;
- public $shortargs = 'i:o:hflp';
- // Need to wait for PHP 5.3
- public $longargs = array('help');
- public function __construct($config = array())
- {
- $config['clientId'] = 2;
- parent::__construct($config);
- // Initialize the execution arguments.
- $this->_initializeOptions();
- // If the help screen has been requested, print it and exit.
- if (isset($this->options->h)) {
- $this->help();
- exit(0);
- }
- // Get the current directory.
- $this->cwd = getcwd();
- }
- public function execute()
- {
- // Print the application header.
- $this->out('Joomla! Example Command Line Application');
- $this->out('----------------------------------------');
- $this->out();
- $name = $this->getName();
- $this->out($name);
- //$login =& $this->login(array('username' => 'admin',
- // 'password' => 'admin'),
- // array('remember' => FALSE));
- //$this->out($login);
- $listings = KFactory::tmp('admin::com.unbooked.controller.listing')->_actionDownload();
- //$this->out(file_get_contents(JComponentHelper::getParams('com_unbooked')->get('ub_api_url')."vendors"));
- //$db = JFactory::getDBO();
- //print_r($json_data);
- $this->out('----------------------------------------');
- $this->out();
- }
- /**
- * Method to print a line of text to stdout.
- *
- * @param string The line of text to print to stdout.
- * @return void
- * @since 1.0
- */
- function out($text = '')
- {
- echo "\n".$text;
- }
- /**
- * Method to build and print the help screen text to stdout.
- *
- * @return void
- * @since 1.0
- */
- protected function help()
- {
- // Initialize variables.
- $help = array();
- // Build the help screen information.
- $help[] = 'Your Help Screen';
- $help[] = '';
- $help[] = 'Here is where you put all your help screen information.';
- $help[] = '';
- // Print out the help information.
- echo implode("\n", $help);
- }
- /**
- * Initialize the command line options and arguments.
- *
- * @return void
- * @since 1.0
- */
- private function _initializeOptions()
- {
- // Get the options from the command line argument list and argument values.
- $opts = getopt($this->shortargs /*, $this->longargs*/);
- $args = isset($GLOBALS['argv']) ? (array) $GLOBALS['argv'] : array();
- // If the argument value list is not empty, make sure the options are unset.
- if (!empty($args))
- {
- // Iterate over the found options.
- foreach ($opts as $o => $a)
- {
- // Search for occurrences of the option with no value or with no space between option and value.
- while ($k = array_search('-'.$o.$a,$args))
- {
- // Remove any found options from the argument value array.
- if ($k) {
- unset($args[$k]);
- }
- }
- // Search for remaining occurrences of the option (space between option and value).
- while ($k = array_search('-'.$o,$args))
- {
- // Remove any found options and values from the argument value array.
- if($k) {
- unset($args[$k]);
- unset($args[$k+1]);
- }
- }
- }
- }
- // Set the options and argument values to internal members.
- $this->options = (object) $opts;
- $this->argv = (array) $args;
- }
- }
- $app = new JApplicationCLI(); // Create the application object.
- $app->execute(); // Execute the application.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement