blob: 051d3d899831b29e5474e4a6000b1e8e6a9d8f60 [file] [log] [blame]
Derek Allard29eff532007-02-05 23:55:06 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
Derek Allardd2df9bc2007-04-15 17:41:17 +00003 * CodeIgniter
Derek Allard29eff532007-02-05 23:55:06 +00004 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Allard6838f002007-10-04 19:29:59 +000010 * @license http://www.codeigniter.com/user_guide/license.html
Derek Allard29eff532007-02-05 23:55:06 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Loader Class
20 *
21 * Loads views and files
22 *
23 * @package CodeIgniter
24 * @subpackage Libraries
25 * @author Rick Ellis
26 * @category Loader
27 * @link http://www.codeigniter.com/user_guide/libraries/loader.html
28 */
29class CI_Loader {
30
31 // All these are set automatically. Don't mess with them.
32 var $_ci_ob_level;
33 var $_ci_view_path = '';
34 var $_ci_is_php5 = FALSE;
35 var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance()
36 var $_ci_cached_vars = array();
37 var $_ci_classes = array();
38 var $_ci_models = array();
39 var $_ci_helpers = array();
40 var $_ci_plugins = array();
41 var $_ci_scripts = array();
42 var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
43
44
45 /**
46 * Constructor
47 *
48 * Sets the path to the view files and gets the initial output buffering level
49 *
50 * @access public
51 */
52 function CI_Loader()
53 {
54 $this->_ci_is_php5 = (floor(phpversion()) >= 5) ? TRUE : FALSE;
55 $this->_ci_view_path = APPPATH.'views/';
56 $this->_ci_ob_level = ob_get_level();
57
58 log_message('debug', "Loader Class Initialized");
59 }
60
61 // --------------------------------------------------------------------
62
63 /**
64 * Class Loader
65 *
66 * This function lets users load and instantiate classes.
67 * It is designed to be called from a user's app controllers.
68 *
69 * @access public
70 * @param string the name of the class
71 * @param mixed the optional parameters
72 * @return void
73 */
74 function library($library = '', $params = NULL)
75 {
76 if ($library == '')
77 {
78 return FALSE;
79 }
80
81 if (is_array($library))
82 {
83 foreach ($library as $class)
84 {
85 $this->_ci_load_class($class, $params);
86 }
87 }
88 else
89 {
90 $this->_ci_load_class($library, $params);
91 }
92
93 $this->_ci_assign_to_models();
94 }
95
96 // --------------------------------------------------------------------
97
98 /**
99 * Model Loader
100 *
101 * This function lets users load and instantiate models.
102 *
103 * @access public
104 * @param string the name of the class
105 * @param mixed any initialization parameters
106 * @return void
107 */
108 function model($model, $name = '', $db_conn = FALSE)
109 {
110 if ($model == '')
111 return;
112
113 // Is the model in a sub-folder? If so, parse out the filename and path.
114 if (strpos($model, '/') === FALSE)
115 {
116 $path = '';
117 }
118 else
119 {
120 $x = explode('/', $model);
121 $model = end($x);
122 unset($x[count($x)-1]);
123 $path = implode('/', $x).'/';
124 }
125
126 if ($name == '')
127 {
128 $name = $model;
129 }
130
131 if (in_array($name, $this->_ci_models, TRUE))
132 {
133 return;
134 }
135
136 $CI =& get_instance();
137 if (isset($CI->$name))
138 {
139 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
140 }
141
142 $model = strtolower($model);
143
144 if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT))
145 {
146 show_error('Unable to locate the model you have specified: '.$model);
147 }
148
149 if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
150 {
151 if ($db_conn === TRUE)
152 $db_conn = '';
153
154 $CI->load->database($db_conn, FALSE, TRUE);
155 }
156
Derek Allardac0eb452007-02-15 18:42:22 +0000157 if ( ! class_exists('Model'))
158 {
159 require_once(BASEPATH.'libraries/Model'.EXT);
160 }
Derek Allard29eff532007-02-05 23:55:06 +0000161
162 require_once(APPPATH.'models/'.$path.$model.EXT);
163
164 $model = ucfirst($model);
165
166 $CI->$name = new $model();
167 $CI->$name->_assign_libraries();
168
169 $this->_ci_models[] = $name;
170 }
171
172 // --------------------------------------------------------------------
173
174 /**
175 * Database Loader
176 *
177 * @access public
178 * @param string the DB credentials
179 * @param bool whether to return the DB object
180 * @param bool whether to enable active record (this allows us to override the config setting)
181 * @return object
182 */
183 function database($params = '', $return = FALSE, $active_record = FALSE)
184 {
185 // Do we even need to load the database class?
186 if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE)
187 {
188 return FALSE;
189 }
190
191 require_once(BASEPATH.'database/DB'.EXT);
192
193 if ($return === TRUE)
194 {
195 return DB($params, $active_record);
196 }
197
198 // Grab the super object
199 $CI =& get_instance();
200
201 // Initialize the db variable. Needed to prevent
202 // reference errors with some configurations
203 $CI->db = '';
204
205 // Load the DB class
206 $CI->db =& DB($params, $active_record);
207
208 // Assign the DB object to any existing models
209 $this->_ci_assign_to_models();
210 }
211
212 // --------------------------------------------------------------------
213
214 /**
215 * Load the Utilities Class
216 *
217 * @access public
218 * @return string
219 */
220 function dbutil()
221 {
222 if ( ! class_exists('CI_DB'))
223 {
224 $this->database();
225 }
226
227 $CI =& get_instance();
228
229 require_once(BASEPATH.'database/DB_utility'.EXT);
230 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
231 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
232
233 $CI->dbutil = new $class();
234 $CI->load->_ci_assign_to_models();
235 }
236
237 // --------------------------------------------------------------------
238
239 /**
240 * Load View
241 *
242 * This function is used to load a "view" file. It has three parameters:
243 *
244 * 1. The name of the "view" file to be included.
245 * 2. An associative array of data to be extracted for use in the view.
246 * 3. TRUE/FALSE - whether to return the data or load it. In
247 * some cases it's advantageous to be able to return data so that
248 * a developer can process it in some way.
249 *
250 * @access public
251 * @param string
252 * @param array
253 * @param bool
254 * @return void
255 */
256 function view($view, $vars = array(), $return = FALSE)
257 {
258 return $this->_ci_load(array('view' => $view, 'vars' => $this->_ci_object_to_array($vars), 'return' => $return));
259 }
260
261 // --------------------------------------------------------------------
262
263 /**
264 * Load File
265 *
266 * This is a generic file loader
267 *
268 * @access public
269 * @param string
270 * @param bool
271 * @return string
272 */
273 function file($path, $return = FALSE)
274 {
275 return $this->_ci_load(array('path' => $path, 'return' => $return));
276 }
277
278 // --------------------------------------------------------------------
279
280 /**
281 * Set Variables
282 *
283 * Once variables are set they become available within
284 * the controller class and its "view" files.
285 *
286 * @access public
287 * @param array
288 * @return void
289 */
290 function vars($vars = array())
291 {
292 $vars = $this->_ci_object_to_array($vars);
293
294 if (is_array($vars) AND count($vars) > 0)
295 {
296 foreach ($vars as $key => $val)
297 {
298 $this->_ci_cached_vars[$key] = $val;
299 }
300 }
301 }
302
303 // --------------------------------------------------------------------
304
305 /**
306 * Load Helper
307 *
308 * This function loads the specified helper file.
309 *
310 * @access public
311 * @param mixed
312 * @return void
313 */
314 function helper($helpers = array())
315 {
316 if ( ! is_array($helpers))
317 {
318 $helpers = array($helpers);
319 }
320
321 foreach ($helpers as $helper)
322 {
323 $helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');
324
325 if (isset($this->_ci_helpers[$helper]))
326 {
327 continue;
328 }
329
330 if (file_exists(APPPATH.'helpers/'.$helper.EXT))
331 {
332 include_once(APPPATH.'helpers/'.$helper.EXT);
333 }
334 else
335 {
336 if (file_exists(BASEPATH.'helpers/'.$helper.EXT))
337 {
338 include(BASEPATH.'helpers/'.$helper.EXT);
339 }
340 else
341 {
342 show_error('Unable to load the requested file: helpers/'.$helper.EXT);
343 }
344 }
345
346 $this->_ci_helpers[$helper] = TRUE;
347
348 }
349
350 log_message('debug', 'Helpers loaded: '.implode(', ', $helpers));
351 }
352
353 // --------------------------------------------------------------------
354
355 /**
356 * Load Helpers
357 *
358 * This is simply an alias to the above function in case the
359 * user has written the plural form of this function.
360 *
361 * @access public
362 * @param array
363 * @return void
364 */
365 function helpers($helpers = array())
366 {
367 $this->helper($helpers);
368 }
369
370 // --------------------------------------------------------------------
371
372 /**
373 * Load Plugin
374 *
375 * This function loads the specified plugin.
376 *
377 * @access public
378 * @param array
379 * @return void
380 */
381 function plugin($plugins = array())
382 {
383 if ( ! is_array($plugins))
384 {
385 $plugins = array($plugins);
386 }
387
388 foreach ($plugins as $plugin)
389 {
390 $plugin = strtolower(str_replace(EXT, '', str_replace('_plugin.', '', $plugin)).'_pi');
391
392 if (isset($this->_ci_plugins[$plugin]))
393 {
394 continue;
395 }
396
397 if (file_exists(APPPATH.'plugins/'.$plugin.EXT))
398 {
399 include(APPPATH.'plugins/'.$plugin.EXT);
400 }
401 else
402 {
403 if (file_exists(BASEPATH.'plugins/'.$plugin.EXT))
404 {
405 include(BASEPATH.'plugins/'.$plugin.EXT);
406 }
407 else
408 {
409 show_error('Unable to load the requested file: plugins/'.$plugin.EXT);
410 }
411 }
412
413 $this->_ci_plugins[$plugin] = TRUE;
414 }
415
416 log_message('debug', 'Plugins loaded: '.implode(', ', $plugins));
417 }
418
419 // --------------------------------------------------------------------
420
421 /**
422 * Load Plugins
423 *
424 * This is simply an alias to the above function in case the
425 * user has written the plural form of this function.
426 *
427 * @access public
428 * @param array
429 * @return void
430 */
431 function plugins($plugins = array())
432 {
433 $this->plugin($plugins);
434 }
435
436 // --------------------------------------------------------------------
437
438 /**
439 * Load Script
440 *
441 * This function loads the specified include file from the
442 * application/scripts/ folder.
443 *
444 * NOTE: This feature has been deprecated but it will remain available
445 * for legacy users.
446 *
447 * @access public
448 * @param array
449 * @return void
450 */
451 function script($scripts = array())
452 {
453 if ( ! is_array($scripts))
454 {
455 $scripts = array($scripts);
456 }
457
458 foreach ($scripts as $script)
459 {
460 $script = strtolower(str_replace(EXT, '', $script));
461
462 if (isset($this->_ci_scripts[$script]))
463 {
464 continue;
465 }
466
467 if ( ! file_exists(APPPATH.'scripts/'.$script.EXT))
468 {
469 show_error('Unable to load the requested script: scripts/'.$script.EXT);
470 }
471
472 include(APPPATH.'scripts/'.$script.EXT);
473 }
474
475 log_message('debug', 'Scripts loaded: '.implode(', ', $scripts));
476 }
477
478 // --------------------------------------------------------------------
479
480 /**
481 * Loads a language file
482 *
483 * @access public
Derek Allardc9e2b102007-07-12 12:14:45 +0000484 * @param array
Derek Allard29eff532007-02-05 23:55:06 +0000485 * @param string
486 * @return void
487 */
Derek Allardc9e2b102007-07-12 12:14:45 +0000488 function language($file = array(), $lang = '')
Derek Allard29eff532007-02-05 23:55:06 +0000489 {
490 $CI =& get_instance();
Derek Allardc9e2b102007-07-12 12:14:45 +0000491
492 if ( ! is_array($file))
493 {
494 $file = array($file);
495 }
496
497 foreach ($file as $langfile)
498 {
499 $CI->lang->load($langfile, $lang);
500 }
Derek Allard29eff532007-02-05 23:55:06 +0000501 }
Derek Allard873c7222007-07-15 23:03:05 +0000502
503 /**
Derek Allard5808a112007-07-15 23:19:08 +0000504 * Loads language files for scaffolding
Derek Allard873c7222007-07-15 23:03:05 +0000505 *
506 * @access public
507 * @param string
Derek Allard5808a112007-07-15 23:19:08 +0000508 * @return arra
Derek Allard873c7222007-07-15 23:03:05 +0000509 */
510 function scaffold_language($file = '', $lang = '', $return = FALSE)
511 {
512 $CI =& get_instance();
513 return $CI->lang->load($file, $lang, $return);
514 }
Derek Allard29eff532007-02-05 23:55:06 +0000515
516 // --------------------------------------------------------------------
517
518 /**
519 * Loads a config file
520 *
521 * @access public
522 * @param string
523 * @return void
524 */
525 function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
526 {
527 $CI =& get_instance();
528 $CI->config->load($file, $use_sections, $fail_gracefully);
529 }
530
531 // --------------------------------------------------------------------
532
533 /**
534 * Scaffolding Loader
535 *
536 * This initializing function works a bit different than the
537 * others. It doesn't load the class. Instead, it simply
538 * sets a flag indicating that scaffolding is allowed to be
539 * used. The actual scaffolding function below is
540 * called by the front controller based on whether the
541 * second segment of the URL matches the "secret" scaffolding
542 * word stored in the application/config/routes.php
543 *
544 * @access public
545 * @param string
546 * @return void
547 */
548 function scaffolding($table = '')
549 {
550 if ($table === FALSE)
551 {
Derek Allard655bc022007-02-06 23:45:33 +0000552 show_error('You must include the name of the table you would like to access when you initialize scaffolding');
Derek Allard29eff532007-02-05 23:55:06 +0000553 }
554
555 $CI =& get_instance();
556 $CI->_ci_scaffolding = TRUE;
557 $CI->_ci_scaff_table = $table;
558 }
559
560 // --------------------------------------------------------------------
561
562 /**
563 * Loader
564 *
565 * This function is used to load views and files.
566 *
567 * @access private
568 * @param array
569 * @return void
570 */
571 function _ci_load($data)
572 {
573 // Set the default data variables
574 foreach (array('view', 'vars', 'path', 'return') as $val)
575 {
576 $$val = ( ! isset($data[$val])) ? FALSE : $data[$val];
577 }
578
579 // Set the path to the requested file
580 if ($path == '')
581 {
582 $ext = pathinfo($view, PATHINFO_EXTENSION);
583 $file = ($ext == '') ? $view.EXT : $view;
584 $path = $this->_ci_view_path.$file;
585 }
586 else
587 {
588 $x = explode('/', $path);
589 $file = end($x);
590 }
591
592 if ( ! file_exists($path))
593 {
594 show_error('Unable to load the requested file: '.$file);
595 }
596
597 // This allows anything loaded using $this->load (views, files, etc.)
598 // to become accessible from within the Controller and Model functions.
599 // Only needed when running PHP 5
600
601 if ($this->_ci_is_instance())
602 {
603 $CI =& get_instance();
604 foreach (get_object_vars($CI) as $key => $var)
605 {
606 if ( ! isset($this->$key))
607 {
608 $this->$key =& $CI->$key;
609 }
610 }
611 }
612
613 /*
614 * Extract and cache variables
615 *
616 * You can either set variables using the dedicated $this->load_vars()
617 * function or via the second parameter of this function. We'll merge
618 * the two types and cache them so that views that are embedded within
619 * other views can have access to these variables.
620 */
621 if (is_array($vars))
622 {
623 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars);
624 }
625 extract($this->_ci_cached_vars);
626
627 /*
628 * Buffer the output
629 *
630 * We buffer the output for two reasons:
631 * 1. Speed. You get a significant speed boost.
632 * 2. So that the final rendered template can be
633 * post-processed by the output class. Why do we
634 * need post processing? For one thing, in order to
635 * show the elapsed page load time. Unless we
636 * can intercept the content right before it's sent to
637 * the browser and then stop the timer it won't be accurate.
638 */
639 ob_start();
640
641 // If the PHP installation does not support short tags we'll
642 // do a little string replacement, changing the short tags
643 // to standard PHP echo statements.
644
645 if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
646 {
647 echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($path))).'<?php ');
648 }
649 else
650 {
651 include($path);
652 }
653
654 log_message('debug', 'File loaded: '.$path);
655
656 // Return the file data if requested
657 if ($return === TRUE)
658 {
659 $buffer = ob_get_contents();
660 @ob_end_clean();
661 return $buffer;
662 }
663
664 /*
665 * Flush the buffer... or buff the flusher?
666 *
667 * In order to permit views to be nested within
668 * other views, we need to flush the content back out whenever
669 * we are beyond the first level of output buffering so that
670 * it can be seen and included properly by the first included
671 * template and any subsequent ones. Oy!
672 *
673 */
674 if (ob_get_level() > $this->_ci_ob_level + 1)
675 {
676 ob_end_flush();
677 }
678 else
679 {
680 // PHP 4 requires that we use a global
681 global $OUT;
682 $OUT->set_output(ob_get_contents());
683 @ob_end_clean();
684 }
685 }
686
687 // --------------------------------------------------------------------
688
689 /**
690 * Load class
691 *
692 * This function loads the requested class.
693 *
694 * @access private
695 * @param string the item that is being loaded
696 * @param mixed any additional parameters
697 * @return void
698 */
699 function _ci_load_class($class, $params = NULL)
700 {
701 // Get the class name
702 $class = str_replace(EXT, '', $class);
703
704 // We'll test for both lowercase and capitalized versions of the file name
705 foreach (array(ucfirst($class), strtolower($class)) as $class)
706 {
Rick Ellis8c501b32007-06-09 01:13:36 +0000707 $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT;
708
709 // Is this a class extension request?
710 if (file_exists($subclass))
Derek Allard29eff532007-02-05 23:55:06 +0000711 {
Rick Ellis8c501b32007-06-09 01:13:36 +0000712 $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
713
714 if ( ! file_exists($baseclass))
Derek Allard29eff532007-02-05 23:55:06 +0000715 {
716 log_message('error', "Unable to load the requested class: ".$class);
717 show_error("Unable to load the requested class: ".$class);
718 }
Rick Ellis8c501b32007-06-09 01:13:36 +0000719
720 // Safety: Was the class already loaded by a previous call?
721 if (in_array($subclass, $this->_ci_classes))
722 {
723 $is_duplicate = TRUE;
724 log_message('debug', $class." class already loaded. Second attempt ignored.");
725 return;
726 }
Derek Allard29eff532007-02-05 23:55:06 +0000727
Rick Ellis8c501b32007-06-09 01:13:36 +0000728 include($baseclass);
729 include($subclass);
730 $this->_ci_classes[] = $subclass;
Derek Allard29eff532007-02-05 23:55:06 +0000731
732 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params);
733 }
734
735 // Lets search for the requested library file and load it.
Derek Allard4dde0de2007-02-14 22:44:36 +0000736 $is_duplicate = FALSE;
Derek Allard29eff532007-02-05 23:55:06 +0000737 for ($i = 1; $i < 3; $i++)
738 {
739 $path = ($i % 2) ? APPPATH : BASEPATH;
Rick Ellis8c501b32007-06-09 01:13:36 +0000740 $filepath = $path.'libraries/'.$class.EXT;
Derek Allard29eff532007-02-05 23:55:06 +0000741
742 // Does the file exist? No? Bummer...
Rick Ellis8c501b32007-06-09 01:13:36 +0000743 if ( ! file_exists($filepath))
Derek Allard29eff532007-02-05 23:55:06 +0000744 {
745 continue;
746 }
747
748 // Safety: Was the class already loaded by a previous call?
Rick Ellis8c501b32007-06-09 01:13:36 +0000749 if (in_array($filepath, $this->_ci_classes))
Derek Allard29eff532007-02-05 23:55:06 +0000750 {
Derek Allard4dde0de2007-02-14 22:44:36 +0000751 $is_duplicate = TRUE;
Derek Allard29eff532007-02-05 23:55:06 +0000752 log_message('debug', $class." class already loaded. Second attempt ignored.");
753 return;
754 }
755
Rick Ellis8c501b32007-06-09 01:13:36 +0000756 include($filepath);
757 $this->_ci_classes[] = $filepath;
Derek Allard29eff532007-02-05 23:55:06 +0000758 return $this->_ci_init_class($class, '', $params);
759 }
760 } // END FOREACH
761
762 // If we got this far we were unable to find the requested class.
763 // We do not issue errors if the load call failed due to a duplicate request
764 if ($is_duplicate == FALSE)
765 {
766 log_message('error', "Unable to load the requested class: ".$class);
767 show_error("Unable to load the requested class: ".$class);
768 }
769 }
770
771 // --------------------------------------------------------------------
772
773 /**
774 * Instantiates a class
775 *
776 * @access private
777 * @param string
778 * @param string
779 * @return null
780 */
781 function _ci_init_class($class, $prefix = '', $config = FALSE)
782 {
783 // Is there an associated config file for this class?
784 if ($config === NULL)
785 {
786 $config = NULL;
787 if (file_exists(APPPATH.'config/'.$class.EXT))
788 {
789 include(APPPATH.'config/'.$class.EXT);
790 }
791 }
792
793 if ($prefix == '')
794 {
795 $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class;
796 }
797 else
798 {
799 $name = $prefix.$class;
800 }
801
802 // Set the variable name we will assign the class to
803 $class = strtolower($class);
804 $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
805
806 // Instantiate the class
807 $CI =& get_instance();
808 if ($config !== NULL)
809 {
810 $CI->$classvar = new $name($config);
811 }
812 else
813 {
814 $CI->$classvar = new $name;
815 }
816 }
817
818 // --------------------------------------------------------------------
819
820 /**
821 * Autoloader
822 *
823 * The config/autoload.php file contains an array that permits sub-systems,
824 * libraries, plugins, and helpers to be loaded automatically.
825 *
826 * @access private
827 * @param array
828 * @return void
829 */
830 function _ci_autoloader()
831 {
832 include(APPPATH.'config/autoload'.EXT);
833
834 if ( ! isset($autoload))
835 {
836 return FALSE;
837 }
838
Derek Allardc9e2b102007-07-12 12:14:45 +0000839 // Load any custom config file
Derek Allard29eff532007-02-05 23:55:06 +0000840 if (count($autoload['config']) > 0)
841 {
842 $CI =& get_instance();
843 foreach ($autoload['config'] as $key => $val)
844 {
845 $CI->config->load($val);
846 }
847 }
848
Derek Allardc9e2b102007-07-12 12:14:45 +0000849 // Autoload plugins, helpers, scripts and languages
850 foreach (array('helper', 'plugin', 'script', 'language') as $type)
851 {
Derek Allard29eff532007-02-05 23:55:06 +0000852 if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
853 {
854 $this->$type($autoload[$type]);
855 }
856 }
Derek Allardc9e2b102007-07-12 12:14:45 +0000857
Derek Allard29eff532007-02-05 23:55:06 +0000858 // A little tweak to remain backward compatible
859 // The $autoload['core'] item was deprecated
860 if ( ! isset($autoload['libraries']))
861 {
862 $autoload['libraries'] = $autoload['core'];
863 }
864
865 // Load libraries
866 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
867 {
868 // Load the database driver.
869 if (in_array('database', $autoload['libraries']))
870 {
871 $this->database();
872 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
873 }
874
875 // Load the model class.
876 if (in_array('model', $autoload['libraries']))
877 {
878 $this->model();
879 $autoload['libraries'] = array_diff($autoload['libraries'], array('model'));
880 }
881
882 // Load scaffolding
883 if (in_array('scaffolding', $autoload['libraries']))
884 {
885 $this->scaffolding();
886 $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding'));
887 }
888
889 // Load all other libraries
890 foreach ($autoload['libraries'] as $item)
891 {
892 $this->library($item);
893 }
894 }
895 }
896
897 // --------------------------------------------------------------------
898
899 /**
900 * Assign to Models
901 *
902 * Makes sure that anything loaded by the loader class (libraries, plugins, etc.)
903 * will be available to models, if any exist.
904 *
905 * @access private
906 * @param object
907 * @return array
908 */
909 function _ci_assign_to_models()
910 {
911 if (count($this->_ci_models) == 0)
912 {
913 return;
914 }
915
916 if ($this->_ci_is_instance())
917 {
918 $CI =& get_instance();
919 foreach ($this->_ci_models as $model)
920 {
921 $CI->$model->_assign_libraries();
922 }
923 }
924 else
925 {
926 foreach ($this->_ci_models as $model)
927 {
928 $this->$model->_assign_libraries();
929 }
930 }
931 }
932
933 // --------------------------------------------------------------------
934
935 /**
936 * Object to Array
937 *
938 * Takes an object as input and converts the class variables to array key/vals
939 *
940 * @access private
941 * @param object
942 * @return array
943 */
944 function _ci_object_to_array($object)
945 {
946 return (is_object($object)) ? get_object_vars($object) : $object;
947 }
948
949 // --------------------------------------------------------------------
950
951 /**
952 * Determines whether we should use the CI instance or $this
953 *
954 * @access private
955 * @return bool
956 */
957 function _ci_is_instance()
958 {
959 if ($this->_ci_is_php5 == TRUE)
960 {
961 return TRUE;
962 }
963
964 global $CI;
965 return (is_object($CI)) ? TRUE : FALSE;
966 }
967
968}
adminb0dd10f2006-08-25 17:25:49 +0000969?>