Skip to content

Instantly share code, notes, and snippets.

@narfbg
Created February 20, 2014 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narfbg/9111681 to your computer and use it in GitHub Desktop.
Save narfbg/9111681 to your computer and use it in GitHub Desktop.
Simplify CI_Upload::initialize() defaults reset
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 983d832..686f27d 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -301,41 +301,16 @@ class CI_Upload {
*/
public function initialize($config = array())
{
- $defaults = array(
- 'max_size' => 0,
- 'max_width' => 0,
- 'max_height' => 0,
- 'min_width' => 0,
- 'min_height' => 0,
- 'max_filename' => 0,
- 'max_filename_increment' => 100,
- 'allowed_types' => '',
- 'file_temp' => '',
- 'file_name' => '',
- 'orig_name' => '',
- 'file_type' => '',
- 'file_size' => NULL,
- 'file_ext' => '',
- 'file_ext_tolower' => FALSE,
- 'upload_path' => '',
- 'overwrite' => FALSE,
- 'encrypt_name' => FALSE,
- 'is_image' => FALSE,
- 'image_width' => NULL,
- 'image_height' => NULL,
- 'image_type' => '',
- 'image_size_str' => '',
- 'error_msg' => array(),
- 'remove_spaces' => TRUE,
- 'detect_mime' => TRUE,
- 'xss_clean' => FALSE,
- 'mod_mime_fix' => TRUE,
- 'temp_prefix' => 'temp_file_',
- 'client_name' => ''
- );
-
- foreach ($defaults as $key => $val)
+ $defaults = new ReflectionClass($this);
+ $defaults = $defaults->getDefaultProperties();
+
+ foreach (array_keys($defaults) as $key)
{
+ if ($key[0] === '_')
+ {
+ continue;
+ }
+
if (isset($config[$key]))
{
$method = 'set_'.$key;
@@ -350,7 +325,7 @@ class CI_Upload {
}
else
{
- $this->$key = $val;
+ $this->$key = $defaults[$key];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment