Skip to content

Instantly share code, notes, and snippets.

@haringsrob
Last active March 1, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haringsrob/6b4b2b9862f66feb8a5a4c493c7e1fdb to your computer and use it in GitHub Desktop.
Save haringsrob/6b4b2b9862f66feb8a5a4c493c7e1fdb to your computer and use it in GitHub Desktop.
Automatic drush alias generation based on directory
<?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