Created
March 31, 2010 00:36
-
-
Save AdrianRossouw/349790 to your computer and use it in GitHub Desktop.
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 | |
function environment_factory($options) { | |
$classes = array('provisionServer' => 'server_eval', 'provisionPlatform' => 'platform_eval', 'provisionSite' => 'site_eval'); | |
foreach ($classes as $class => $callback) { | |
if ($callback($options)) { | |
$className = $class; | |
} | |
else { | |
break; | |
} | |
} | |
$object = new $className($options); | |
return $object; | |
} | |
function server_eval($options) { | |
return TRUE; | |
} | |
class provisionServer { | |
function __construct($options) { | |
$this->hostname = 'localhost'; | |
} | |
} | |
function platform_eval($options) { | |
if ($options['root']) { | |
return true; | |
} | |
} | |
class provisionPlatform extends provisionServer { | |
function __construct($options) { | |
$this->root = $options['root']; | |
} | |
} | |
function site_eval($options) { | |
if ($options['uri']) { | |
return true; | |
} | |
} | |
class provisionSite extends provisionPlatform { | |
function __construct($options) { | |
parent::__construct($options); | |
$this->uri = $options['uri']; | |
} | |
} | |
print_r(environment_factory(array('root' => 1, 'uri' => 2))); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment