Last active
August 29, 2015 14:01
-
-
Save epson121/ddeb509e5145ea28cb11 to your computer and use it in GitHub Desktop.
List all rewrites in magento application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$folders = array('app/code/local/', 'app/code/community/');//folders to parse | |
$configFiles = array(); | |
foreach ($folders as $folder){ | |
$files = glob($folder.'*/*/etc/config.xml');//get all config.xml files in the specified folder | |
$configFiles = array_merge($configFiles, $files);//merge with the rest of the config files | |
} | |
$rewrites = array();//list of all rewrites | |
foreach ($configFiles as $file){ | |
$pattern = '/.*\/.*\/.*\/(.*\/.*)\/.*\/.*/'; | |
preg_match($pattern, $file, $match); | |
$dom = new DOMDocument; | |
$dom->loadXML(file_get_contents($file)); | |
$xpath = new DOMXPath($dom); | |
$path = '//rewrite/*';//search for tags named 'rewrite' | |
$text = $xpath->query($path); | |
foreach ($text as $rewriteElement){ | |
$type = $rewriteElement->parentNode->parentNode->parentNode->tagName;//what is overwritten (model, block, helper) | |
$parent = $rewriteElement->parentNode->parentNode->tagName;//module identifier that is being rewritten (core, catalog, sales, ...) | |
$name = $rewriteElement->tagName;//element that is rewritten (layout, product, category, order) | |
foreach ($rewriteElement->childNodes as $element){ | |
$rewritesByModule[$match[1]][$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it | |
$rewritesByType[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it | |
} | |
} | |
} | |
echo "<pre>";print_r($rewritesByType); | |
echo "<hr><hr>"; | |
echo "<pre>";print_r($rewritesByModule); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saved for later from http://magento.stackexchange.com/questions/1594/how-do-i-get-a-list-of-all-class-rewrites