Last active
March 1, 2017 16:22
-
-
Save haringsrob/6b4b2b9862f66feb8a5a4c493c7e1fdb to your computer and use it in GitHub Desktop.
Automatic drush alias generation based on directory
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 | |
$root = "/home/rob/Sites/"; | |
$allowed_dirs = [ | |
'web', | |
'wwwroot', | |
'build', | |
]; | |
foreach (new DirectoryIterator($root) as $main_dir) { | |
if ($main_dir->isDot() || !$main_dir->isDir()) { continue; } | |
foreach (new DirectoryIterator($main_dir->getPath() . '/' . $main_dir->getFilename()) as $sub_dir) { | |
if ($sub_dir->isDot() || !$sub_dir->isDir()) { continue; } | |
if ($sub_dir->getFilename() == '.git') { continue; } | |
foreach ($allowed_dirs as $check_dir) { | |
if (file_exists($sub_dir->getPath() . '/' . $sub_dir->getFilename() . '/' . $check_dir)) { | |
$dir = $check_dir; | |
break; | |
} | |
} | |
if (isset($dir)) { | |
$aliases[$sub_dir->getFilename()] = [ | |
'root' => $sub_dir->getPath() . '/' . $sub_dir->getFilename() . '/' . $dir, | |
'uri' => $main_dir->getFilename() . '.' . $sub_dir->getFilename() . '.' . $dir . '.dev', | |
]; | |
unset($dir); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment