Skip to content

Instantly share code, notes, and snippets.

@LiamKarlMitchell
Created March 1, 2019 06:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LiamKarlMitchell/8d88c5a23df6ea71525524be422b07de to your computer and use it in GitHub Desktop.
Save LiamKarlMitchell/8d88c5a23df6ea71525524be422b07de to your computer and use it in GitHub Desktop.
Dumps container, referenceContainer, block and referenceBlock names and locations from Magento2 site.
<?php
$instructions = array("container", "referenceContainer", "block", "referenceBlock");
foreach ($instructions as $instruction) {
$containers = array();
$fp = fopen('debug_'.$instruction.'.txt', 'w');
$command = 'egrep -r -i --include \*.xml "<'.$instruction.'".*?"name=" *';
exec($command, $output);
$container_max_length = 1;
$pattern = '/(.*?):.*<'.$instruction.'.*name="(.*?)".*/';
foreach ($output as $subject) {
preg_match($pattern, $subject, $matches);
$containers[$matches[2]][] = $matches[1];
if (strlen($matches[2]) > $container_max_length) $container_max_length = strlen($matches[2]);
}
$n=1;
ksort($containers);
foreach ($containers as $k => $v) {
fprintf($fp, "%6s", "$n. ");
fprintf($fp, "%-".$container_max_length."s".$v[0]."\n", $k);
$i=1;
while (isset($v[$i])) {
fprintf($fp, " %-".$container_max_length."s".$v[$i]."\n", "");
$i++;
}
$n++;
}
fclose($fp);
}
?>
@LiamKarlMitchell
Copy link
Author

I can't really take credit for this, found it on Stack Overflow shared by maxagaz and just modified it to dump them all to txt file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment