PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/class/AutoLoad.php

http://pos-tracker.googlecode.com/
PHP | 175 lines | 81 code | 1 blank | 93 comment | 19 complexity | 7feed1bde0587abf0ca1ef19958fa3a6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Pos-Tracker
  4. *
  5. * AutoLoad.php - Contains AutoLoad class. Modified from yapeal.
  6. *
  7. * PHP version 5
  8. *
  9. * LICENSE: This file is part of POS-Tracker.
  10. * POS-Tracker is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, version 3 of the License.
  13. *
  14. * POS-Tracker is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with POS-Tracker. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @author Stephen Gulickk <stephenmg12@gmail.com>
  23. * @author Michael Cummings <mgcummings@yahoo.com>
  24. * @copyright 2007-2011 (C) Stephen Gulick and Michael Cummings
  25. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL 3.0
  26. * @package POS-Tracker
  27. * @version SVN: $Id$
  28. * @link http://code.google.com/p/pos-tracker/
  29. * @link http://code.google.com/p/yapeal/
  30. * @link http://www.eveonline.com/
  31. */
  32. /**
  33. * @internal Allow viewing of the source code in web browser.
  34. */
  35. if (isset($_REQUEST['viewSource'])) {
  36. highlight_file(__FILE__);
  37. exit();
  38. };
  39. /**
  40. * @internal Only let this code be included or required not ran directly.
  41. */
  42. if (basename(__FILE__) == basename($_SERVER['SCRIPT_NAME'])) {
  43. exit();
  44. };
  45. // Need to require one last class before autoloader can take over.
  46. require_once EVEHR_CLASS . 'FilterFileFinder.php';
  47. /**
  48. * Class used to manage auto loading of other classes/interfaces.
  49. *
  50. * @package Yapeal
  51. * @subpackage Autoload
  52. */
  53. class EVEHRAutoLoad {
  54. /**
  55. * @var object
  56. */
  57. protected static $instance;
  58. /**
  59. * @var array
  60. */
  61. private static $dirList;
  62. /**
  63. * @var array
  64. */
  65. private static $suffixList;
  66. /**
  67. * Only way to make instance is through {@link getInstance() getInstance()}.
  68. */
  69. private function __construct() {
  70. self::$dirList = array(EVEHR_CLASS, EVEHR_EXT, EVEHR_CON);
  71. self::$suffixList = array('.php', '.class.php', '.inc.php', '.class', '.inc');
  72. }
  73. /**
  74. * No backdoor through cloning either.
  75. */
  76. private function __clone() {}
  77. /**
  78. * Used to get an instance of the class.
  79. *
  80. * @return YapealAutoLoad Returns an instance of the class.
  81. */
  82. public static function getInstance() {
  83. if (!(self::$instance instanceof self)) {
  84. self::$instance = new self();
  85. };
  86. return self::$instance;
  87. }
  88. /**
  89. * Searches through the common class directory locations for the file
  90. * containing the class/interface we need.
  91. *
  92. * @param string $className Class name to be loaded.
  93. *
  94. * @return bool TRUE if class/interface is found.
  95. */
  96. public static function autoLoad($className) {
  97. self::getInstance();
  98. //Dwoo Autoloader code
  99. if (substr($className, 0, 5) === 'Dwoo_') {
  100. include_once EVEHR_DWOO.strtr($className, '_', DIRECTORY_SEPARATOR).'.php';
  101. //See if we have the class now
  102. if (class_exists($className, FALSE) ||
  103. interface_exists($className, FALSE)) {
  104. // Yes, we're done.
  105. return TRUE;
  106. }
  107. }
  108. foreach (self::$dirList as $dir) {
  109. $files = new evehrFilterFileFinder($dir, $className, evehrFilterFileFinder::CONTAINS);
  110. foreach ($files as $name => $object) {
  111. $bn = basename($name);
  112. foreach (self::$suffixList as $suffix) {
  113. if ($bn == $className . $suffix ||
  114. $bn == strtolower($className) . $suffix ||
  115. $bn == 'I' . $className . $suffix ||
  116. $bn == 'class.' . $className . $suffix ||
  117. $bn == 'I' . strtolower($className) . $suffix) {
  118. include_once($name);
  119. // Does the class/interface requested actually exist now?
  120. if (class_exists($className, FALSE) ||
  121. interface_exists($className, FALSE)) {
  122. // Yes, we're done.
  123. return TRUE;
  124. };// if class_exists...
  125. };// if basename...
  126. };// foreach self::$suffixList ...
  127. };// foreach $files ...
  128. };// foreach self::$dirList ...
  129. return FALSE;
  130. }
  131. /**
  132. * Add an extension to the list used for class/interface names.
  133. *
  134. * @param string $ext The extension to be added to list.
  135. *
  136. * @return bool TRUE if extension was already in the list.
  137. */
  138. static public function addExtension($ext) {
  139. self::getInstance();
  140. if (!in_array($ext, self::$suffixList)) {
  141. self::$suffixList[] = $ext;
  142. return FALSE;
  143. };
  144. return TRUE;
  145. }
  146. /**
  147. * Add a directory to the list to be searched in for class/interface files.
  148. *
  149. * @param string $dir The directory to be added to list.
  150. *
  151. * @return bool TRUE if directory was already in the list.
  152. */
  153. static public function addPath($dir) {
  154. self::getInstance();
  155. if (!in_array($dir, self::$dirList)) {
  156. self::$dirList[] = $dir;
  157. return FALSE;
  158. };
  159. return TRUE;
  160. }
  161. }
  162. // Now activate the YapealAutoLoad autoloader.
  163. if (FALSE == spl_autoload_functions()) {
  164. spl_autoload_register(array('EVEHRAutoLoad', 'autoLoad'));
  165. if (function_exists('__autoload')) {
  166. spl_autoload_register('__autoload', FALSE);
  167. };
  168. } else {
  169. // Prepend if other autoloaders already exist.
  170. spl_autoload_register(array('EVEHRAutoLoad', 'autoLoad'), FALSE, TRUE);
  171. };// else FALSE == spl_autoload_functions() ...
  172. require_once EVEHR_DWOO.'Dwoo.php';
  173. ?>