Created
January 29, 2014 03:57
-
-
Save lividgreen/8681575 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 | |
// Base of any runner | |
abstract class Runner { | |
public abstract function run(); | |
} | |
abstract class Configuration { | |
// TODO validation, defaults etc. | |
} | |
trait Console { | |
public function say($text) { | |
echo $text; | |
} | |
} | |
// A user-defined tool ================================================================================================= | |
class ToolConfiguration extends Configuration { | |
private $parameter; | |
public function setParameter($parameter) { | |
$this->parameter = $parameter; | |
} | |
public function getParameter() { | |
return $this->parameter; | |
} | |
} | |
class ToolRunner extends Runner { | |
use Console; | |
private $configuration; | |
public function __construct(ToolConfiguration $configuration) { | |
$this->configuration = $configuration; | |
} | |
public function run() { | |
$this->say($this->configuration->getParameter()); | |
} | |
} | |
trait Tool { | |
public function tool(ToolConfiguration $configuration) { | |
$runner = new ToolRunner($configuration); | |
$runner->run(); | |
} | |
} | |
// list of commands | |
class Commands { | |
use Tool, Console; | |
public function command() { | |
$this->say('Answer is: '); | |
$toolConfiguration = new ToolConfiguration(); | |
$toolConfiguration->setParameter(42); | |
$this->tool($toolConfiguration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment