source: trunk/www.guidonia.net/wp/wp-content/plugins/tubepress/classes/tubepress_classloader.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 2.1 KB
Line 
1<?php
2/**
3 * Copyright 2006, 2007, 2008, 2009 Eric D. Hough (http://ehough.com)
4 *
5 * This file is part of TubePress (http://tubepress.org)
6 *
7 * TubePress is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * TubePress is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with TubePress. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22function tubepress_load_classes($classesToLoad) {
23 foreach ($classesToLoad as $class) {
24 tubepress_classloader($class);
25 }
26}
27
28/**
29 * Attempts to load a class file based on the class name
30 *
31 * @param string $className The name of the class to load
32 *
33 * @return void
34 */
35function tubepress_classloader($className)
36{
37 /* already have the class or interface? bail */
38 if (class_exists($className, false) || interface_exists($className, false)) {
39 return;
40 }
41
42 /*
43 * replace all underscores with the directory separator and add ".class.php"
44 * e.g. "org_tubepress_package_MyClass" becomes "org/tubepress/package/MyClass.class.php"
45 */
46 $fileName = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.class.php';
47
48 /* piece together the absolute file name */
49 $currentDir = dirname(__FILE__) . "/../classes/";
50 $absPath = $currentDir . $fileName;
51
52 /* include the file if it exists */
53 if (file_exists($absPath)) {
54 include $absPath;
55 }
56}
57
58///*
59// * register it as a class loader if PHP >= 5.1.2, otherwise
60// * we just have to register it as *the* classloader (bad!)
61// */
62//if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
63// spl_autoload_register("tubepress_classloader");
64//} else {
65// function __autoload($className) {
66// return tubepress_classloader($className);
67// }
68//}
69?>
Note: See TracBrowser for help on using the repository browser.