Skip to content

Instantly share code, notes, and snippets.

@simme
Created October 3, 2011 13:18
Show Gist options
  • Save simme/1259082 to your computer and use it in GitHub Desktop.
Save simme/1259082 to your computer and use it in GitHub Desktop.
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