/app/class/AutoLoad.php
PHP | 175 lines | 81 code | 1 blank | 93 comment | 19 complexity | 7feed1bde0587abf0ca1ef19958fa3a6 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- /**
- * Pos-Tracker
- *
- * AutoLoad.php - Contains AutoLoad class. Modified from yapeal.
- *
- * PHP version 5
- *
- * LICENSE: This file is part of POS-Tracker.
- * POS-Tracker is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- *
- * POS-Tracker is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with POS-Tracker. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Stephen Gulickk <stephenmg12@gmail.com>
- * @author Michael Cummings <mgcummings@yahoo.com>
- * @copyright 2007-2011 (C) Stephen Gulick and Michael Cummings
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL 3.0
- * @package POS-Tracker
- * @version SVN: $Id$
- * @link http://code.google.com/p/pos-tracker/
- * @link http://code.google.com/p/yapeal/
- * @link http://www.eveonline.com/
- */
- /**
- * @internal Allow viewing of the source code in web browser.
- */
- if (isset($_REQUEST['viewSource'])) {
- highlight_file(__FILE__);
- exit();
- };
- /**
- * @internal Only let this code be included or required not ran directly.
- */
- if (basename(__FILE__) == basename($_SERVER['SCRIPT_NAME'])) {
- exit();
- };
- // Need to require one last class before autoloader can take over.
- require_once EVEHR_CLASS . 'FilterFileFinder.php';
- /**
- * Class used to manage auto loading of other classes/interfaces.
- *
- * @package Yapeal
- * @subpackage Autoload
- */
- class EVEHRAutoLoad {
- /**
- * @var object
- */
- protected static $instance;
- /**
- * @var array
- */
- private static $dirList;
- /**
- * @var array
- */
- private static $suffixList;
- /**
- * Only way to make instance is through {@link getInstance() getInstance()}.
- */
- private function __construct() {
- self::$dirList = array(EVEHR_CLASS, EVEHR_EXT, EVEHR_CON);
- self::$suffixList = array('.php', '.class.php', '.inc.php', '.class', '.inc');
- }
- /**
- * No backdoor through cloning either.
- */
- private function __clone() {}
- /**
- * Used to get an instance of the class.
- *
- * @return YapealAutoLoad Returns an instance of the class.
- */
- public static function getInstance() {
- if (!(self::$instance instanceof self)) {
- self::$instance = new self();
- };
- return self::$instance;
- }
- /**
- * Searches through the common class directory locations for the file
- * containing the class/interface we need.
- *
- * @param string $className Class name to be loaded.
- *
- * @return bool TRUE if class/interface is found.
- */
- public static function autoLoad($className) {
- self::getInstance();
- //Dwoo Autoloader code
- if (substr($className, 0, 5) === 'Dwoo_') {
- include_once EVEHR_DWOO.strtr($className, '_', DIRECTORY_SEPARATOR).'.php';
- //See if we have the class now
- if (class_exists($className, FALSE) ||
- interface_exists($className, FALSE)) {
- // Yes, we're done.
- return TRUE;
- }
- }
- foreach (self::$dirList as $dir) {
- $files = new evehrFilterFileFinder($dir, $className, evehrFilterFileFinder::CONTAINS);
- foreach ($files as $name => $object) {
- $bn = basename($name);
- foreach (self::$suffixList as $suffix) {
- if ($bn == $className . $suffix ||
- $bn == strtolower($className) . $suffix ||
- $bn == 'I' . $className . $suffix ||
- $bn == 'class.' . $className . $suffix ||
- $bn == 'I' . strtolower($className) . $suffix) {
- include_once($name);
- // Does the class/interface requested actually exist now?
- if (class_exists($className, FALSE) ||
- interface_exists($className, FALSE)) {
- // Yes, we're done.
- return TRUE;
- };// if class_exists...
- };// if basename...
- };// foreach self::$suffixList ...
- };// foreach $files ...
- };// foreach self::$dirList ...
- return FALSE;
- }
- /**
- * Add an extension to the list used for class/interface names.
- *
- * @param string $ext The extension to be added to list.
- *
- * @return bool TRUE if extension was already in the list.
- */
- static public function addExtension($ext) {
- self::getInstance();
- if (!in_array($ext, self::$suffixList)) {
- self::$suffixList[] = $ext;
- return FALSE;
- };
- return TRUE;
- }
- /**
- * Add a directory to the list to be searched in for class/interface files.
- *
- * @param string $dir The directory to be added to list.
- *
- * @return bool TRUE if directory was already in the list.
- */
- static public function addPath($dir) {
- self::getInstance();
- if (!in_array($dir, self::$dirList)) {
- self::$dirList[] = $dir;
- return FALSE;
- };
- return TRUE;
- }
- }
- // Now activate the YapealAutoLoad autoloader.
- if (FALSE == spl_autoload_functions()) {
- spl_autoload_register(array('EVEHRAutoLoad', 'autoLoad'));
- if (function_exists('__autoload')) {
- spl_autoload_register('__autoload', FALSE);
- };
- } else {
- // Prepend if other autoloaders already exist.
- spl_autoload_register(array('EVEHRAutoLoad', 'autoLoad'), FALSE, TRUE);
- };// else FALSE == spl_autoload_functions() ...
- require_once EVEHR_DWOO.'Dwoo.php';
- ?>