Advertisement
Guest User

Untitled

a guest
Jul 21st, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Loader)
  6. *
  7. * @ Version : 2.0.0.3
  8. * @ Author : DeZender
  9. * @ Release on : 06.05.2013
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. namespace {
  15.  
  16. require_once "Loader.php";
  17.  
  18. }
  19.  
  20. namespace Core\Loader {
  21.  
  22. class Autoloader {
  23.  
  24.  
  25. /**
  26.  
  27. *
  28.  
  29. * @var \Core\Loader\Autoloader Singleton instance
  30.  
  31. */
  32. protected static $_instance = null;
  33. /**
  34.  
  35. *
  36.  
  37. * @var array Concrete autoloader callback implementations
  38.  
  39. */
  40. protected static $_autoloaders = array();
  41. /**
  42.  
  43. *
  44.  
  45. * @var array Default autoloader callback
  46.  
  47. */
  48. protected static $_defaultAutoloader = array(0 => "\\Core\\Loader\\Loader", 1 => "loadClass");
  49. /**
  50.  
  51. *
  52.  
  53. * @var bool Whether or not to act as a fallback autoloader
  54.  
  55. */
  56. protected static $_fallbackAutoloader = false;
  57. /**
  58.  
  59. *
  60.  
  61. * @var array Callback for internal autoloader implementation
  62.  
  63. */
  64. protected static $_internalAutoloader = null;
  65. /**
  66.  
  67. *
  68.  
  69. * @var array Supported namespaces 'Core' by default.
  70.  
  71. */
  72. protected static $_namespaces = array();
  73. /**
  74.  
  75. *
  76.  
  77. * @var array Namespace-specific autoloaders
  78.  
  79. */
  80. protected static $_namespaceAutoloaders = array();
  81. /**
  82.  
  83. *
  84.  
  85. * @var bool Whether or not to suppress file not found warnings
  86.  
  87. */
  88. protected static $_suppressNotFoundWarnings = false;
  89. public static function getInstance() {
  90. if (null === self::$_instance) {
  91. self::$_instance = new self();
  92. }
  93. return self::$_instance;
  94. }
  95.  
  96. public static function resetInstance() {
  97. self::$_instance = null;
  98. }
  99.  
  100. public static function autoload($class) {
  101. $self = self::getInstance();
  102. foreach ($self->getClassAutoloaders($class) as $autoloader) {
  103. if ($autoloader instanceof Autoloader) {
  104. if ($autoloader->autoload($class)) {
  105. return true;
  106. }
  107. }
  108. else {
  109. if (is_string($autoloader)) {
  110. if ($autoloader($class)) {
  111. return true;
  112. }
  113. }
  114. else {
  115. if (is_array($autoloader)) {
  116. $object = array_shift($autoloader);
  117. $method = array_shift($autoloader);
  118. if (call_user_func(array($object, $method), $class)) {
  119. return true;
  120. }
  121. }
  122. }
  123. }
  124. continue;
  125. }
  126. return false;
  127. }
  128.  
  129. public function setDefaultAutoloader($callback) {
  130. if (!is_callable($callback)) {
  131. throw new Exception("Invalid callback specified for default autoloader");
  132. }
  133. $this->_defaultAutoloader = $callback;
  134. return $this;
  135. }
  136.  
  137. public function getDefaultAutoloader() {
  138. return $this->_defaultAutoloader;
  139. }
  140.  
  141. public function setAutoloaders(array $autoloaders) {
  142. $this->_autoloaders = $autoloaders;
  143. return $this;
  144. }
  145.  
  146. public function getAutoloaders() {
  147. return $this->_autoloaders;
  148. }
  149.  
  150. public function getNamespaceAutoloaders($namespace) {
  151. $namespace = (string)$namespace;
  152. if (!array_key_exists($namespace, $this->_namespaceAutoloaders)) {
  153. return array();
  154. }
  155. return $this->_namespaceAutoloaders[$namespace];
  156. }
  157.  
  158. public function registerNamespace($namespace, $path = null) {
  159. if (is_array($namespace)) {
  160. return $this->registerNamespaces($namespace);
  161. }
  162. else {
  163. if (!$path || is_array($path)) {
  164. throw new Exception("Invalid namespace provided");
  165. }
  166. }
  167. $namespace = rtrim($namespace, "\\") . "\\";
  168. if (!isset($this->_namespaces[$namespace])) {
  169. $this->_namespaces[$namespace] = $path;
  170. }
  171. return $this;
  172. }
  173.  
  174. public function registerNamespaces($namespace) {
  175. if (!is_array($namespace)) {
  176. throw new Exception("Invalid namespace provided");
  177. }
  178. foreach ($namespace as $ns => $path) {
  179. $this->registerNamespace($ns, $path);
  180. continue;
  181. }
  182. return $this;
  183. }
  184.  
  185. public function unregisterNamespace($namespace) {
  186. if (is_string($namespace)) {
  187. $namespace = (array)$namespace;
  188. }
  189. else {
  190. if (!is_array($namespace)) {
  191. throw new Exception("Invalid namespace provided");
  192. }
  193. }
  194. foreach ($namespace as $ns) {
  195. if (isset($this->_namespaces[$ns])) {
  196. unset($this->_namespaces[$ns]);
  197. }
  198. continue;
  199. }
  200. return $this;
  201. }
  202.  
  203. public function getRegisteredNamespaces() {
  204. return $this->_namespaces;
  205. }
  206.  
  207. public function suppressNotFoundWarnings($flag = null) {
  208. if (null === $flag) {
  209. return $this->_suppressNotFoundWarnings;
  210. }
  211. $this->_suppressNotFoundWarnings = (bool)$flag;
  212. return $this;
  213. }
  214.  
  215. public function setFallbackAutoloader($flag) {
  216. $this->_fallbackAutoloader = (bool)$flag;
  217. return $this;
  218. }
  219.  
  220. public function isFallbackAutoloader() {
  221. return $this->_fallbackAutoloader;
  222. }
  223.  
  224. public function getClassAutoloaders($class) {
  225. $namespace = false;
  226. $autoloaders = (array());
  227. foreach (array_keys($this->_namespaceAutoloaders) as $ns) {
  228. if ("" == $ns) {
  229. continue;
  230. }
  231. if (0 === strpos($class, $ns)) {
  232. $namespace = $ns;
  233. $autoloaders = $autoloaders + $this->getNamespaceAutoloaders($ns);
  234. break;
  235. }
  236. continue;
  237. }
  238. foreach ($this->getRegisteredNamespaces() as $ns => $path) {
  239. if (0 === strpos($class, $ns)) {
  240. $namespace = $ns;
  241. $autoloaders[] = $this->_internalAutoloader;
  242. break;
  243. }
  244. continue;
  245. }
  246. $autoloaders = $autoloaders + $this->getNamespaceAutoloaders("");
  247. if (!$namespace && $this->isFallbackAutoloader()) {
  248. $autoloaders[] = $this->_internalAutoloader;
  249. }
  250. return $autoloaders;
  251. }
  252.  
  253. public function unshiftAutoloader($callback, $namespace = "") {
  254. $autoloaders = $this->getAutoloaders();
  255. array_unshift($autoloaders, $callback);
  256. $this->setAutoloaders($autoloaders);
  257. $namespace = (array)$namespace;
  258. foreach ($namespace as $ns) {
  259. .........................................................................
  260. ....................................
  261. ............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement