PluginProbe
ShiftController Employee Shift Scheduling / 2.2.2
ShiftController Employee Shift Scheduling v2.2.2
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / happ / system / core / Loader.php

Loader.php in ShiftController Employee Shift Scheduling 2.2.2, at happ/system/core/Loader.php

1,251 lines 30.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2 /**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://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 ExpressionEngine Dev Team
26 * @category Loader
27 * @link http://codeigniter.com/user_guide/libraries/loader.html
28 */
29 class CI_Loader {
30
31 // All these are set automatically. Don't mess with them.
32 /**
33 * Nesting level of the output buffering mechanism
34 *
35 * @var int
36 * @access protected
37 */
38 protected $_ci_ob_level;
39 /**
40 * List of paths to load views from
41 *
42 * @var array
43 * @access protected
44 */
45 protected $_ci_view_paths = array();
46 /**
47 * List of paths to load libraries from
48 *
49 * @var array
50 * @access protected
51 */
52 protected $_ci_library_paths = array();
53 /**
54 * List of paths to load models from
55 *
56 * @var array
57 * @access protected
58 */
59 protected $_ci_model_paths = array();
60 /**
61 * List of paths to load helpers from
62 *
63 * @var array
64 * @access protected
65 */
66 protected $_ci_helper_paths = array();
67 /**
68 * List of loaded base classes
69 * Set by the controller class
70 *
71 * @var array
72 * @access protected
73 */
74 protected $_base_classes = array(); // Set by the controller class
75 /**
76 * List of cached variables
77 *
78 * @var array
79 * @access protected
80 */
81 protected $_ci_cached_vars = array();
82 /**
83 * List of loaded classes
84 *
85 * @var array
86 * @access protected
87 */
88 protected $_ci_classes = array();
89 /**
90 * List of loaded files
91 *
92 * @var array
93 * @access protected
94 */
95 protected $_ci_loaded_files = array();
96 /**
97 * List of loaded models
98 *
99 * @var array
100 * @access protected
101 */
102 protected $_ci_models = array();
103 /**
104 * List of loaded helpers
105 *
106 * @var array
107 * @access protected
108 */
109 protected $_ci_helpers = array();
110 /**
111 * List of class name mappings
112 *
113 * @var array
114 * @access protected
115 */
116 protected $_ci_varmap = array('unit_test' => 'unit',
117 'user_agent' => 'agent');
118
119 /**
120 * Constructor
121 *
122 * Sets the path to the view files and gets the initial output buffering level
123 */
124 public function __construct()
125 {
126 $this->_ci_ob_level = ob_get_level();
127 $this->_ci_library_paths = array(APPPATH, BASEPATH);
128 $this->_ci_helper_paths = array(APPPATH, BASEPATH);
129 $this->_ci_model_paths = array(APPPATH);
130 $this->_ci_view_paths = array(APPPATH.'views/' => TRUE);
131
132 log_message('debug', "Loader Class Initialized");
133 }
134
135 // --------------------------------------------------------------------
136
137 /**
138 * Initialize the Loader
139 *
140 * This method is called once in CI_Controller.
141 *
142 * @param array
143 * @return object
144 */
145 public function initialize()
146 {
147 $this->_ci_classes = array();
148 $this->_ci_loaded_files = array();
149 $this->_ci_models = array();
150 $this->_base_classes =& is_loaded();
151
152 $this->_ci_autoloader();
153
154 return $this;
155 }
156
157 // --------------------------------------------------------------------
158
159 /**
160 * Is Loaded
161 *
162 * A utility function to test if a class is in the self::$_ci_classes array.
163 * This function returns the object name if the class tested for is loaded,
164 * and returns FALSE if it isn't.
165 *
166 * It is mainly used in the form_helper -> _get_validation_object()
167 *
168 * @param string class being checked for
169 * @return mixed class object name on the CI SuperObject or FALSE
170 */
171 public function is_loaded($class)
172 {
173 if (isset($this->_ci_classes[$class]))
174 {
175 return $this->_ci_classes[$class];
176 }
177
178 return FALSE;
179 }
180
181 // --------------------------------------------------------------------
182
183 /**
184 * Class Loader
185 *
186 * This function lets users load and instantiate classes.
187 * It is designed to be called from a user's app controllers.
188 *
189 * @param string the name of the class
190 * @param mixed the optional parameters
191 * @param string an optional object name
192 * @return void
193 */
194 public function library($library = '', $params = NULL, $object_name = NULL)
195 {
196 if (is_array($library))
197 {
198 foreach ($library as $class)
199 {
200 $this->library($class, $params);
201 }
202
203 return;
204 }
205
206 if ($library == '' OR isset($this->_base_classes[$library]))
207 {
208 return FALSE;
209 }
210
211 if ( ! is_null($params) && ! is_array($params))
212 {
213 $params = NULL;
214 }
215 $this->_ci_load_class($library, $params, $object_name);
216 }
217
218 // --------------------------------------------------------------------
219
220 /**
221 * Model Loader
222 *
223 * This function lets users load and instantiate models.
224 *
225 * @param string the name of the class
226 * @param string name for the model
227 * @param bool database connection
228 * @return void
229 */
230 public function model($model, $name = '', $db_conn = FALSE)
231 {
232 if (is_array($model))
233 {
234 foreach ($model as $babe)
235 {
236 $this->model($babe);
237 }
238 return;
239 }
240
241 if ($model == '')
242 {
243 return;
244 }
245
246 $path = '';
247
248 // Is the model in a sub-folder? If so, parse out the filename and path.
249 if (($last_slash = strrpos($model, '/')) !== FALSE)
250 {
251 // The path is in front of the last slash
252 $path = substr($model, 0, $last_slash + 1);
253
254 // And the model name behind it
255 $model = substr($model, $last_slash + 1);
256 }
257
258 if ($name == '')
259 {
260 $name = $model;
261 }
262
263 if (in_array($name, $this->_ci_models, TRUE))
264 {
265 return;
266 }
267
268 $CI =& ci_get_instance();
269 if (isset($CI->$name))
270 {
271 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
272 }
273
274 $model = strtolower($model);
275
276 foreach ($this->_ci_model_paths as $mod_path)
277 {
278 if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
279 {
280 continue;
281 }
282
283 if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
284 {
285 if ($db_conn === TRUE)
286 {
287 $db_conn = '';
288 }
289
290 $CI->load->database($db_conn, FALSE, TRUE);
291 }
292
293 if ( ! class_exists('CI_Model'))
294 {
295 load_class('Model', 'core');
296 }
297
298 require_once($mod_path.'models/'.$path.$model.'.php');
299
300 $model = ucfirst($model);
301
302 $CI->$name = new $model();
303
304 $this->_ci_models[] = $name;
305 return;
306 }
307
308 // couldn't find the model
309 show_error('Unable to locate the model you have specified: '.$model);
310 }
311
312 // --------------------------------------------------------------------
313
314 /**
315 * Database Loader
316 *
317 * @param string the DB credentials
318 * @param bool whether to return the DB object
319 * @param bool whether to enable active record (this allows us to override the config setting)
320 * @return object
321 */
322 public function database($params = '', $return = FALSE, $active_record = NULL)
323 {
324 // Grab the super object
325 $CI =& ci_get_instance();
326
327 // Do we even need to load the database class?
328 if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
329 {
330 return FALSE;
331 }
332
333 require_once(BASEPATH.'database/DB.php');
334
335 if ($return === TRUE)
336 {
337 return DB($params, $active_record);
338 }
339
340 // Initialize the db variable. Needed to prevent
341 // reference errors with some configurations
342 $CI->db = '';
343
344 // Load the DB class
345 $CI->db =& DB($params, $active_record);
346 }
347
348 // --------------------------------------------------------------------
349
350 /**
351 * Load the Utilities Class
352 *
353 * @return string
354 */
355 public function dbutil()
356 {
357 if ( ! class_exists('CI_DB'))
358 {
359 $this->database();
360 }
361
362 $CI =& ci_get_instance();
363
364 // for backwards compatibility, load dbforge so we can extend dbutils off it
365 // this use is deprecated and strongly discouraged
366 $CI->load->dbforge();
367
368 require_once(BASEPATH.'database/DB_utility.php');
369 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
370 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
371
372 $CI->dbutil = new $class();
373 }
374
375 // --------------------------------------------------------------------
376
377 /**
378 * Load the Database Forge Class
379 *
380 * @return string
381 */
382 public function dbforge()
383 {
384 if ( ! class_exists('CI_DB'))
385 {
386 $this->database();
387 }
388
389 $CI =& ci_get_instance();
390
391 require_once(BASEPATH.'database/DB_forge.php');
392 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
393 $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
394
395 $CI->dbforge = new $class();
396 }
397
398 // --------------------------------------------------------------------
399
400 /**
401 * Load View
402 *
403 * This function is used to load a "view" file. It has three parameters:
404 *
405 * 1. The name of the "view" file to be included.
406 * 2. An associative array of data to be extracted for use in the view.
407 * 3. TRUE/FALSE - whether to return the data or load it. In
408 * some cases it's advantageous to be able to return data so that
409 * a developer can process it in some way.
410 *
411 * @param string
412 * @param array
413 * @param bool
414 * @return void
415 */
416 public function view($view, $vars = array(), $return = FALSE)
417 {
418 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
419 }
420
421 // --------------------------------------------------------------------
422
423 /**
424 * Load File
425 *
426 * This is a generic file loader
427 *
428 * @param string
429 * @param bool
430 * @return string
431 */
432 public function file($path, $return = FALSE)
433 {
434 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
435 }
436
437 // --------------------------------------------------------------------
438
439 /**
440 * Set Variables
441 *
442 * Once variables are set they become available within
443 * the controller class and its "view" files.
444 *
445 * @param array
446 * @param string
447 * @return void
448 */
449 public function vars($vars = array(), $val = '')
450 {
451 if ($val != '' AND is_string($vars))
452 {
453 $vars = array($vars => $val);
454 }
455
456 $vars = $this->_ci_object_to_array($vars);
457
458 if (is_array($vars) AND count($vars) > 0)
459 {
460 foreach ($vars as $key => $val)
461 {
462 $this->_ci_cached_vars[$key] = $val;
463 }
464 }
465 }
466
467 // --------------------------------------------------------------------
468
469 /**
470 * Get Variable
471 *
472 * Check if a variable is set and retrieve it.
473 *
474 * @param array
475 * @return void
476 */
477 public function get_var($key)
478 {
479 return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
480 }
481
482 // --------------------------------------------------------------------
483
484 /**
485 * Load Helper
486 *
487 * This function loads the specified helper file.
488 *
489 * @param mixed
490 * @return void
491 */
492 public function helper($helpers = array())
493 {
494 foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
495 {
496 if (isset($this->_ci_helpers[$helper]))
497 {
498 continue;
499 }
500
501 $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php';
502 // Is this a helper extension request?
503 if (file_exists($ext_helper))
504 {
505 $base_helper = BASEPATH.'helpers/'.$helper.'.php';
506
507 if ( ! file_exists($base_helper))
508 {
509 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
510 }
511
512 include_once($ext_helper);
513 include_once($base_helper);
514
515 $this->_ci_helpers[$helper] = TRUE;
516 log_message('debug', 'Helper loaded: '.$helper);
517 continue;
518 }
519
520 // Try to load the helper
521 foreach ($this->_ci_helper_paths as $path)
522 {
523 if (file_exists($path.'helpers/'.$helper.'.php'))
524 {
525 include_once($path.'helpers/'.$helper.'.php');
526
527 $this->_ci_helpers[$helper] = TRUE;
528 log_message('debug', 'Helper loaded: '.$helper);
529 break;
530 }
531 }
532
533 // unable to load the helper
534 if ( ! isset($this->_ci_helpers[$helper]))
535 {
536 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
537 }
538 }
539 }
540
541 // --------------------------------------------------------------------
542
543 /**
544 * Load Helpers
545 *
546 * This is simply an alias to the above function in case the
547 * user has written the plural form of this function.
548 *
549 * @param array
550 * @return void
551 */
552 public function helpers($helpers = array())
553 {
554 $this->helper($helpers);
555 }
556
557 // --------------------------------------------------------------------
558
559 /**
560 * Loads a language file
561 *
562 * @param array
563 * @param string
564 * @return void
565 */
566 public function language($file = array(), $lang = '')
567 {
568 $CI =& ci_get_instance();
569
570 if ( ! is_array($file))
571 {
572 $file = array($file);
573 }
574
575 foreach ($file as $langfile)
576 {
577 $CI->lang->load($langfile, $lang);
578 }
579 }
580
581 // --------------------------------------------------------------------
582
583 /**
584 * Loads a config file
585 *
586 * @param string
587 * @param bool
588 * @param bool
589 * @return void
590 */
591 public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
592 {
593 $CI =& ci_get_instance();
594 $CI->config->load($file, $use_sections, $fail_gracefully);
595 }
596
597 // --------------------------------------------------------------------
598
599 /**
600 * Driver
601 *
602 * Loads a driver library
603 *
604 * @param string the name of the class
605 * @param mixed the optional parameters
606 * @param string an optional object name
607 * @return void
608 */
609 public function driver($library = '', $params = NULL, $object_name = NULL)
610 {
611 if ( ! class_exists('CI_Driver_Library'))
612 {
613 // we aren't instantiating an object here, that'll be done by the Library itself
614 require BASEPATH.'libraries/Driver.php';
615 }
616
617 if ($library == '')
618 {
619 return FALSE;
620 }
621
622 // We can save the loader some time since Drivers will *always* be in a subfolder,
623 // and typically identically named to the library
624 if ( ! strpos($library, '/'))
625 {
626 $library = ucfirst($library).'/'.$library;
627 }
628
629 return $this->library($library, $params, $object_name);
630 }
631
632 // --------------------------------------------------------------------
633
634 /**
635 * Add Package Path
636 *
637 * Prepends a parent path to the library, model, helper, and config path arrays
638 *
639 * @param string
640 * @param boolean
641 * @return void
642 */
643 public function add_package_path($path, $view_cascade=TRUE)
644 {
645 $path = rtrim($path, '/').'/';
646
647 array_unshift($this->_ci_library_paths, $path);
648 array_unshift($this->_ci_model_paths, $path);
649 array_unshift($this->_ci_helper_paths, $path);
650
651 $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
652
653 // Add config file path
654 $config =& $this->_ci_get_component('config');
655 // array_unshift($config->_config_paths, $path);
656 $config->_config_paths[] = $path;
657 // array_unshift($config->_config_paths, $path);
658 }
659
660 // --------------------------------------------------------------------
661
662 /**
663 * Get Package Paths
664 *
665 * Return a list of all package paths, by default it will ignore BASEPATH.
666 *
667 * @param string
668 * @return void
669 */
670 public function get_package_paths($include_base = FALSE)
671 {
672 return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
673 }
674
675 // --------------------------------------------------------------------
676
677 /**
678 * Remove Package Path
679 *
680 * Remove a path from the library, model, and helper path arrays if it exists
681 * If no path is provided, the most recently added path is removed.
682 *
683 * @param type
684 * @param bool
685 * @return type
686 */
687 public function remove_package_path($path = '', $remove_config_path = TRUE)
688 {
689 $config =& $this->_ci_get_component('config');
690
691 if ($path == '')
692 {
693 $void = array_shift($this->_ci_library_paths);
694 $void = array_shift($this->_ci_model_paths);
695 $void = array_shift($this->_ci_helper_paths);
696 $void = array_shift($this->_ci_view_paths);
697 $void = array_shift($config->_config_paths);
698 }
699 else
700 {
701 $path = rtrim($path, '/').'/';
702 foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
703 {
704 if (($key = array_search($path, $this->{$var})) !== FALSE)
705 {
706 unset($this->{$var}[$key]);
707 }
708 }
709
710 if (isset($this->_ci_view_paths[$path.'views/']))
711 {
712 unset($this->_ci_view_paths[$path.'views/']);
713 }
714
715 if (($key = array_search($path, $config->_config_paths)) !== FALSE)
716 {
717 unset($config->_config_paths[$key]);
718 }
719 }
720
721 // make sure the application default paths are still in the array
722 $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
723 $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
724 $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
725 $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
726 $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
727 }
728
729 // --------------------------------------------------------------------
730
731 /**
732 * Loader
733 *
734 * This function is used to load views and files.
735 * Variables are prefixed with _ci_ to avoid symbol collision with
736 * variables made available to view files
737 *
738 * @param array
739 * @return void
740 */
741 protected function _ci_load($_ci_data)
742 {
743 // Set the default data variables
744 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
745 {
746 $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
747 }
748
749 $file_exists = FALSE;
750
751 // Set the path to the requested file
752 if ($_ci_path != '')
753 {
754 $_ci_x = explode('/', $_ci_path);
755 $_ci_file = end($_ci_x);
756 }
757 else
758 {
759 $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
760 $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view;
761
762 foreach ($this->_ci_view_paths as $view_file => $cascade)
763 {
764 if (file_exists($view_file.$_ci_file))
765 {
766 $_ci_path = $view_file.$_ci_file;
767 $file_exists = TRUE;
768 break;
769 }
770
771 if ( ! $cascade)
772 {
773 break;
774 }
775 }
776 }
777
778 if ( ! $file_exists && ! file_exists($_ci_path))
779 {
780 show_error('Unable to load the requested file: '.$_ci_file);
781 }
782
783 // This allows anything loaded using $this->load (views, files, etc.)
784 // to become accessible from within the Controller and Model functions.
785
786 $_ci_CI =& ci_get_instance();
787 foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
788 {
789 if ( ! isset($this->$_ci_key))
790 {
791 $this->$_ci_key =& $_ci_CI->$_ci_key;
792 }
793 }
794
795 /*
796 * Extract and cache variables
797 *
798 * You can either set variables using the dedicated $this->load_vars()
799 * function or via the second parameter of this function. We'll merge
800 * the two types and cache them so that views that are embedded within
801 * other views can have access to these variables.
802 */
803 if (is_array($_ci_vars))
804 {
805 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
806 }
807 extract($this->_ci_cached_vars);
808
809 /*
810 * Buffer the output
811 *
812 * We buffer the output for two reasons:
813 * 1. Speed. You get a significant speed boost.
814 * 2. So that the final rendered template can be
815 * post-processed by the output class. Why do we
816 * need post processing? For one thing, in order to
817 * show the elapsed page load time. Unless we
818 * can intercept the content right before it's sent to
819 * the browser and then stop the timer it won't be accurate.
820 */
821 ob_start();
822
823 // If the PHP installation does not support short tags we'll
824 // do a little string replacement, changing the short tags
825 // to standard PHP echo statements.
826
827 if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
828 {
829 echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
830 }
831 else
832 {
833 include($_ci_path); // include() vs include_once() allows for multiple views with the same name
834 }
835
836 log_message('debug', 'File loaded: '.$_ci_path);
837
838 // Return the file data if requested
839 if ($_ci_return === TRUE)
840 {
841 $buffer = ob_get_contents();
842 @ob_end_clean();
843 return $buffer;
844 }
845
846 /*
847 * Flush the buffer... or buff the flusher?
848 *
849 * In order to permit views to be nested within
850 * other views, we need to flush the content back out whenever
851 * we are beyond the first level of output buffering so that
852 * it can be seen and included properly by the first included
853 * template and any subsequent ones. Oy!
854 *
855 */
856 if (ob_get_level() > $this->_ci_ob_level + 1)
857 {
858 ob_end_flush();
859 }
860 else
861 {
862 $_ci_CI->output->append_output(ob_get_contents());
863 @ob_end_clean();
864 }
865 }
866
867 // --------------------------------------------------------------------
868
869 /**
870 * Load class
871 *
872 * This function loads the requested class.
873 *
874 * @param string the item that is being loaded
875 * @param mixed any additional parameters
876 * @param string an optional object name
877 * @return void
878 */
879 protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
880 {
881 // Get the class name, and while we're at it trim any slashes.
882 // The directory path can be included as part of the class name,
883 // but we don't want a leading slash
884 $class = str_replace('.php', '', trim($class, '/'));
885
886 // Was the path included with the class name?
887 // We look for a slash to determine this
888 $subdir = '';
889 if (($last_slash = strrpos($class, '/')) !== FALSE)
890 {
891 // Extract the path
892 $subdir = substr($class, 0, $last_slash + 1);
893
894 // Get the filename from the path
895 $class = substr($class, $last_slash + 1);
896 }
897
898 // We'll test for both lowercase and capitalized versions of the file name
899 foreach (array(ucfirst($class), strtolower($class)) as $class)
900 {
901 $subclass = NTS_SYSTEM_APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
902 // Is this a class extension request?
903 if (file_exists($subclass))
904 {
905 $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
906
907 if ( ! file_exists($baseclass))
908 {
909 log_message('error', "Unable to load the requested class: ".$class);
910 show_error("Unable to load the requested class: ".$class);
911 }
912
913 // Safety: Was the class already loaded by a previous call?
914 if (in_array($subclass, $this->_ci_loaded_files))
915 {
916 // Before we deem this to be a duplicate request, let's see
917 // if a custom object name is being supplied. If so, we'll
918 // return a new instance of the object
919 if ( ! is_null($object_name))
920 {
921 $CI =& ci_get_instance();
922 if ( ! isset($CI->$object_name))
923 {
924 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
925 }
926 }
927
928 $is_duplicate = TRUE;
929 log_message('debug', $class." class already loaded. Second attempt ignored.");
930 return;
931 }
932
933 include_once($baseclass);
934 include_once($subclass);
935 $this->_ci_loaded_files[] = $subclass;
936
937 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
938 }
939
940 // Lets search for the requested library file and load it.
941 $is_duplicate = FALSE;
942 foreach ($this->_ci_library_paths as $path)
943 {
944 $filepath = $path.'libraries/'.$subdir.$class.'.php';
945
946 // Does the file exist? No? Bummer...
947 if ( ! file_exists($filepath))
948 {
949 continue;
950 }
951
952 // Safety: Was the class already loaded by a previous call?
953 if (in_array($filepath, $this->_ci_loaded_files))
954 {
955 // Before we deem this to be a duplicate request, let's see
956 // if a custom object name is being supplied. If so, we'll
957 // return a new instance of the object
958 if ( ! is_null($object_name))
959 {
960 $CI =& ci_get_instance();
961 if ( ! isset($CI->$object_name))
962 {
963 return $this->_ci_init_class($class, '', $params, $object_name);
964 }
965 }
966
967 $is_duplicate = TRUE;
968 log_message('debug', $class." class already loaded. Second attempt ignored.");
969 return;
970 }
971
972 include_once($filepath);
973 $this->_ci_loaded_files[] = $filepath;
974 return $this->_ci_init_class($class, '', $params, $object_name);
975 }
976
977 } // END FOREACH
978
979 // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
980 if ($subdir == '')
981 {
982 $path = strtolower($class).'/'.$class;
983 return $this->_ci_load_class($path, $params);
984 }
985
986 // If we got this far we were unable to find the requested class.
987 // We do not issue errors if the load call failed due to a duplicate request
988 if ($is_duplicate == FALSE)
989 {
990 log_message('error', "Unable to load the requested class: ".$class);
991 show_error("Unable to load the requested class: ".$class);
992 }
993 }
994
995 // --------------------------------------------------------------------
996
997 /**
998 * Instantiates a class
999 *
1000 * @param string
1001 * @param string
1002 * @param bool
1003 * @param string an optional object name
1004 * @return null
1005 */
1006 protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
1007 {
1008 // Is there an associated config file for this class? Note: these should always be lowercase
1009 if ($config === NULL)
1010 {
1011 // Fetch the config paths containing any package paths
1012 $config_component = $this->_ci_get_component('config');
1013
1014 if (is_array($config_component->_config_paths))
1015 {
1016 // Break on the first found file, thus package files
1017 // are not overridden by default paths
1018 foreach ($config_component->_config_paths as $path)
1019 {
1020 // We test for both uppercase and lowercase, for servers that
1021 // are case-sensitive with regard to file names. Check for environment
1022 // first, global next
1023 if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
1024 {
1025 include($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
1026 break;
1027 }
1028 elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
1029 {
1030 include($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
1031 break;
1032 }
1033 elseif (file_exists($path .'config/'.strtolower($class).'.php'))
1034 {
1035 include($path .'config/'.strtolower($class).'.php');
1036 break;
1037 }
1038 elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php'))
1039 {
1040 include($path .'config/'.ucfirst(strtolower($class)).'.php');
1041 break;
1042 }
1043 }
1044 }
1045 }
1046
1047 if ($prefix == '')
1048 {
1049 if (class_exists('CI_'.$class))
1050 {
1051 $name = 'CI_'.$class;
1052 }
1053 elseif (class_exists(config_item('subclass_prefix').$class))
1054 {
1055 $name = config_item('subclass_prefix').$class;
1056 }
1057 else
1058 {
1059 $name = $class;
1060 }
1061 }
1062 else
1063 {
1064 $name = $prefix.$class;
1065 }
1066
1067 // Is the class name valid?
1068 if ( ! class_exists($name))
1069 {
1070 log_message('error', "Non-existent class: ".$name);
1071 show_error("Non-existent class: ".$class);
1072 }
1073
1074 // Set the variable name we will assign the class to
1075 // Was a custom class name supplied? If so we'll use it
1076 $class = strtolower($class);
1077
1078 if (is_null($object_name))
1079 {
1080 $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
1081 }
1082 else
1083 {
1084 $classvar = $object_name;
1085 }
1086
1087 // Save the class name and object name
1088 $this->_ci_classes[$class] = $classvar;
1089
1090 // Instantiate the class
1091 $CI =& ci_get_instance();
1092 if ($config !== NULL)
1093 {
1094 $CI->$classvar = new $name($config);
1095 }
1096 else
1097 {
1098 $CI->$classvar = new $name;
1099 }
1100 }
1101
1102 // --------------------------------------------------------------------
1103
1104 /**
1105 * Autoloader
1106 *
1107 * The config/autoload.php file contains an array that permits sub-systems,
1108 * libraries, and helpers to be loaded automatically.
1109 *
1110 * @param array
1111 * @return void
1112 */
1113 private function _ci_autoloader()
1114 {
1115 if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
1116 {
1117 include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
1118 }
1119 else
1120 {
1121 include(NTS_SYSTEM_APPPATH.'config/autoload.php');
1122 if ( file_exists(APPPATH.'config/autoload.php') )
1123 {
1124 include(APPPATH.'config/autoload.php');
1125 }
1126 }
1127
1128 if ( ! isset($autoload))
1129 {
1130 return FALSE;
1131 }
1132
1133 // Autoload packages
1134 if (isset($autoload['packages']))
1135 {
1136 foreach ($autoload['packages'] as $package_path)
1137 {
1138 $this->add_package_path($package_path);
1139 }
1140 }
1141
1142 // Load any custom config file
1143 if (count($autoload['config']) > 0)
1144 {
1145 $CI =& ci_get_instance();
1146 foreach ($autoload['config'] as $key => $val)
1147 {
1148 $CI->config->load($val);
1149 }
1150 }
1151
1152 // Autoload helpers and languages
1153 foreach (array('helper', 'language') as $type)
1154 {
1155 if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
1156 {
1157 $this->$type($autoload[$type]);
1158 }
1159 }
1160
1161 // A little tweak to remain backward compatible
1162 // The $autoload['core'] item was deprecated
1163 if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
1164 {
1165 $autoload['libraries'] = $autoload['core'];
1166 }
1167
1168 // Load libraries
1169 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
1170 {
1171 // Load the database driver.
1172 if (in_array('database', $autoload['libraries']))
1173 {
1174 $this->database();
1175 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
1176 }
1177
1178 // Load all other libraries
1179 foreach ($autoload['libraries'] as $item)
1180 {
1181 $this->library($item);
1182 }
1183 }
1184
1185 // Autoload models
1186 if (isset($autoload['model']))
1187 {
1188 $this->model($autoload['model']);
1189 }
1190 }
1191
1192 // --------------------------------------------------------------------
1193
1194 /**
1195 * Object to Array
1196 *
1197 * Takes an object as input and converts the class variables to array key/vals
1198 *
1199 * @param object
1200 * @return array
1201 */
1202 protected function _ci_object_to_array($object)
1203 {
1204 return (is_object($object)) ? get_object_vars($object) : $object;
1205 }
1206
1207 // --------------------------------------------------------------------
1208
1209 /**
1210 * Get a reference to a specific library or model
1211 *
1212 * @param string
1213 * @return bool
1214 */
1215 protected function &_ci_get_component($component)
1216 {
1217 $CI =& ci_get_instance();
1218 return $CI->$component;
1219 }
1220
1221 // --------------------------------------------------------------------
1222
1223 /**
1224 * Prep filename
1225 *
1226 * This function preps the name of various items to make loading them more reliable.
1227 *
1228 * @param mixed
1229 * @param string
1230 * @return array
1231 */
1232 protected function _ci_prep_filename($filename, $extension)
1233 {
1234 if ( ! is_array($filename))
1235 {
1236 return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension));
1237 }
1238 else
1239 {
1240 foreach ($filename as $key => $val)
1241 {
1242 $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension);
1243 }
1244
1245 return $filename;
1246 }
1247 }
1248 }
1249
1250 /* End of file Loader.php */
1251 /* Location: ./system/core/Loader.php */