/** * Merging one group of classed (for one alias) * * @param array $classes * @return boolean */ public function merge($classes) { $this->_latestMergedFiles = array(); if (!is_array($classes) || empty($classes)) { return false; } $filename = md5($classes[count($classes) - 1]['child']); $filepath = $this->_rewriteDir . $filename . '.php'; $fileContent = ''; $fileContent .= '<?php' . "\r\n"; $fileContent .= '/* DO NOT MODIFY THIS FILE! THIS IS TEMPORARY FILE AND WILL BE RE-GENERATED AS SOON AS CACHE CLEARED. */' . "\r\n"; $rewriteClass = new Aitoc_Aitsys_Model_Rewriter_Class(); $bOmitRewriteChain = false; $iEncodedCount = 0; //set count of encoded classes foreach ($classes as $parent => $class) { if (isset($class['encoded']) && $class['encoded']) { $iEncodedCount++; } } foreach ($classes as $parent => $class) { if ($bOmitRewriteChain) { continue; } $bEncodedCurrent = false; /** * Different strategy for normal and abstract rewrites */ if (is_array($class)) { // for abstract rewrites $contentFrom = $class['contents']; $parent = $class['parent']; $child = $class['child']; $bEncodedCurrent = isset($class['encoded']) && $class['encoded'] ? true : false; if ($bEncodedCurrent) { $iEncodedCount--; } } else { // parent is parent $contentFrom = $parent; $child = $class; } /** * The last $child is always magento base class */ $contents = $rewriteClass->getContents($contentFrom); $this->_latestMergedFiles[$contentFrom] = $rewriteClass->getClassPath($contentFrom); if ($child) { $contents = preg_replace('/' . $contentFrom . '(\\s+)(extends)?(\\s+)?([^\\s{]+)?/', "{$parent} \$2 {$child}", $contents, 1); } else { $contents = preg_replace('/' . $contentFrom . '(\\s+)(extends)?(\\s+)?([^\\s{]+)?/', "{$parent} \$2 \$4", $contents, 1); } if ($bEncodedCurrent) { if ($contentFrom != $parent) { $bOmitRewriteChain = true; continue; } else { $contents = ($iEncodedCount > 0 ? '//' : '') . 'require_once("' . $rewriteClass->getClassPath($parent) . '");'; } } $fileContent .= $contents; $fileContent .= "\r\n\r\n"; } if ($bOmitRewriteChain) { return false; } $this->tool()->filesystem()->putFile($filepath, $fileContent); return $filename; }
/** * @param $class * @param $array * @return bool */ protected function _findInheriatanceClass($class, &$array) { $classModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $content = $classModel->getContents($class); if (empty($content)) { return false; } if (in_array($class, $array)) { //delete static AITOC rewrite. Not use preg_replace because 100k limit if ((strpos($class, 'Aitoc') === 0 || strpos($class, 'AdjustWare') === 0) && strpos($content, 'AITOC static rewrite inserts start') !== false) { $maches = array(); preg_match('/\\/\\* default extends start \\*\\/(\\n)?(\\s+)?class(\\s+)?' . $class . '_Aittmp(\\s+)extends(\\s+)?([^\\s{]+)?(\\s+)?{}(\\n)?(\\s+)?\\/\\* default extends end \\*\\//', $content, $maches); //$content = preg_replace('/\/\* AITOC static rewrite inserts start \*\/(.|\n)*\/\* AITOC static rewrite inserts end \*\/(\n)?/', '', $content, 1); //$content = preg_replace('/(class)(\s+)?'.$class.'(\s+)(extends)?(\s+)?'.$class.'_Aittmp/', 'class '.$class.' extends '.$maches[6], $content, 1); $content = substr($content, strpos($content, '/* AITOC static rewrite inserts end */')); $content = str_replace('/* AITOC static rewrite inserts end */', '', $content); $content = str_replace('class ' . $class . ' extends ' . $class . '_Aittmp', 'class ' . $class . ' extends ' . $maches[6], $content); } $this->_contentArray[$class] = $content; } $this->_checkClassByContent($class, $array, $content); }