Advertisement
Guest User

al

a guest
Feb 21st, 2017
203
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Varien
  22. * @package Varien_Autoload
  23. * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26.  
  27. /**
  28. * Classes source autoload
  29. */
  30. class Varien_Autoload
  31. {
  32. const SCOPE_FILE_PREFIX = '__';
  33.  
  34. static protected $_instance;
  35. static protected $_scope = 'default';
  36.  
  37. protected $_isIncludePathDefined= null;
  38. protected $_collectClasses = false;
  39. protected $_collectPath = null;
  40. protected $_arrLoadedClasses = array();
  41.  
  42. /**
  43. * Class constructor
  44. */
  45. public function __construct()
  46. {
  47. register_shutdown_function(array($this, 'destroy'));
  48. $this->_isIncludePathDefined = defined('COMPILER_INCLUDE_PATH');
  49. if (defined('COMPILER_COLLECT_PATH')) {
  50. $this->_collectClasses = true;
  51. $this->_collectPath = COMPILER_COLLECT_PATH;
  52. }
  53. self::registerScope(self::$_scope);
  54. }
  55.  
  56. /**
  57. * Singleton pattern implementation
  58. *
  59. * @return Varien_Autoload
  60. */
  61. static public function instance()
  62. {
  63. if (!self::$_instance) {
  64. self::$_instance = new Varien_Autoload();
  65. }
  66. return self::$_instance;
  67. }
  68.  
  69. /**
  70. * Register SPL autoload function
  71. */
  72. static public function register()
  73. {
  74. spl_autoload_register(array(self::instance(), 'autoload'));
  75. }
  76.  
  77. /**
  78. * Load class source code
  79. *
  80. * @param string $class
  81. */
  82. public function autoload($class)
  83. {
  84. if ($this->_collectClasses) {
  85. $this->_arrLoadedClasses[self::$_scope][] = $class;
  86. }
  87. if ($this->_isIncludePathDefined) {
  88. $classFile = COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . $class;
  89. } else {
  90. $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
  91. }
  92. $classFile.= '.php';
  93. //echo $classFile;die();
  94. if ($class === 'File') { mageDebugBacktrace(); }
  95. return include $classFile;
  96.  
  97. }
  98.  
  99. /**
  100. * Register autoload scope
  101. * This process allow include scope file which can contain classes
  102. * definition which are used for this scope
  103. *
  104. * @param string $code scope code
  105. */
  106. static public function registerScope($code)
  107. {
  108. self::$_scope = $code;
  109. if (defined('COMPILER_INCLUDE_PATH')) {
  110. @include COMPILER_INCLUDE_PATH . DIRECTORY_SEPARATOR . self::SCOPE_FILE_PREFIX.$code.'.php';
  111. }
  112. }
  113.  
  114. /**
  115. * Get current autoload scope
  116. *
  117. * @return string
  118. */
  119. static public function getScope()
  120. {
  121. return self::$_scope;
  122. }
  123.  
  124. /**
  125. * Class destructor
  126. */
  127. public function destroy()
  128. {
  129. if ($this->_collectClasses) {
  130. $this->_saveCollectedStat();
  131. }
  132. }
  133.  
  134. /**
  135. * Save information about used classes per scope with class popularity
  136. * Class_Name:popularity
  137. *
  138. * @return Varien_Autoload
  139. */
  140. protected function _saveCollectedStat()
  141. {
  142. if (!is_dir($this->_collectPath)) {
  143. @mkdir($this->_collectPath);
  144. @chmod($this->_collectPath, 0777);
  145. }
  146.  
  147. if (!is_writeable($this->_collectPath)) {
  148. return $this;
  149. }
  150.  
  151. foreach ($this->_arrLoadedClasses as $scope => $classes) {
  152. if ($class === 'File') { mageDebugBacktrace(); }
  153. $file = $this->_collectPath.DIRECTORY_SEPARATOR.$scope.'.csv';
  154. $data = array();
  155. if (file_exists($file)) {
  156. $data = explode("\n", file_get_contents($file));
  157. foreach ($data as $index => $class) {
  158. $class = explode(':', $class);
  159. $searchIndex = array_search($class[0], $classes);
  160. if ($searchIndex !== false) {
  161. $class[1]+=1;
  162. unset($classes[$searchIndex]);
  163. }
  164. $data[$index] = $class[0].':'.$class[1];
  165. }
  166. }
  167. foreach ($classes as $class) {
  168. $data[] = $class . ':1';
  169. }
  170. file_put_contents($file, implode("\n", $data));
  171. }
  172. return $this;
  173. }
  174.  
  175.  
  176.  
  177. }
Advertisement
RAW Paste Data Copied
Advertisement