Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drush automagic site aliases
<?php
/**
* @file
* Setup site aliases for local sites.
*
* Expects the following setup:
* SITES_DIR/
* site.local/public_html
* site2.local/public_html
*
* @todo
* - Detect Drupal (if it can be done efficiently)
* - Some kind of cache perhaps, this might get slow
*/
// Absolute path to sites directory
define('SITES_DIR', '/path/to/your/sites/');
// Name of public folder
define('PUBLIC_DIR', 'public_html');
// Local "domain"
define('DOMAIN', '.local');
// Automatically set up local site aliases
$di = new DirectoryIterator(SITES_DIR);
foreach ($di as $dir) {
if ($dir->isDir() && !$dir->isDot()) {
$path = $dir->getPathname() . '/' . PUBLIC_DIR;
$aliases[$dir->getBasename(DOMAIN)] = array(
'uri' => $dir->getFilename(),
'path' => $path,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.