Skip to content

Instantly share code, notes, and snippets.

@lividgreen
Created January 29, 2014 03:57
Show Gist options
  • Save lividgreen/8681575 to your computer and use it in GitHub Desktop.
Save lividgreen/8681575 to your computer and use it in GitHub Desktop.
<?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