Permalink
Browse files

Merge remote-tracking branch 'joomla/master' into language

  • Loading branch information...
2 parents 5d8925c + a34b024 commit e20763ec257ad1abd75fbe7f52cccb5c79cd7264 @chdemko committed Oct 20, 2011
@@ -978,7 +978,7 @@ protected function _createConfiguration($file)
{
jimport('joomla.registry.registry');
- include_once $file;
+ JLoader::register('JConfig', $file);
// Create the JConfig object.
$config = new JConfig;
@@ -334,38 +334,42 @@ public function set($key, $value = null)
* will extend this method in child classes to provide configuration data from whatever data source is relevant
* for your specific application.
*
- * @param string $fileName The name of the configuration file (default is 'configuration').
- * Note that .php is appended to this name
+ * @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.
+ * @return mixed Either an array or object to be loaded into the configuration object.
*
* @since 11.1
*/
- protected function fetchConfigurationData($fileName = 'configuration')
+ protected function fetchConfigurationData($file = '', $class = 'JConfig')
{
// Instantiate variables.
$config = array();
- if (empty($fileName))
+ if (empty($file) && defined('JPATH_BASE'))
{
- $fileName = 'configuration';
+ $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 = '';
+ }
}
- // Handle the convention-based default case for configuration file.
- if (defined('JPATH_BASE'))
+ if (!empty($file))
{
- // Set the configuration file name and check to see if it exists.
- $file = JPATH_BASE . '/' . preg_replace('#[^A-Z0-9-_.]#i', '', $fileName) . '.php';
- if (is_file($file))
+ JLoader::register($class, $file);
+
+ if (class_exists($class))
+ {
+ $config = new $class;
+ }
+ else
{
- // Import the configuration file.
- include_once $file;
-
- // Instantiate the configuration object if it exists.
- if (class_exists('JConfig'))
- {
- $config = new JConfig;
- }
+ throw new Exception('Configuration class does not exist.');
}
}
@@ -139,7 +139,7 @@ public function __construct(JInputCli $input = null, JRegistry $config = null, J
/**
* Method to handle POSIX signals.
*
- * @param integer $signal The recieved POSIX signal.
+ * @param integer $signal The received POSIX signal.
*
* @return void
*
@@ -158,8 +158,8 @@ public static function signal($signal)
throw new ApplicationException;
}
- // Fire the onRecieveSignal event.
- static::$instance->triggerEvent('onRecieveSignal', array($signal));
+ // Fire the onReceiveSignal event.
+ static::$instance->triggerEvent('onReceiveSignal', array($signal));
switch ($signal)
{
@@ -663,7 +663,7 @@ public function display($cachable = false, $urlparams = false)
$viewName = JRequest::getCmd('view', $this->default_view);
$viewLayout = JRequest::getCmd('layout', 'default');
- $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath));
+ $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));
// Get/Create the model
if ($model = $this->getModel($viewName))
@@ -672,9 +672,6 @@ public function display($cachable = false, $urlparams = false)
$view->setModel($model, true);
}
- // Set the layout
- $view->setLayout($viewLayout);
-
$view->assignRef('document', $document);
$conf = JFactory::getConfig();
@@ -977,38 +977,42 @@ protected function detectRequestUri()
* will extend this method in child classes to provide configuration data from whatever data source is relevant
* for your specific application.
*
- * @param string $fileName The name of the configuration file (default is 'configuration').
- * Note that .php is appended to this name
+ * @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.
+ * @return mixed Either an array or object to be loaded into the configuration object.
*
* @since 11.3
*/
- protected function fetchConfigurationData($fileName = 'configuration')
+ protected function fetchConfigurationData($file = '', $class = 'JConfig')
{
// Instantiate variables.
$config = array();
- if (empty($fileName))
+ if (empty($file) && defined('JPATH_BASE'))
{
- $fileName = 'configuration';
+ $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 = '';
+ }
}
- // Handle the convention-based default case for configuration file.
- if (defined('JPATH_BASE'))
+ if (!empty($file))
{
- // Set the configuration file name and check to see if it exists.
- $file = JPATH_BASE . '/' . preg_replace('#[^A-Z0-9-_.]#i', '', $fileName) . '.php';
- if (is_file($file))
- {
- // Import the configuration file.
- include_once $file;
+ JLoader::register($class, $file);
- // Instantiate the configuration object if it exists.
- if (class_exists('JConfig'))
- {
- $config = new JConfig;
- }
+ if (class_exists($class))
+ {
+ $config = new $class;
+ }
+ else
+ {
+ throw new Exception('Configuration class does not exist.');
}
}
@@ -35,7 +35,8 @@
*/
public static function bytes($bytes, $unit = 'auto', $precision = 2)
{
- $bytes = (int) $bytes;
+ // No explicit casting $bytes to integer here, since it might overflow
+ // on 32-bit systems
$precision = (int) $precision;
if (empty($bytes))
@@ -29,24 +29,6 @@ class JCliTest extends JoomlaTestCase
protected $inspector;
/**
- * Data for fetchConfigurationData method.
- *
- * @return array
- *
- * @since 11.3
- */
- public function getFetchConfigurationData()
- {
- return array(
- // fileName, expectsClass, (expected result array)
- 'Default configuration class' => array(null, true, array('foo' => 'bar')),
- 'Custom file with array' => array('config.jweb-array', false, array('foo' => 'bar')),
-// 'Custom file, invalid class' => array('config.JCli-wrongclass', false, array()),
- 'Custom file, snooping' => array('../test_application/config.jcli-snoopy', false, array()),
- );
- }
-
- /**
* Setup for testing.
*
* @return void
@@ -232,9 +214,26 @@ public function testExecute()
}
/**
+ * Data for fetchConfigurationData method.
+ *
+ * @return array
+ *
+ * @since 11.3
+ */
+ public function getFetchConfigurationData()
+ {
+ return array(
+ // file, class, expectsClass, (expected result array), whether there should be an exception
+ 'Default configuration class' => array(null, null, 'JConfig', 'ConfigEval'),
+ 'Custom file, invalid class' => array(JPATH_BASE . '/config.JCli-wrongclass.php', 'noclass', false, array(), true),
+ );
+ }
+
+ /**
* Tests the JCli::fetchConfigurationData method.
*
* @param string $fileName The name of the configuration file.
+ * @param string $fileName The name of the configuration file.
* @param boolean $expectsClass The result is expected to be a class.
* @param array $expects The expected result as an array.
*
@@ -243,14 +242,36 @@ public function testExecute()
* @dataProvider getFetchConfigurationData
* @since 11.3
*/
- public function testFetchConfigurationData($fileName, $expectsClass, $expects)
+ public function testFetchConfigurationData($file, $class, $expectsClass, $expects, $expectedException = false)
{
- $config = $this->inspector->fetchConfigurationData($fileName);
+ if ($expectedException)
+ {
+ $this->setExpectedException('Exception');
+ }
+
+ if (is_null($file) && is_null($class))
+ {
+ $config = $this->inspector->fetchConfigurationData();
+ }
+ elseif (is_null($class))
+ {
+ $config = $this->inspector->fetchConfigurationData($file);
+ }
+ else
+ {
+ $config = $this->inspector->fetchConfigurationData($file, $class);
+ }
+
+ if ($expects == 'ConfigEval')
+ {
+ $expects = new JConfig;
+ $expects = (array)$expects;
+ }
if ($expectsClass)
{
$this->assertInstanceOf(
- 'JConfig',
+ $expectsClass,
$config,
'Checks the configuration object is the appropriate class.'
);
@@ -69,24 +69,6 @@ public function getDetectRequestUriData()
*
* @since 11.3
*/
- public function getFetchConfigurationData()
- {
- return array(
- // fileName, expectsClass, (expected result array)
- 'Default configuration class' => array(null, true, array('foo' => 'bar')),
- 'Custom file with array' => array('config.jweb-array', false, array('foo' => 'bar')),
-// 'Custom file, invalid class' => array('config.jweb-wrongclass', false, array()),
- 'Custom file, snooping' => array('../test_application/config.jweb-snoopy', false, array()),
- );
- }
-
- /**
- * Data for fetchConfigurationData method.
- *
- * @return array
- *
- * @since 11.3
- */
public function getRedirectData()
{
return array(
@@ -742,8 +724,25 @@ public function testExecuteWithDocument()
}
/**
- * Tests the JWeb::fetchConfigurationData method.
+ * Data for fetchConfigurationData method.
+ *
+ * @return array
*
+ * @since 11.3
+ */
+ public function getFetchConfigurationData()
+ {
+ return array(
+ // file, class, expectsClass, (expected result array), whether there should be an exception
+ 'Default configuration class' => array(null, null, 'JConfig', 'ConfigEval'),
+ 'Custom file, invalid class' => array(JPATH_BASE . '/config.JCli-wrongclass.php', 'noclass', false, array(), true),
+ );
+ }
+
+ /**
+ * Tests the JCli::fetchConfigurationData method.
+ *
+ * @param string $fileName The name of the configuration file.
* @param string $fileName The name of the configuration file.
* @param boolean $expectsClass The result is expected to be a class.
* @param array $expects The expected result as an array.
@@ -753,14 +752,36 @@ public function testExecuteWithDocument()
* @dataProvider getFetchConfigurationData
* @since 11.3
*/
- public function testFetchConfigurationData($fileName, $expectsClass, $expects)
+ public function testFetchConfigurationData($file, $class, $expectsClass, $expects, $expectedException = false)
{
- $config = $this->inspector->fetchConfigurationData($fileName);
+ if ($expectedException)
+ {
+ $this->setExpectedException('Exception');
+ }
+
+ if (is_null($file) && is_null($class))
+ {
+ $config = $this->inspector->fetchConfigurationData();
+ }
+ elseif (is_null($class))
+ {
+ $config = $this->inspector->fetchConfigurationData($file);
+ }
+ else
+ {
+ $config = $this->inspector->fetchConfigurationData($file, $class);
+ }
+
+ if ($expects == 'ConfigEval')
+ {
+ $expects = new JConfig;
+ $expects = (array)$expects;
+ }
if ($expectsClass)
{
$this->assertInstanceOf(
- 'JConfig',
+ $expectsClass,
$config,
'Checks the configuration object is the appropriate class.'
);
@@ -105,9 +105,9 @@ public function setClassProperty($name, $value)
*
* @since 11.3
*/
- public function fetchConfigurationData($fileName = null)
+ public function fetchConfigurationData($file = '', $class = 'JConfig')
{
- return parent::fetchConfigurationData($fileName);
+ return parent::fetchConfigurationData($file, $class);
}
/**
@@ -181,9 +181,9 @@ public function doExecute()
*
* @since 11.3
*/
- public function fetchConfigurationData($fileName = null)
+ public function fetchConfigurationData($file = '', $class = 'JConfig')
{
- return parent::fetchConfigurationData($fileName);
+ return parent::fetchConfigurationData($file, $class);
}
/**
Oops, something went wrong.

0 comments on commit e20763e

Please sign in to comment.