How do I get a list of all class rewrites?
Have a look at the n98-magerun utility:
Rewrite List
Lists all registered class rewrites:
$ n98-magerun.phar dev:module:rewrite:list
Rewrite Conflicts
Lists all duplicated rewrites and tells you which class is loaded by Magento. The command checks class inheritance in order of your module dependencies.
n98-magerun.phar dev:module:rewrite:conflicts [--log-junit="..."]
If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.
You can also log the conflicts to a JUnit Style XML file for further analysis, for example on a continues integration server.
Disclaimer: semi-self-link / I am involved in that project
Here a small one-liner that gives you all active rewrites:
print_r(Mage::getConfig()->getNode()->xpath('//global//rewrite'));
To limit it by object type, add models, blocks, or helpers to the xpath respectively.
For example:
Mage::getConfig()->getNode()->xpath('//global/models//rewrite')
here is a small script I use to check if any models, blocks or helpers are overwritten. Unfortunately it does not work for controllers and it takes into account the disabled modules also. But from my point of view this is no big deal.
The main idea is to parse the config files and look for the <rewrite>
tag.
Create a php file on the same level as index.php
. Let's call it rewrites.php
, with this content:
<?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){
$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){
$rewrites[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it
}
}
}
echo "<pre>";print_r($rewrites);
when calling it in a browser you should see something like this:
Array
(
[models] => Array
(
[core/layout] => Array
(
[0] => Namespace_Module_Model_Core_Layout
[1] => Namespace1_Module1_Model_Core_Layout //if the second element is present it means there is a possible conflict
)
[...] => ....
)
[blocks] => ...
[helpers] => ...
)
this means that the model 'core/layout'
is overwritten by Namespace_Module_Model_Core_Layout
If you have 2 or more values in the array ['core/layout'] it means there is a conflict.
And you can easily identify the module that overwrites something based on Namespace
and Module