Skip to content
Browse files

Docblock improvements to the Config library and remove CI_Config::_as…

…sign_to_config()

Existance of _assign_to_config() is pointless as this method
consists just of a foreach calling CI_Config::set_item() and
is only called by CodeIgniter.php - moved that foreach() in
there instead.
  • Loading branch information...
1 parent 60826db commit 5232ba07752ffa783d03754c3a869d9f73ccae69 @narfbg narfbg committed Oct 27, 2012
View
7 system/core/CodeIgniter.php
@@ -130,9 +130,12 @@
$CFG =& load_class('Config', 'core');
// Do we have any manually set config items in the index.php file?
- if (isset($assign_to_config))
+ if (isset($assign_to_config) && is_array($assign_to_config))
{
- $CFG->_assign_to_config($assign_to_config);
+ foreach ($assign_to_config as $key => $value)
+ {
+ $CFG->set_item($key, $value);
+ }
}
/*
View
80 system/core/Config.php
@@ -26,7 +26,7 @@
*/
/**
- * CodeIgniter Config Class
+ * Config Class
*
* This class contains functions that enable config files to be managed
*
@@ -41,29 +41,31 @@ class CI_Config {
/**
* List of all loaded config values
*
- * @var array
+ * @var array
*/
public $config = array();
/**
* List of all loaded config files
*
- * @var array
+ * @var array
*/
public $is_loaded = array();
/**
* List of paths to search when trying to load a config file.
- * This must be public as it's used by the Loader class.
*
- * @var array
+ * @used-by CI_Loader Must be public
+ * @var array
*/
public $_config_paths = array(APPPATH);
/**
- * Constructor
+ * Class constructor
*
- * Sets the $config data from the primary config.php file as a class variable
+ * Sets the $config data from the primary config.php file as a class variable.
+ *
+ * @return void
*/
public function __construct()
{
@@ -93,10 +95,10 @@ public function __construct()
/**
* Load Config File
*
- * @param string the config file name
- * @param bool if configuration values should be loaded into their own section
- * @param bool true if errors should just return false, false if an error message should be displayed
- * @return bool if the file was loaded correctly
+ * @param string $file Configuration file name
+ * @param bool $use_sections Whether configuration values should be loaded into their own section
+ * @param bool $fail_gracefully Whether to just return FALSE or display an error message
+ * @return bool TRUE if the file was loaded correctly or FALSE on failure
*/
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
@@ -183,9 +185,9 @@ public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE
/**
* Fetch a config file item
*
- * @param string the config item name
- * @param string the index name
- * @return string
+ * @param string $item Config item name
+ * @param string $index Index name
+ * @return string|bool The configuration item or FALSE on failure
*/
public function item($item, $index = '')
{
@@ -200,10 +202,10 @@ public function item($item, $index = '')
// --------------------------------------------------------------------
/**
- * Fetch a config file item - adds slash after item (if item is not empty)
+ * Fetch a config file item with slash appended (if not empty)
*
- * @param string the config item name
- * @return string
+ * @param string $item Config item name
+ * @return string|bool The configuration item or FALSE on failure
*/
public function slash_item($item)
{
@@ -223,9 +225,12 @@ public function slash_item($item)
/**
* Site URL
+ *
* Returns base_url . index_page [. uri_string]
*
- * @param mixed the URI string or an array of segments
+ * @uses CI_Config::_uri_string()
+ *
+ * @param string|string[] $uri URI string or an array of segments
* @return string
*/
public function site_url($uri = '')
@@ -264,9 +269,12 @@ public function site_url($uri = '')
/**
* Base URL
+ *
* Returns base_url [. uri_string]
*
- * @param string $uri
+ * @uses CI_Config::_uri_string()
+ *
+ * @param string|string[] $uri URI string or an array of segments
* @return string
*/
public function base_url($uri = '')
@@ -277,9 +285,12 @@ public function base_url($uri = '')
// -------------------------------------------------------------
/**
- * Build URI string for use in Config::site_url() and Config::base_url()
+ * Build URI string
+ *
+ * @used-by CI_Config::site_url()
+ * @used-by CI_Config::base_url()
*
- * @param mixed $uri
+ * @param string|string[] $uri URI string or an array of segments
* @return string
*/
protected function _uri_string($uri)
@@ -318,38 +329,15 @@ public function system_url()
/**
* Set a config file item
*
- * @param string the config item key
- * @param string the config item value
+ * @param string $item Config item key
+ * @param string $value Config item value
* @return void
*/
public function set_item($item, $value)
{
$this->config[$item] = $value;
}
- // --------------------------------------------------------------------
-
- /**
- * Assign to Config
- *
- * This function is called by the front controller (CodeIgniter.php)
- * after the Config class is instantiated. It permits config items
- * to be assigned or overriden by variables contained in the index.php file
- *
- * @param array
- * @return void
- */
- public function _assign_to_config($items = array())
- {
- if (is_array($items))
- {
- foreach ($items as $key => $val)
- {
- $this->set_item($key, $val);
- }
- }
- }
-
}
/* End of file Config.php */
View
2 system/core/Exceptions.php
@@ -130,7 +130,7 @@ public function show_404($page = '', $log_error = TRUE)
* @param string $heading Page heading
* @param string|string[] $message Error message
* @param string $template Template name
- * @param int $statis_code (default: 500)
+ * @param int $status_code (default: 500)
*
* @return string Error page output
*/
View
25 tests/codeigniter/core/Config_test.php
@@ -9,7 +9,7 @@ public function set_up()
// set predictable config values
$this->cfg = array(
'index_page' => 'index.php',
- 'base_url' => 'http://example.com/',
+ 'base_url' => 'http://example.com/',
'subclass_prefix' => 'MY_'
);
$this->ci_set_config($this->cfg);
@@ -38,7 +38,6 @@ public function test_set_item()
$this->assertFalse($this->config->item('not_yet_set'));
$this->config->set_item('not_yet_set', 'is set');
-
$this->assertEquals('is set', $this->config->item('not_yet_set'));
}
@@ -50,7 +49,6 @@ public function test_slash_item()
$this->assertFalse($this->config->slash_item('no_good_item'));
$this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url'));
-
$this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix'));
}
@@ -124,7 +122,7 @@ public function test_site_url()
$q_string = $this->config->item('enable_query_strings');
$this->config->set_item('enable_query_strings', FALSE);
- $uri= 'test';
+ $uri = 'test';
$uri2 = '1';
$this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri));
$this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2)));
@@ -137,7 +135,6 @@ public function test_site_url()
$this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg));
$this->config->set_item('url_suffix', FALSE);
-
$this->config->set_item('enable_query_strings', TRUE);
$this->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri));
@@ -233,22 +230,4 @@ public function test_load_nonexistent()
$this->assertNull($this->config->load($file));
}
- // --------------------------------------------------------------------
-
- public function test_assign_to_config()
- {
- $key1 = 'test';
- $key2 = '1';
- $val1 = 'foo';
- $val2 = 'bar';
- $cfg = array(
- $key1 => $val1,
- $key2 => $val2
- );
-
- $this->assertNull($this->config->_assign_to_config($cfg));
- $this->assertEquals($val1, $this->config->item($key1));
- $this->assertEquals($val2, $this->config->item($key2));
- }
-
}
View
8 user_guide_src/source/changelog.rst
@@ -236,8 +236,8 @@ Release Date: Not Released
- Added method ``get_vars()`` to the Loader to retrieve all variables loaded with ``$this->load->vars()``.
- ``CI_Loader::_ci_autoloader()`` is now a protected method.
- Added autoloading of drivers with ``$autoload['drivers']``.
- - ``CI_Loader::library()`` will now load drivers as well, for backward compatibility of converted libraries (like Session).
- - ``$config['rewrite_short_tags']`` now has no effect when using PHP 5.4 as *<?=* will always be available.
+ - ``CI_Loader::library()`` will now load drivers as well, for backward compatibility of converted libraries (like :doc:`Session <libraries/sessions>`).
+ - ``$config['rewrite_short_tags']`` now has no effect when using PHP 5.4 as ``<?=`` will always be available.
- :doc:`Input Library <libraries/input>` changes include:
- Added ``method()`` to retrieve ``$_SERVER['REQUEST_METHOD']``.
- Modified ``valid_ip()`` to use PHP's ``filter_var()``.
@@ -254,7 +254,9 @@ Release Date: Not Released
- Added method ``get_content_type()``.
- Added a second argument to method ``set_content_type()`` that allows setting the document charset as well.
- ``$config['time_reference']`` now supports all timezone strings supported by PHP.
- - Changed :doc:`Config Library <libraries/config>` method ``site_url()`` to accept an array as well.
+ - :doc:`Config Library <libraries/config>` changes include:
+ - Changed ``site_url()`` method to accept an array as well.
+ - Removed internal method ``_assign_to_config()`` and moved it's implementation in *CodeIgniter.php* instead.
- :doc:`Security Library <libraries/security>` changes include:
- Added method ``strip_image_tags()``.
- Added ``$config['csrf_regeneration']``, which makes token regeneration optional.

0 comments on commit 5232ba0

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