Subversion-Projekte lars-tiefland.ci

Revision

Revision 2049 | Revision 2242 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2049 Revision 2107
Zeile 180... Zeile 180...
180
	 * Library Loader
180
	 * Library Loader
181
	 *
181
	 *
182
	 * Loads and instantiates libraries.
182
	 * Loads and instantiates libraries.
183
	 * Designed to be called from application controllers.
183
	 * Designed to be called from application controllers.
184
	 *
184
	 *
185
	 * @param	string	$library	Library name
185
	 * @param	mixed	$library	Library name
186
	 * @param	array	$params		Optional parameters to pass to the library class constructor
186
	 * @param	array	$params		Optional parameters to pass to the library class constructor
187
	 * @param	string	$object_name	An optional object name to assign to
187
	 * @param	string	$object_name	An optional object name to assign to
188
	 * @return	object
188
	 * @return	object
189
	 */
189
	 */
190
	public function library($library, $params = NULL, $object_name = NULL)
190
	public function library($library, $params = NULL, $object_name = NULL)
Zeile 588... Zeile 588...
588
		is_array($helpers) OR $helpers = array($helpers);
588
		is_array($helpers) OR $helpers = array($helpers);
589
		foreach ($helpers as &$helper)
589
		foreach ($helpers as &$helper)
590
		{
590
		{
591
			$filename = basename($helper);
591
			$filename = basename($helper);
592
			$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
592
			$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
593
			$filename = strtolower(preg_replace('#(_helper)?(.php)?$#i', '', $filename)).'_helper';
593
			$filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper';
594
			$helper   = $filepath.$filename;
594
			$helper   = $filepath.$filename;
Zeile 595... Zeile 595...
595
 
595
 
596
			if (isset($this->_ci_helpers[$helper]))
596
			if (isset($this->_ci_helpers[$helper]))
597
			{
597
			{
Zeile 1035... Zeile 1035...
1035
		if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php'))
1035
		if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php'))
1036
		{
1036
		{
1037
			return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
1037
			return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
1038
		}
1038
		}
Zeile -... Zeile 1039...
-
 
1039
 
-
 
1040
		// Safety: Was the class already loaded by a previous call?
-
 
1041
		if (class_exists($class, FALSE))
-
 
1042
		{
-
 
1043
			$property = $object_name;
-
 
1044
			if (empty($property))
-
 
1045
			{
-
 
1046
				$property = strtolower($class);
-
 
1047
				isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
-
 
1048
			}
-
 
1049
 
-
 
1050
			$CI =& get_instance();
-
 
1051
			if (isset($CI->$property))
-
 
1052
			{
-
 
1053
				log_message('debug', $class.' class already loaded. Second attempt ignored.');
-
 
1054
				return;
-
 
1055
			}
-
 
1056
 
-
 
1057
			return $this->_ci_init_library($class, '', $params, $object_name);
-
 
1058
		}
1039
 
1059
 
1040
		// Let's search for the requested library file and load it.
1060
		// Let's search for the requested library file and load it.
1041
		foreach ($this->_ci_library_paths as $path)
1061
		foreach ($this->_ci_library_paths as $path)
1042
		{
1062
		{
1043
			// BASEPATH has already been checked for
1063
			// BASEPATH has already been checked for
1044
			if ($path === BASEPATH)
1064
			if ($path === BASEPATH)
1045
			{
1065
			{
1046
				continue;
1066
				continue;
Zeile 1047... Zeile 1067...
1047
			}
1067
			}
1048
 
-
 
1049
			$filepath = $path.'libraries/'.$subdir.$class.'.php';
-
 
1050
 
-
 
1051
			// Safety: Was the class already loaded by a previous call?
-
 
1052
			if (class_exists($class, FALSE))
-
 
1053
			{
-
 
1054
				// Before we deem this to be a duplicate request, let's see
-
 
1055
				// if a custom object name is being supplied. If so, we'll
-
 
1056
				// return a new instance of the object
-
 
1057
				if ($object_name !== NULL)
-
 
1058
				{
-
 
1059
					$CI =& get_instance();
-
 
1060
					if ( ! isset($CI->$object_name))
-
 
1061
					{
-
 
1062
						return $this->_ci_init_library($class, '', $params, $object_name);
-
 
1063
					}
-
 
1064
				}
-
 
1065
 
-
 
1066
				log_message('debug', $class.' class already loaded. Second attempt ignored.');
-
 
1067
				return;
1068
 
1068
			}
1069
			$filepath = $path.'libraries/'.$subdir.$class.'.php';
1069
			// Does the file exist? No? Bummer...
1070
			// Does the file exist? No? Bummer...
1070
			elseif ( ! file_exists($filepath))
1071
			if ( ! file_exists($filepath))
1071
			{
1072
			{
Zeile 1072... Zeile 1073...
1072
				continue;
1073
				continue;
Zeile 1110... Zeile 1111...
1110
			if (class_exists(config_item('subclass_prefix').$library_name, FALSE))
1111
			if (class_exists(config_item('subclass_prefix').$library_name, FALSE))
1111
			{
1112
			{
1112
				$prefix = config_item('subclass_prefix');
1113
				$prefix = config_item('subclass_prefix');
1113
			}
1114
			}
Zeile 1114... Zeile -...
1114
 
-
 
1115
			// Before we deem this to be a duplicate request, let's see
-
 
1116
			// if a custom object name is being supplied. If so, we'll
1115
 
1117
			// return a new instance of the object
1116
			$property = $object_name;
1118
			if ($object_name !== NULL)
1117
			if (empty($property))
-
 
1118
			{
-
 
1119
				$property = strtolower($library_name);
-
 
1120
				isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
-
 
1121
			}
1119
			{
1122
 
1120
				$CI =& get_instance();
1123
			$CI =& get_instance();
1121
				if ( ! isset($CI->$object_name))
1124
			if ( ! isset($CI->$property))
1122
				{
1125
			{
1123
					return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
-
 
1124
				}
1126
				return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
Zeile 1125... Zeile 1127...
1125
			}
1127
			}
1126
 
1128
 
1127
			log_message('debug', $library_name.' class already loaded. Second attempt ignored.');
1129
			log_message('debug', $library_name.' class already loaded. Second attempt ignored.');
Zeile 1141... Zeile 1143...
1141
				include_once($path);
1143
				include_once($path);
1142
				if (class_exists($prefix.$library_name, FALSE))
1144
				if (class_exists($prefix.$library_name, FALSE))
1143
				{
1145
				{
1144
					return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
1146
					return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
1145
				}
1147
				}
1146
				else
-
 
1147
				{
1148
 
1148
					log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
1149
				log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
1149
				}
-
 
1150
			}
1150
			}
1151
		}
1151
		}
Zeile 1152... Zeile 1152...
1152
 
1152
 
Zeile 1162... Zeile 1162...
1162
				if (class_exists($subclass, FALSE))
1162
				if (class_exists($subclass, FALSE))
1163
				{
1163
				{
1164
					$prefix = config_item('subclass_prefix');
1164
					$prefix = config_item('subclass_prefix');
1165
					break;
1165
					break;
1166
				}
1166
				}
1167
				else
-
 
1168
				{
1167
 
1169
					log_message('debug', $path.' exists, but does not declare '.$subclass);
1168
				log_message('debug', $path.' exists, but does not declare '.$subclass);
1170
				}
-
 
1171
			}
1169
			}
1172
		}
1170
		}
Zeile 1173... Zeile 1171...
1173
 
1171
 
1174
		return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
1172
		return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
Zeile 1366... Zeile 1364...
1366
 
1364
 
1367
	/**
1365
	/**
1368
	 * Prepare variables for _ci_vars, to be later extract()-ed inside views
1366
	 * Prepare variables for _ci_vars, to be later extract()-ed inside views
1369
	 *
1367
	 *
1370
	 * Converts objects to associative arrays and filters-out internal
1368
	 * Converts objects to associative arrays and filters-out internal
1371
	 * variable names (i.e. keys prexied with '_ci_').
1369
	 * variable names (i.e. keys prefixed with '_ci_').
1372
	 *
1370
	 *
1373
	 * @param	mixed	$vars
1371
	 * @param	mixed	$vars
1374
	 * @return	array
1372
	 * @return	array
1375
	 */
1373
	 */
1376
	protected function _ci_prepare_view_vars($vars)
1374
	protected function _ci_prepare_view_vars($vars)
1377
	{
1375
	{
1378
		if ( ! is_array($vars))
1376
		if ( ! is_array($vars))
1379
		{
1377
		{
1380
			$vars = is_object($vars)
1378
			$vars = is_object($vars)
1381
				? get_object_vars($object)
1379
				? get_object_vars($vars)
1382
				: array();
1380
				: array();
Zeile 1383... Zeile 1381...
1383
		}
1381
		}
1384
 
1382