Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/libraries/loader.php
f43d1a4680a9
4.0 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | <?php
/**
* @version $Id: loader.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
if(!defined('DS')) {
define( 'DS', DIRECTORY_SEPARATOR );
}
/**
* @package Joomla.Framework
*/
class JLoader
{
/**
* Loads a class from specified directories.
*
* @param string $name The class name to look for ( dot notation ).
* @param string $base Search this directory for the class.
* @param string $key String used as a prefix to denote the full path of the file ( dot notation ).
* @return void
* @since 1.5
*/
function import( $filePath, $base = null, $key = 'libraries.' )
{
static $paths;
if (!isset($paths)) {
$paths = array();
}
$keyPath = $key ? $key . $filePath : $filePath;
if (!isset($paths[$keyPath]))
{
if ( ! $base ) {
$base = dirname( __FILE__ );
}
$parts = explode( '.', $filePath );
$classname = array_pop( $parts );
switch($classname)
{
case 'helper' :
$classname = ucfirst(array_pop( $parts )).ucfirst($classname);
break;
default :
$classname = ucfirst($classname);
break;
}
$path = str_replace( '.', DS, $filePath );
if (strpos($filePath, 'joomla') === 0)
{
/*
* If we are loading a joomla class prepend the classname with a
* capital J.
*/
$classname = 'J'.$classname;
$classes = JLoader::register($classname, $base.DS.$path.'.php');
$rs = isset($classes[strtolower($classname)]);
}
else
{
/*
* If it is not in the joomla namespace then we have no idea if
* it uses our pattern for class names/files so just include.
*/
$rs = include($base.DS.$path.'.php');
}
$paths[$keyPath] = $rs;
}
return $paths[$keyPath];
}
/**
* Add a class to autoload
*
* @param string $classname The class name
* @param string $file Full path to the file that holds the class
* @return array|boolean Array of classes
* @since 1.5
*/
function & register ($class = null, $file = null)
{
static $classes;
if(!isset($classes)) {
$classes = array();
}
if($class && is_file($file))
{
// Force to lower case.
$class = strtolower($class);
$classes[$class] = $file;
// In php4 we load the class immediately.
if((version_compare( phpversion(), '5.0' ) < 0)) {
JLoader::load($class);
}
}
return $classes;
}
/**
* Load the file for a class
*
* @access public
* @param string $class The class that will be loaded
* @return boolean True on success
* @since 1.5
*/
function load( $class )
{
$class = strtolower($class); //force to lower case
if (class_exists($class)) {
return;
}
$classes = JLoader::register();
if(array_key_exists( strtolower($class), $classes)) {
include($classes[$class]);
return true;
}
return false;
}
}
/**
* When calling a class that hasn't been defined, __autoload will attempt to
* include the correct file for that class.
*
* This function get's called by PHP. Never call this function yourself.
*
* @param string $class
* @access public
* @return boolean
* @since 1.5
*/
function __autoload($class)
{
if(JLoader::load($class)) {
return true;
}
return false;
}
/**
* Global application exit.
*
* This function provides a single exit point for the framework.
*
* @param mixed Exit code or string. Defaults to zero.
*/
function jexit($message = 0) {
exit($message);
}
/**
* Intelligent file importer
*
* @access public
* @param string $path A dot syntax path
* @since 1.5
*/
function jimport( $path ) {
return JLoader::import($path);
}
|