Permalink
Browse files

Merge pull request #847 from realityking/application

Use JApplicationBase as the foundation for JApplication as well.
  • Loading branch information...
robschley committed Feb 10, 2012
2 parents 9c68148 + 5612a32 commit cde4a88b65bd473f020889b4b79697022e2f95e5
@@ -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.
@@ -101,14 +99,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.
@@ -343,20 +335,6 @@ public function render()
$this->triggerEvent('onAfterRender');
}
- /**
- * 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.
*
@@ -638,39 +616,6 @@ public function getUserStateFromRequest($key, $request, $default = null, $type =
return $new_state;
}
- /**
- * 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.
*
@@ -18,31 +18,15 @@
* @subpackage Application
* @since 12.1
*/
-abstract class JApplicationBase
+abstract class JApplicationBase extends JObject
{
/**
* The application input object.
*
* @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.
@@ -52,14 +36,6 @@
*/
protected $dispatcher;
- /**
- * The application instance.
- *
- * @var JApplicationBase
- * @since 12.1
- */
- protected static $instance;
-
/**
* Method to close the application.
*
@@ -74,66 +50,6 @@ public function close($code = 0)
exit($code);
}
- /**
- * 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.
*
@@ -154,40 +70,6 @@ public function registerEvent($event, $handler)
return $this;
}
- /**
- * 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.
*
@@ -208,53 +90,6 @@ public function triggerEvent($event, array $args = null)
return 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
Oops, something went wrong.

0 comments on commit cde4a88

Please sign in to comment.