Skip to content

Instantly share code, notes, and snippets.

@helhum
Created November 3, 2015 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helhum/c582225f8397310a59e0 to your computer and use it in GitHub Desktop.
Save helhum/c582225f8397310a59e0 to your computer and use it in GitHub Desktop.
Dummy IDE file for class aliases
<?php
error_reporting(E_ALL);
$aliasMapFile = '/Migrations/Code/ClassAliasMap.php';
$ideFile = '/Migrations/Code/LegacyClassesForIde.php';
$extensionDir = getcwd() . '/typo3/sysext/';
$map = array();
$iterator = new DirectoryIterator($extensionDir);
foreach ($iterator as $fileinfo) {
/** @var $fileinfo DirectoryIterator */
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
if (is_file($fileinfo->getPathname() . $aliasMapFile)) {
$map = require $fileinfo->getPathname() . $aliasMapFile;
$template = '
namespace%s{
/**
* @deprecated since 6.0, removed since 7.0
*/
%s%s %s extends %s
{
}
}';
$res = '<?php
namespace {
die(\'Access denied\');
}
';
foreach ($map as $old => $new) {
if (preg_match('/Interface$/', $new)) {
$kind = 'interface';
} else {
$kind = 'class';
if (strpos($new, 'Interface') !== FALSE) {
// echo 'Interface: ' . $new . chr(10);
}
}
if (!preg_match('/Exception$/', $new) && strpos($new, 'Exception') !== FALSE) {
// echo 'Exception: ' . $new . chr(10);
}
$explodedNew = explode('\\', $new);
$classname = array_pop($explodedNew);
if (preg_match('/^Abstract/', $classname)) {
$abstract = 'abstract ';
} else {
if (strpos($classname, 'Abstract') !== FALSE) {
// echo 'Abstract: ' . $new . chr(10);
}
$abstract = '';
}
if ($kind === 'interface') {
$abstract = '';
}
if (strpos($old, '\\') === FALSE) {
$namespace = ' ';
} else {
$oldExploded = explode('\\', $old);
$old = array_pop($oldExploded);
$namespace = ' ' . implode($oldExploded, '\\') . ' ';
}
$res .= sprintf($template, $namespace, $abstract, $kind, $old, '\\' . $new) . chr(10);
}
$res .= chr(10);
// echo $res;
file_put_contents($fileinfo->getPathname() . $ideFile, $res);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment