Explain Magento's autoload functionality and how to instantiate classes
Explain Magento's autoload functionality and how to instantiate classes
Add my voice to the request. Just begin to work with Magento and such information will be very useful for me.
Last edited by bevehinds; 05-02-2012 at 09:40 AM.
Is there a function of reserve power supply in gsm repeaters in case of power failure. Just read it
Can I use local tv antenna for getting better signal from my AT700 gsm booster? in my big office.
I have just visited the given blog link for more information and really there are my guiding light in the dark daunting world of Magento. Most tutorials out there don't really explain why the code snippets work, making it hard to modify them to your needs.
Hi,
i am agree with your answer
As a Drupalmint magento web developers, I have find this code and hope it will be useful.
00001 <?php
00002 /**
00003 * Magento
00004 *
00005 * NOTICE OF LICENSE
00006 *
00007 * This source file is subject to the Open Software License (OSL 3.0)
00008 * that is bundled with this package in the file LICENSE.txt.
00009 * It is also available through the world-wide-web at this URL:
00010 * http://opensource.org/licenses/osl-3.0.php
00011 * If you did not receive a copy of the license and are unable to
00012 * obtain it through the world-wide-web, please send an email
00013 * to license@magentocommerce.com so we can send you a copy immediately.
00014 *
00015 * DISCLAIMER
00016 *
00017 * Do not edit or add to this file if you wish to upgrade Magento to newer
00018 * versions in the future. If you wish to customize Magento for your
00019 * needs please refer to http://www.magentocommerce.com for more information.
00020 *
00021 * @category Varien
00022 * @package Varien_Autoload
00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
00025 */
00026
00027 /**
00028 * Classes source autoload
00029 */
00030 class Varien_Autoload
00031 {
00032 const SCOPE_FILE_PREFIX = '__';
00033
00034 static protected $_instance;
00035 static protected $_scope = 'default';
00036
00037 protected $_isIncludePathDefined= null;
00038 protected $_collectClasses = false;
00039 protected $_collectPath = null;
00040 protected $_arrLoadedClasses = array();
00041
00042 /**
00043 * Class constructor
00044 */
00045 public function __construct()
00046 {
00047 $this->_isIncludePathDefined = defined('COMPILER_INCLUDE_PATH');
00048 if (defined('COMPILER_COLLECT_PATH')) {
00049 $this->_collectClasses = true;
00050 $this->_collectPath = COMPILER_COLLECT_PATH;
00051 }
00052 self::registerScope(self::$_scope);
00053 }
00054
00055 /**
00056 * Singleton pattern implementation
00057 *
00058 * @return Varien_Autoload
00059 */
00060 static public function instance()
00061 {
00062 if (!self::$_instance) {
00063 self::$_instance = new Varien_Autoload();
00064 }
00065 return self::$_instance;
00066 }
00067
00068 /**
00069 * Register SPL autoload function
00070 */
00071 static public function register()
00072 {
00073 spl_autoload_register(array(self::instance(), 'autoload'));
00074 }
00075
00076 /**
00077 * Load class source code
00078 *
00079 * @param string $class
00080 */
00081 public function autoload($class)
00082 {
00083 if ($this->_collectClasses) {
00084 $this->_arrLoadedClasses[self::$_scope][] = $class;
00085 }
00086 if ($this->_isIncludePathDefined) {
00087 $classFile = $class;
00088 } else {
00089 $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
00090 }
00091 $classFile.= '.php';
00092 //echo $classFile;die();
00093 return include $classFile;
00094 }
00095
00096 /**
00097 * Register autoload scope
00098 * This process allow include scope file which can contain classes
00099 * definition which are used for this scope
00100 *
00101 * @param string $code scope code
00102 */
00103 static public function registerScope($code)
00104 {
00105 self::$_scope = $code;
00106 @include self::SCOPE_FILE_PREFIX.$code.'.php';
00107 }
00108
00109 /**
00110 * Get current autoload scope
00111 *
00112 * @return string
00113 */
00114 static public function getScope()
00115 {
00116 return self::$_scope;
00117 }
00118
00119 /**
00120 * Class destructor
00121 */
00122 public function __destruct()
00123 {
00124 if ($this->_collectClasses) {
00125 $this->_saveCollectedStat();
00126 }
00127 }
00128
00129 /**
00130 * Save information about used classes per scope with class popularity
00131 * Class_Nameopularity
00132 *
00133 * @return Varien_Autoload
00134 */
00135 protected function _saveCollectedStat()
00136 {
00137 if (!is_dir($this->_collectPath)) {
00138 @mkdir($this->_collectPath);
00139 @chmod($this->_collectPath, 0777);
00140 }
00141
00142 if (!is_writeable($this->_collectPath)) {
00143 return $this;
00144 }
00145
00146 foreach ($this->_arrLoadedClasses as $scope => $classes) {
00147 $file = $this->_collectPath.DIRECTORY_SEPARATOR.$scope.'.csv';
00148 $data = array();
00149 if (file_exists($file)) {
00150 $data = explode("\n", file_get_contents($file));
00151 foreach ($data as $index => $class) {
00152 $class = explode(':', $class);
00153 $searchIndex = array_search($class[0], $classes);
00154 if ($searchIndex !== false) {
00155 $class[1]+=1;
00156 unset($classes[$searchIndex]);
00157 }
00158 $data[$index] = $class[0].':'.$class[1];
00159 }
00160 }
00161 foreach ($classes as $class) {
00162 $data[] = $class . ':1';
00163 }
00164 file_put_contents($file, implode("\n", $data));
00165 }
00166 return $this;
00167 }
00168 }
Hello,
Here's the answer you need to know => http://alanstorm.com/magento_class_abstration_autoload
Hope this would help you out.
Regards,
Dennies Bright
I think google is the best ally of yours, you can search your requirement Wikipedia is the best place where you can get results of all inquiries. Anyways, if you are looking development services we can help you out, before moving on we will explain all the queries that you want.
visit us here: website designing company in india
This is very useful information. I am also a web developer, but I have never come across something like this I think I have not come to a scenario like this till now.
web designing company in Hyderabad | best urologist in Hyderabad urologist Hyderabad, best urologist Hyderabad, urology | visit for website design in Hyderabad, Web design | website design company in Hyderabad
|
Bookmarks