blob: ee99696a024178099982d77bae23a11b7f16ab3d [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 Allard29eff532007-02-05 23:55:06 +000010 * @license http://www.codeignitor.com/user_guide/license.html
11 * @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
Derek Allardc9e2b102007-07-12 12:14:45 +0000486 * @param bool
Derek Allard29eff532007-02-05 23:55:06 +0000487 * @return void
488 */
Derek Allardc9e2b102007-07-12 12:14:45 +0000489 function language($file = array(), $lang = '')
Derek Allard29eff532007-02-05 23:55:06 +0000490 {
491 $CI =& get_instance();
Derek Allardc9e2b102007-07-12 12:14:45 +0000492
493 if ( ! is_array($file))
494 {
495 $file = array($file);
496 }
497
498 foreach ($file as $langfile)
499 {
500 $CI->lang->load($langfile, $lang);
501 }
Derek Allard29eff532007-02-05 23:55:06 +0000502 }
Derek Allard873c7222007-07-15 23:03:05 +0000503
504 /**
505 * Loads a language file
506 *
507 * @access public
508 * @param string
509 * @return void
510 */
511 function scaffold_language($file = '', $lang = '', $return = FALSE)
512 {
513 $CI =& get_instance();
514 return $CI->lang->load($file, $lang, $return);
515 }
Derek Allard29eff532007-02-05 23:55:06 +0000516
517 // --------------------------------------------------------------------
518
519 /**
520 * Loads a config file
521 *
522 * @access public
523 * @param string
524 * @return void
525 */
526 function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
527 {
528 $CI =& get_instance();
529 $CI->config->load($file, $use_sections, $fail_gracefully);
530 }
531
532 // --------------------------------------------------------------------
533
534 /**
535 * Scaffolding Loader
536 *
537 * This initializing function works a bit different than the
538 * others. It doesn't load the class. Instead, it simply
539 * sets a flag indicating that scaffolding is allowed to be
540 * used. The actual scaffolding function below is
541 * called by the front controller based on whether the
542 * second segment of the URL matches the "secret" scaffolding
543 * word stored in the application/config/routes.php
544 *
545 * @access public
546 * @param string
547 * @return void
548 */
549 function scaffolding($table = '')
550 {
551 if ($table === FALSE)
552 {
Derek Allard655bc022007-02-06 23:45:33 +0000553 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 +0000554 }
555
556 $CI =& get_instance();
557 $CI->_ci_scaffolding = TRUE;
558 $CI->_ci_scaff_table = $table;
559 }
560
561 // --------------------------------------------------------------------
562
563 /**
564 * Loader
565 *
566 * This function is used to load views and files.
567 *
568 * @access private
569 * @param array
570 * @return void
571 */
572 function _ci_load($data)
573 {
574 // Set the default data variables
575 foreach (array('view', 'vars', 'path', 'return') as $val)
576 {
577 $$val = ( ! isset($data[$val])) ? FALSE : $data[$val];
578 }
579
580 // Set the path to the requested file
581 if ($path == '')
582 {
583 $ext = pathinfo($view, PATHINFO_EXTENSION);
584 $file = ($ext == '') ? $view.EXT : $view;
585 $path = $this->_ci_view_path.$file;
586 }
587 else
588 {
589 $x = explode('/', $path);
590 $file = end($x);
591 }
592
593 if ( ! file_exists($path))
594 {
595 show_error('Unable to load the requested file: '.$file);
596 }
597
598 // This allows anything loaded using $this->load (views, files, etc.)
599 // to become accessible from within the Controller and Model functions.
600 // Only needed when running PHP 5
601
602 if ($this->_ci_is_instance())
603 {
604 $CI =& get_instance();
605 foreach (get_object_vars($CI) as $key => $var)
606 {
607 if ( ! isset($this->$key))
608 {
609 $this->$key =& $CI->$key;
610 }
611 }
612 }
613
614 /*
615 * Extract and cache variables
616 *
617 * You can either set variables using the dedicated $this->load_vars()
618 * function or via the second parameter of this function. We'll merge
619 * the two types and cache them so that views that are embedded within
620 * other views can have access to these variables.
621 */
622 if (is_array($vars))
623 {
624 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars);
625 }
626 extract($this->_ci_cached_vars);
627
628 /*
629 * Buffer the output
630 *
631 * We buffer the output for two reasons:
632 * 1. Speed. You get a significant speed boost.
633 * 2. So that the final rendered template can be
634 * post-processed by the output class. Why do we
635 * need post processing? For one thing, in order to
636 * show the elapsed page load time. Unless we
637 * can intercept the content right before it's sent to
638 * the browser and then stop the timer it won't be accurate.
639 */
640 ob_start();
641
642 // If the PHP installation does not support short tags we'll
643 // do a little string replacement, changing the short tags
644 // to standard PHP echo statements.
645
646 if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
647 {
648 echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($path))).'<?php ');
649 }
650 else
651 {
652 include($path);
653 }
654
655 log_message('debug', 'File loaded: '.$path);
656
657 // Return the file data if requested
658 if ($return === TRUE)
659 {
660 $buffer = ob_get_contents();
661 @ob_end_clean();
662 return $buffer;
663 }
664
665 /*
666 * Flush the buffer... or buff the flusher?
667 *
668 * In order to permit views to be nested within
669 * other views, we need to flush the content back out whenever
670 * we are beyond the first level of output buffering so that
671 * it can be seen and included properly by the first included
672 * template and any subsequent ones. Oy!
673 *
674 */
675 if (ob_get_level() > $this->_ci_ob_level + 1)
676 {
677 ob_end_flush();
678 }
679 else
680 {
681 // PHP 4 requires that we use a global
682 global $OUT;
683 $OUT->set_output(ob_get_contents());
684 @ob_end_clean();
685 }
686 }
687
688 // --------------------------------------------------------------------
689
690 /**
691 * Load class
692 *
693 * This function loads the requested class.
694 *
695 * @access private
696 * @param string the item that is being loaded
697 * @param mixed any additional parameters
698 * @return void
699 */
700 function _ci_load_class($class, $params = NULL)
701 {
702 // Get the class name
703 $class = str_replace(EXT, '', $class);
704
705 // We'll test for both lowercase and capitalized versions of the file name
706 foreach (array(ucfirst($class), strtolower($class)) as $class)
707 {
Rick Ellis8c501b32007-06-09 01:13:36 +0000708 $subclass = APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT;
709
710 // Is this a class extension request?
711 if (file_exists($subclass))
Derek Allard29eff532007-02-05 23:55:06 +0000712 {
Rick Ellis8c501b32007-06-09 01:13:36 +0000713 $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
714
715 if ( ! file_exists($baseclass))
Derek Allard29eff532007-02-05 23:55:06 +0000716 {
717 log_message('error', "Unable to load the requested class: ".$class);
718 show_error("Unable to load the requested class: ".$class);
719 }
Rick Ellis8c501b32007-06-09 01:13:36 +0000720
721 // Safety: Was the class already loaded by a previous call?
722 if (in_array($subclass, $this->_ci_classes))
723 {
724 $is_duplicate = TRUE;
725 log_message('debug', $class." class already loaded. Second attempt ignored.");
726 return;
727 }
Derek Allard29eff532007-02-05 23:55:06 +0000728
Rick Ellis8c501b32007-06-09 01:13:36 +0000729 include($baseclass);
730 include($subclass);
731 $this->_ci_classes[] = $subclass;
Derek Allard29eff532007-02-05 23:55:06 +0000732
733 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params);
734 }
735
736 // Lets search for the requested library file and load it.
Derek Allard4dde0de2007-02-14 22:44:36 +0000737 $is_duplicate = FALSE;
Derek Allard29eff532007-02-05 23:55:06 +0000738 for ($i = 1; $i < 3; $i++)
739 {
740 $path = ($i % 2) ? APPPATH : BASEPATH;
Rick Ellis8c501b32007-06-09 01:13:36 +0000741 $filepath = $path.'libraries/'.$class.EXT;
Derek Allard29eff532007-02-05 23:55:06 +0000742
743 // Does the file exist? No? Bummer...
Rick Ellis8c501b32007-06-09 01:13:36 +0000744 if ( ! file_exists($filepath))
Derek Allard29eff532007-02-05 23:55:06 +0000745 {
746 continue;
747 }
748
749 // Safety: Was the class already loaded by a previous call?
Rick Ellis8c501b32007-06-09 01:13:36 +0000750 if (in_array($filepath, $this->_ci_classes))
Derek Allard29eff532007-02-05 23:55:06 +0000751 {
Derek Allard4dde0de2007-02-14 22:44:36 +0000752 $is_duplicate = TRUE;
Derek Allard29eff532007-02-05 23:55:06 +0000753 log_message('debug', $class." class already loaded. Second attempt ignored.");
754 return;
755 }
756
Rick Ellis8c501b32007-06-09 01:13:36 +0000757 include($filepath);
758 $this->_ci_classes[] = $filepath;
Derek Allard29eff532007-02-05 23:55:06 +0000759 return $this->_ci_init_class($class, '', $params);
760 }
761 } // END FOREACH
762
763 // If we got this far we were unable to find the requested class.
764 // We do not issue errors if the load call failed due to a duplicate request
765 if ($is_duplicate == FALSE)
766 {
767 log_message('error', "Unable to load the requested class: ".$class);
768 show_error("Unable to load the requested class: ".$class);
769 }
770 }
771
772 // --------------------------------------------------------------------
773
774 /**
775 * Instantiates a class
776 *
777 * @access private
778 * @param string
779 * @param string
780 * @return null
781 */
782 function _ci_init_class($class, $prefix = '', $config = FALSE)
783 {
784 // Is there an associated config file for this class?
785 if ($config === NULL)
786 {
787 $config = NULL;
788 if (file_exists(APPPATH.'config/'.$class.EXT))
789 {
790 include(APPPATH.'config/'.$class.EXT);
791 }
792 }
793
794 if ($prefix == '')
795 {
796 $name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class;
797 }
798 else
799 {
800 $name = $prefix.$class;
801 }
802
803 // Set the variable name we will assign the class to
804 $class = strtolower($class);
805 $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
806
807 // Instantiate the class
808 $CI =& get_instance();
809 if ($config !== NULL)
810 {
811 $CI->$classvar = new $name($config);
812 }
813 else
814 {
815 $CI->$classvar = new $name;
816 }
817 }
818
819 // --------------------------------------------------------------------
820
821 /**
822 * Autoloader
823 *
824 * The config/autoload.php file contains an array that permits sub-systems,
825 * libraries, plugins, and helpers to be loaded automatically.
826 *
827 * @access private
828 * @param array
829 * @return void
830 */
831 function _ci_autoloader()
832 {
833 include(APPPATH.'config/autoload'.EXT);
834
835 if ( ! isset($autoload))
836 {
837 return FALSE;
838 }
839
Derek Allardc9e2b102007-07-12 12:14:45 +0000840 // Load any custom config file
Derek Allard29eff532007-02-05 23:55:06 +0000841 if (count($autoload['config']) > 0)
842 {
843 $CI =& get_instance();
844 foreach ($autoload['config'] as $key => $val)
845 {
846 $CI->config->load($val);
847 }
848 }
849
Derek Allardc9e2b102007-07-12 12:14:45 +0000850 // Autoload plugins, helpers, scripts and languages
851 foreach (array('helper', 'plugin', 'script', 'language') as $type)
852 {
Derek Allard29eff532007-02-05 23:55:06 +0000853 if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
854 {
855 $this->$type($autoload[$type]);
856 }
857 }
Derek Allardc9e2b102007-07-12 12:14:45 +0000858
Derek Allard29eff532007-02-05 23:55:06 +0000859 // A little tweak to remain backward compatible
860 // The $autoload['core'] item was deprecated
861 if ( ! isset($autoload['libraries']))
862 {
863 $autoload['libraries'] = $autoload['core'];
864 }
865
866 // Load libraries
867 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
868 {
869 // Load the database driver.
870 if (in_array('database', $autoload['libraries']))
871 {
872 $this->database();
873 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
874 }
875
876 // Load the model class.
877 if (in_array('model', $autoload['libraries']))
878 {
879 $this->model();
880 $autoload['libraries'] = array_diff($autoload['libraries'], array('model'));
881 }
882
883 // Load scaffolding
884 if (in_array('scaffolding', $autoload['libraries']))
885 {
886 $this->scaffolding();
887 $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding'));
888 }
889
890 // Load all other libraries
891 foreach ($autoload['libraries'] as $item)
892 {
893 $this->library($item);
894 }
895 }
896 }
897
898 // --------------------------------------------------------------------
899
900 /**
901 * Assign to Models
902 *
903 * Makes sure that anything loaded by the loader class (libraries, plugins, etc.)
904 * will be available to models, if any exist.
905 *
906 * @access private
907 * @param object
908 * @return array
909 */
910 function _ci_assign_to_models()
911 {
912 if (count($this->_ci_models) == 0)
913 {
914 return;
915 }
916
917 if ($this->_ci_is_instance())
918 {
919 $CI =& get_instance();
920 foreach ($this->_ci_models as $model)
921 {
922 $CI->$model->_assign_libraries();
923 }
924 }
925 else
926 {
927 foreach ($this->_ci_models as $model)
928 {
929 $this->$model->_assign_libraries();
930 }
931 }
932 }
933
934 // --------------------------------------------------------------------
935
936 /**
937 * Object to Array
938 *
939 * Takes an object as input and converts the class variables to array key/vals
940 *
941 * @access private
942 * @param object
943 * @return array
944 */
945 function _ci_object_to_array($object)
946 {
947 return (is_object($object)) ? get_object_vars($object) : $object;
948 }
949
950 // --------------------------------------------------------------------
951
952 /**
953 * Determines whether we should use the CI instance or $this
954 *
955 * @access private
956 * @return bool
957 */
958 function _ci_is_instance()
959 {
960 if ($this->_ci_is_php5 == TRUE)
961 {
962 return TRUE;
963 }
964
965 global $CI;
966 return (is_object($CI)) ? TRUE : FALSE;
967 }
968
969}
adminb0dd10f2006-08-25 17:25:49 +0000970?>