0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: cli.php.tar
home/academiac/www/libraries/joomla/application/input/cli.php 0000644 00000007361 15137261373 0020405 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Application * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.application.input'); /** * Joomla! Input CLI Class * * @package Joomla.Platform * @subpackage Application * @since 11.1 */ class JInputCLI extends JInput { /** * The executable that was called to run the CLI script. * * @var string * @since 11.1 */ public $executable; /** * The additional arguments passed to the script that are not associated * with a specific argument name. * * @var array * @since 11.1 */ public $args = array(); /** * Constructor. * * @param array $source Source data (Optional, default is $_REQUEST) * @param array $options Array of configuration parameters (Optional) * * @since 11.1 */ public function __construct(array $source = null, array $options = array()) { if (isset($options['filter'])) { $this->filter = $options['filter']; } else { $this->filter = JFilterInput::getInstance(); } // Get the command line options $this->parseArguments(); // Set the options for the class. $this->options = $options; } /** * Initialise the options and arguments * * @return void * * @since 11.1 */ protected function parseArguments() { // Get the list of argument values from the environment. $args = $_SERVER['argv']; // Set the path used for program execution and remove it form the program arguments. $this->executable = array_shift($args); // We use a for loop because in some cases we need to look ahead. for ($i = 0; $i < count($args); $i++) { // Get the current argument to analyze. $arg = $args[$i]; // First let's tackle the long argument case. eg. --foo if (strlen($arg) > 2 && substr($arg, 0, 2) == '--') { // Attempt to split the thing over equals so we can get the key/value pair if an = was used. $arg = substr($arg, 2); $parts = explode('=', $arg); $this->data[$parts[0]] = true; // Does not have an =, so let's look ahead to the next argument for the value. if (count($parts) == 1 && isset($args[$i + 1]) && preg_match('/^--?.+/', $args[$i + 1]) == 0) { $this->data[$parts[0]] = $args[$i + 1]; // Since we used the next argument, increment the counter so we don't use it again. $i++; } // We have an equals sign so take the second "part" of the argument as the value. elseif (count($parts) == 2) { $this->data[$parts[0]] = $parts[1]; } } // Next let's see if we are dealing with a "bunch" of short arguments. eg. -abc elseif (strlen($arg) > 2 && $arg[0] == '-') { // For each of these arguments set the value to TRUE since the flag has been set. for ($j = 1; $j < strlen($arg); $j++) { $this->data[$arg[$j]] = true; } } // OK, so it isn't a long argument or bunch of short ones, so let's look and see if it is a single // short argument. eg. -h elseif (strlen($arg) == 2 && $arg[0] == '-') { // Go ahead and set the value to TRUE and if we find a value later we'll overwrite it. $this->data[$arg[1]] = true; // Let's look ahead to see if the next argument is a "value". If it is, use it for this value. if (isset($args[$i + 1]) && preg_match('/^--?.+/', $args[$i + 1]) == 0) { $this->data[$arg[1]] = $args[$i + 1]; // Since we used the next argument, increment the counter so we don't use it again. $i++; } } // Last but not least, we don't have a key/value based argument so just add it to the arguments list. else { $this->args[] = $arg; } } } } home/academiac/www/libraries/joomla/application/cli.php 0000644 00000023560 15137264740 0017246 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Application * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; jimport('joomla.application.input'); jimport('joomla.event.dispatcher'); /** * Base class for a Joomla! command line application. * * @package Joomla.Platform * @subpackage Application * @since 11.4 */ class JApplicationCli { /** * @var JInputCli The application input object. * @since 11.1 */ public $input; /** * @var JRegistry The application configuration object. * @since 11.1 */ protected $config; /** * @var JDispatcher The application dispatcher object. * @since 11.1 */ protected $dispatcher; /** * @var JApplicationCli The application instance. * @since 11.1 */ protected static $instance; /** * Class constructor. * * @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 JDispatcher 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 loadDispatcher() * @since 11.1 */ public function __construct(JInputCli $input = null, JRegistry $config = null, JDispatcher $dispatcher = null) { // Close the application if we are not executed from the command line. // @codeCoverageIgnoreStart if (!defined('STDOUT') || !defined('STDIN') || !isset($_SERVER['argv'])) { $this->close(); } // @codeCoverageIgnoreEnd // If a input object is given use it. if ($input instanceof JInput) { $this->input = $input; } // Create the input based on the application logic. else { if (class_exists('Jinput')) { $this->input = new JInputCLI; } } // If a config object is given use it. if ($config instanceof JRegistry) { $this->config = $config; } // Instantiate a new configuration object. else { $this->config = new JRegistry; } // Reverted back for version CMS 2.5.6 // If a dispatcher object is given use it. if ($dispatcher instanceof JDispatcher) { $this->dispatcher = $dispatcher; } // Create the dispatcher based on the application logic. else { $this->loadDispatcher(); } // Load the configuration object. $this->loadConfiguration($this->fetchConfigurationData()); // 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. $this->set('cwd', getcwd()); } /** * 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. * * @since 11.3 */ public function get($key, $default = null) { return $this->config->get($key, $default); } /** * 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 * * @since 11.1 */ public static function getInstance($name = null) { // 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; } else { self::$instance = new JApplicationCli; } } return self::$instance; } /** * Execute the application. * * @return void * * @since 11.1 */ public function execute() { // Trigger the onBeforeExecute event. $this->triggerEvent('onBeforeExecute'); // Perform application routines. $this->doExecute(); // Trigger the onAfterExecute event. $this->triggerEvent('onAfterExecute'); } /** * 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 * * @codeCoverageIgnore * @since 11.3 */ protected function doExecute() { // Your application routines go here. } /** * Exit the application. * * @param integer $code The exit code (optional; default is 0). * * @return void * * @codeCoverageIgnore * @since 11.1 */ public function close($code = 0) { exit($code); } /** * 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. * * @since 11.1 */ public function loadConfiguration($data) { // Load the data into the configuration object. if (is_array($data)) { $this->config->loadArray($data); } elseif (is_object($data)) { $this->config->loadObject($data); } return $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 JApplicationCli Instance of $this to allow chaining. * * @codeCoverageIgnore * @since 11.1 */ 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. * * @codeCoverageIgnore * @since 11.1 */ public function in() { return rtrim(fread(STDIN, 8192), "\n"); } /** * Registers a handler to a particular event group. * * @param string $event The event name. * @param callback $handler The handler, a function or an instance of a event object. * * @return JApplicationCli Instance of $this to allow chaining. * * @since 11.1 */ public function registerEvent($event, $handler) { if ($this->dispatcher instanceof JDispatcher) { $this->dispatcher->register($event, $handler); } return $this; } /** * Calls all handlers associated with an event group. * * @param string $event The event name. * @param array $args An array of arguments (optional). * * @return array An array of results from each function call, or null if no dispatcher is defined. * * @since 11.1 */ public function triggerEvent($event, array $args = null) { if ($this->dispatcher instanceof JDispatcher) { return $this->dispatcher->trigger($event, $args); } return null; } /** * 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 * * @since 11.3 */ public function set($key, $value = null) { $previous = $this->config->get($key); $this->config->set($key, $value); return $previous; } /** * 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. * * @since 11.1 */ protected function fetchConfigurationData($file = '', $class = 'JConfig') { // Instantiate variables. $config = array(); if (empty($file) && defined('JPATH_BASE')) { $file = JPATH_BASE . '/configuration.php'; // Applications can choose not to have any configuration data // by not implementing this method and not having a config file. if (!file_exists($file)) { $file = ''; } } if (!empty($file)) { JLoader::register($class, $file); if (class_exists($class)) { $config = new $class; } else { throw new RuntimeException('Configuration class does not exist.'); } } return $config; } /** * Method to create an event dispatcher for the application. The logic and options for creating * this object are adequately generic for default cases but for many applications it will make sense * to override this method and create event dispatchers based on more specific needs. * * @return void * * @since 11.3 */ protected function loadDispatcher() { $this->dispatcher = JDispatcher::getInstance(); } } /** * Deprecated class placeholder. You should use JApplicationCli instead. * * @package Joomla.Platform * @subpackage Application * @since 11.1 * @deprecated 12.3 */ class JCli extends JApplicationCli { }
©
2018.