Skip to content
Browse files

Merge pull request #847 from realityking/application

Use JApplicationBase as the foundation for JApplication as well.
  • Loading branch information...
2 parents 9c68148 + 5612a32 commit cde4a88b65bd473f020889b4b79697022e2f95e5 @robschley robschley committed
View
61 libraries/joomla/application/application.php
@@ -9,7 +9,6 @@
defined('JPATH_PLATFORM') or die;
-jimport('joomla.event.dispatcher');
jimport('joomla.environment.response');
/**
@@ -23,8 +22,7 @@
* @subpackage Application
* @since 11.1
*/
-
-class JApplication extends JObject
+class JApplication extends JApplicationBase
{
/**
* The client identifier.
@@ -102,14 +100,6 @@ class JApplication extends JObject
public $startTime = null;
/**
- * The application input object.
- *
- * @var JInput
- * @since 11.2
- */
- public $input = null;
-
- /**
* @var array JApplication instances container.
* @since 11.3
*/
@@ -172,6 +162,8 @@ public function __construct($config = array())
$this->_createSession(self::getHash($config['session_name']));
}
+ $this->loadDispatcher();
+
$this->set('requestTime', gmdate('Y-m-d H:i'));
// Used by task system to ensure that the system doesn't go over time.
@@ -344,20 +336,6 @@ public function render()
}
/**
- * Exit the application.
- *
- * @param integer $code Exit code
- *
- * @return void Exits the application.
- *
- * @since 11.1
- */
- public function close($code = 0)
- {
- exit($code);
- }
-
- /**
* Redirect to another URL.
*
* Optionally enqueues a message in the system message queue (which will be displayed
@@ -639,39 +617,6 @@ public function getUserStateFromRequest($key, $request, $default = null, $type =
}
/**
- * Registers a handler to a particular event group.
- *
- * @param string $event The event name.
- * @param mixed $handler The handler, a function or an instance of a event object.
- *
- * @return void
- *
- * @since 11.1
- */
- public static function registerEvent($event, $handler)
- {
- $dispatcher = JDispatcher::getInstance();
- $dispatcher->register($event, $handler);
- }
-
- /**
- * Calls all handlers associated with an event group.
- *
- * @param string $event The event name.
- * @param array $args An array of arguments.
- *
- * @return array An array of results from each function call.
- *
- * @since 11.1
- */
- public function triggerEvent($event, $args = null)
- {
- $dispatcher = JDispatcher::getInstance();
-
- return $dispatcher->trigger($event, $args);
- }
-
- /**
* Login authentication function.
*
* Username and encoded password are passed the onUserLogin event which
View
169 libraries/joomla/application/base.php
@@ -18,7 +18,7 @@
* @subpackage Application
* @since 12.1
*/
-abstract class JApplicationBase
+abstract class JApplicationBase extends JObject
{
/**
* The application input object.
@@ -26,23 +26,7 @@
* @var JInput
* @since 12.1
*/
- public $input;
-
- /**
- * The application configuration object.
- *
- * @var JRegistry
- * @since 12.1
- */
- protected $config;
-
- /**
- * The character encoding string.
- *
- * @var string
- * @since 12.1
- */
- protected $charSet = 'utf-8';
+ public $input = null;
/**
* The application dispatcher object.
@@ -53,14 +37,6 @@
protected $dispatcher;
/**
- * The application instance.
- *
- * @var JApplicationBase
- * @since 12.1
- */
- protected static $instance;
-
- /**
* Method to close the application.
*
* @param integer $code The exit code (optional; default is 0).
@@ -75,66 +51,6 @@ public function close($code = 0)
}
/**
- * Method to execute the application.
- *
- * @return void
- *
- * @since 12.1
- */
- abstract public function execute();
-
- /**
- * Method to get a property of the application 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 12.1
- */
- public function get($key, $default = null)
- {
- return $this->config->get($key, $default);
- }
-
- /**
- * Method to get the application character set.
- *
- * @return string The character set.
- *
- * @since 12.1
- */
- public function getCharacterSet()
- {
- return $this->charSet;
- }
-
- /**
- * Method to 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 JApplicationBase The application to allow chaining.
- *
- * @since 12.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;
- }
-
- /**
* Registers a handler to a particular event group.
*
* @param string $event The event name.
@@ -155,40 +71,6 @@ public function registerEvent($event, $handler)
}
/**
- * Method to set a property of the application, 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 12.1
- */
- public function set($key, $value = null)
- {
- $previous = $this->config->get($key);
- $this->config->set($key, $value);
-
- return $previous;
- }
-
- /**
- * Method to set the application character set.
- *
- * @param string $charset The character set.
- *
- * @return JApplicationBase The application to allow chaining.
- *
- * @since 12.1
- */
- public function setCharacterSet($charset)
- {
- $this->charSet = $charset;
-
- return $this;
- }
-
- /**
* Calls all handlers associated with an event group.
*
* @param string $event The event name.
@@ -209,53 +91,6 @@ public function triggerEvent($event, array $args = 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.
- *
- * @since 12.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.
View
126 libraries/joomla/application/cli.php
@@ -19,6 +19,18 @@
class JApplicationCli extends JApplicationBase
{
/**
+ * @var JRegistry The application configuration object.
+ * @since 11.1
+ */
+ protected $config;
+
+ /**
+ * @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
@@ -93,6 +105,21 @@ public function __construct(JInputCli $input = null, JRegistry $config = null, J
}
/**
+ * 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();
@@ -141,16 +168,27 @@ public function execute()
}
/**
- * Get a value from standard input.
+ * Load an object or array into the application configuration object.
*
- * @return string The input string from standard input.
+ * @param mixed $data Either an array or object to be loaded into the configuration object.
+ *
+ * @return JApplicationCli Instance of $this to allow chaining.
*
- * @codeCoverageIgnore
* @since 11.1
*/
- public function in()
+ public function loadConfiguration($data)
{
- return rtrim(fread(STDIN, 8192), "\n");
+ // 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;
}
/**
@@ -172,6 +210,84 @@ public function out($text = '', $nl = true)
}
/**
+ * 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");
+ }
+
+ /**
+ * 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 run the application routines. Most likely you will want to instantiate a controller
* and execute it, or perform some sort of task directly.
*
View
116 libraries/joomla/application/web.php
@@ -21,6 +21,12 @@
class JApplicationWeb extends JApplicationBase
{
/**
+ * @var string Character encoding string.
+ * @since 11.3
+ */
+ public $charSet = 'utf-8';
+
+ /**
* @var string Response mime type.
* @since 11.3
*/
@@ -39,6 +45,12 @@ class JApplicationWeb extends JApplicationBase
public $client;
/**
+ * @var JRegistry The application configuration object.
+ * @since 11.3
+ */
+ protected $config;
+
+ /**
* @var JDocument The application document object.
* @since 11.3
*/
@@ -573,6 +585,63 @@ public function redirect($url, $moved = false)
}
/**
+ * 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 JApplicationWeb Instance of $this to allow chaining.
+ *
+ * @since 11.3
+ */
+ 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
* Set/get cachable state for the response. If $allow is set, sets the cachable state of the
* response. Always returns the current state.
*
@@ -866,6 +935,53 @@ protected function detectRequestUri()
}
/**
+ * 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.3
+ */
+ 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 send a header to the client. We are wrapping this to isolate the header() function
* from our code base for testing reasons.
*

0 comments on commit cde4a88

Please sign in to comment.
Something went wrong with that request. Please try again.