public static function instance() { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
public function init($observer) { try { Aitoc_Aitsys_Model_Rewriter_Autoload::register(); } catch (Exception $e) { Mage::log((string) $e, false, 'rewriter.log', true); } }
public function init($observer) { if (!Mage::registry('aitsys_autoload_initialized')) { Aitoc_Aitsys_Model_Rewriter_Autoload::register(); } elseif (Mage::registry('aitsys_autoload_initialized_base')) { $rewriter = new Aitoc_Aitsys_Model_Rewriter(); $rewriter->preRegisterAutoloader(); Mage::unregister('aitsys_autoload_initialized_base'); } }
public function prepare() { $this->_merge = new Aitoc_Aitsys_Model_Rewriter_Merge(); $this->_rewriterConfig = new Aitoc_Aitsys_Model_Rewriter_Config(); // first clearing current class rewrites Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->clearConfig(); $this->_merge->clear(); $rewriteHelper = Mage::helper('aitsys/rewriter'); $result = array(); if ($rewriteHelper->analysisInheritedClasses($this, 'mergeFilesFromClass', $result)) { $this->_rewriterConfig->commit(); } Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->setupConfig(); }
private static function _initSource($file, $key) { if (!Mage::registry('aitoc_test_marker')) { $module = self::get()->platform()->getModule($key)->initSource(); $filename = pathinfo($file, PATHINFO_FILENAME); if ($files = Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->getFileConfig($filename)) { $match = str_replace('_', '/', $key); foreach ($files as $file) { $file = str_replace('\\', '/', $file); if (strstr($file, $match)) { break; } } } $file = str_replace('\\', '/', $file); if (($tmp = strstr($file, 'Aitoc/')) || ($tmp = strstr($file, 'AdjustWare/'))) { $file = $tmp; } else { $file = strstr($file, 'app/'); } Mage::register('aitoc_file:' . md5($file), array($file, $module)); Mage::register('aitoc_block_marker', array($file, $module)); return true; } Mage::unregister('aitoc_test_marker'); return false; }
/** * This file replacement (for /app/code/core/Mage/Core/Model/App.php) is necessary for an early * launch of the Extended Rewriter (ER) subsystem developed by AITOC Inc.. The Magento system * allows only one rewrite to be used by extensions to extend some of the core Magento functionality. * Often different extensions need to use rewrites of the same class in order to work properly. * The `one rewrite` restriction leads to the situation when manual changes in extensions' class * files are required to make extensions work together. Thereby extensions' install and update * processes become much more complex. * * The ER subsystem solves conflicts between AITOCs' and 3rd-party extensions' rewrites by creating * generic chains of rewrites without making direct changes to the extensions' original class files. * It makes the process of modules installation easier and prevents many issues which could be caused * by conflicts of rewrites. * * Please note that this file replacement does NOT affect normal work of the Mageno system - it only * launches an additional subsystem during system initialization. All the extensions developed by AITOC Inc. * could work without this subsystem but it will be much harder to install them as it may be necessary * to manually solve rewrites' conflicts with 3rd-party extension. Please note that solving conflicts * with 3rd-party extensions is out of AITOC's free support policy. The ER subsystem could be disabled * by removing this file but it is strongly not recommended. */ Mage::setRoot(); require_once Mage::getRoot() . '/code/core/Mage/Core/Model/App.php'; $initProcessor = new Aitoc_Aitsys_Model_Init_Processor(); if ($initProcessor->isInstallerEnabled()) { Aitoc_Aitsys_Model_Rewriter_Autoload::register(true); $initProcessor->realize(); } Mage::register('aitsys_autoload_initialized', true); Mage::register('aitsys_autoload_initialized_base', true);
public function prepare() { $merge = new Aitoc_Aitsys_Model_Rewriter_Merge(); $rewriterConfig = new Aitoc_Aitsys_Model_Rewriter_Config(); // first clearing current class rewrites Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->clearConfig(); $merge->clear(); $conflict = new Aitoc_Aitsys_Model_Rewriter_Conflict(); list($conflicts, $rewritesAbstract) = $conflict->getConflictList(); /** * FOR NORMAL REWRITES */ // will combine rewrites by alias groups if (!empty($conflicts)) { foreach ($conflicts as $groupType => $modules) { $groupType = substr($groupType, 0, -1); foreach ($modules as $moduleName => $moduleRewrites) { foreach ($moduleRewrites['rewrite'] as $moduleClass => $rewriteClasses) { /* * $rewriteClasses is an array of class names for one rewrite alias * for example: * Array * ( * [0] => AdjustWare_Deliverydate_Model_Rewrite_AdminhtmlSalesOrderCreate * [4] => Aitoc_Aitcheckoutfields_Model_Rewrite_AdminSalesOrderCreate * [10] => Aitoc_Aitorderedit_Model_Rewrite_AdminSalesOrderCreate * ) */ // building inheritance tree $alias = $moduleName . '/' . $moduleClass; $classModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $inheritanceModel = new Aitoc_Aitsys_Model_Rewriter_Inheritance(); $baseClass = $classModel->getBaseClass($groupType, $alias); $inheritedClasses = $inheritanceModel->build($rewriteClasses, $baseClass); // don't create rewrites for excluded Magento base classes if (in_array($baseClass, $this->tool()->db()->getConfigValue('aitsys_rewriter_exclude_classes', array()))) { continue; } $mergedFilename = $merge->merge($inheritedClasses); if ($mergedFilename) { $rewriterConfig->add($mergedFilename, $rewriteClasses); $rewriterConfig->add(serialize($merge->getLatestMergedFiles()), 'file:' . $mergedFilename); } } } } } /** * FOR ABSTRACT REWRITES (AITOC REALIZATION) */ if (!empty($rewritesAbstract)) { foreach ($rewritesAbstract as $groupType => $modules) { $groupType = substr($groupType, 0, -1); foreach ($modules as $moduleName => $moduleRewrites) { foreach ($moduleRewrites['rewriteabstract'] as $moduleClass => $rewriteClass) { // building inheritance tree $alias = $moduleName . '/' . $moduleClass; $classModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $inheritanceModel = new Aitoc_Aitsys_Model_Rewriter_Inheritance(); $baseClass = $classModel->getBaseClass($groupType, $alias); $inheritedClasses = $inheritanceModel->buildAbstract($rewriteClass, $baseClass); $mergedFilename = $merge->merge($inheritedClasses); if ($mergedFilename) { $rewriterConfig->add($mergedFilename, array($rewriteClass, $baseClass)); } } } } } $rewriterConfig->commit(); Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->setupConfig(); }
protected function _copy($source, $target, $firstIteration = true) { parent::_copy($source, $target, $firstIteration); if (is_file($target) && file_exists($target)) { $platform = Aitoc_Aitsys_Abstract_Service::get()->platform(); $dirs = $platform->getModuleDirs(); foreach ($dirs as $dir) { if ($item = strstr($source, $dir)) { if ($item != $dir) { file_put_contents($target, '<?php class_exists("Mage_Adminhtml_Controller_Action"); require_once "' . $source . '";?>'); return $this; } } } $name = pathinfo($target, PATHINFO_FILENAME); $loader = Aitoc_Aitsys_Model_Rewriter_Autoload::instance(); if ($loader->hasClass($name)) { $path = $loader->getRewriteDir(); $source = <<<SOURCE <?php class_exists("Mage_Adminhtml_Controller_Action"); function _{$name}_autoloader( \$class ) { foreach (glob('{$path}*') as \$path) { require_once \$path; } } if (defined('AITSYS_REWRITED')) return; spl_autoload_register('_{$name}_autoloader'); _{$name}_autoloader(null); spl_autoload_unregister('_{$name}_autoloader'); define('AITSYS_REWRITED',true); SOURCE; file_put_contents($target, ''); } } return $this; }
public static function register($stopProcessing = false) { if (Mage::getConfig()->getNode('default/aitsys/rewriter_status') != 1) { self::$_registered = true; return; } if (!$stopProcessing && !self::$_registered) { $rewriter = new Aitoc_Aitsys_Model_Rewriter(); $rewriter->preRegisterAutoloader(); // unregistering all autoloaders to make our performing first $autoloaders = spl_autoload_functions(); if ($autoloaders && is_array($autoloaders) && !empty($autoloaders)) { foreach ($autoloaders as $autoloader) { spl_autoload_unregister($autoloader); } } // register our autoloader spl_autoload_register(array(self::instance(), 'autoload'), false); // register 1.3.1 and older autoloader if (version_compare(Mage::getVersion(), '1.3.1', 'le')) { spl_autoload_register(array(self::instance(), 'performStandardAutoload'), true); } // register back all unregistered autoloaders if ($autoloaders && is_array($autoloaders) && !empty($autoloaders)) { foreach ($autoloaders as $autoloader) { spl_autoload_register($autoloader, is_array($autoloader) && $autoloader[0] instanceof Varien_Autoload); } } self::$_registered = true; } }