Skip to content

Instantly share code, notes, and snippets.

@sbuzonas
Created February 6, 2015 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbuzonas/e8452798c7473449c94f to your computer and use it in GitHub Desktop.
Save sbuzonas/e8452798c7473449c94f to your computer and use it in GitHub Desktop.
CommandInterface suggestion
abstract class InstallationCommand extends Command
{
abstract public function install();
}
class MyInstaller extends InstallationCommand
{
public function install()
{
// do stuff
}
}
class ThirdPartyCommand extends Command {}
class ThirdPartyInstaller extends InstallationCommand
{
// a bunch of methods copy pasted from ThirdPartyCommand
public function install()
{
// do stuff
}
}
class InstallerConsumingCommand extends Command {
public function addInstaller(InstallationCommand $installer) {
$this->installers[] = $installer;
}
}
interface InstallationCommandInterface extends CommandInterface
{
public function install();
}
class MyInstaller extends Command implements InstallationCommandInterface
{
public function install()
{
// do stuff
}
}
class ThirdPartyCommand extends Command {}
class ThirdPartyInstaller extends ThirdPartyCommand implements InstallationCommandInterface
{
public function install()
{
// do stuff
}
}
class InstallerConsumingCommand extends Command {
public function addInstaller($installer) {
if (!($installer instanceof Command && $installer instanceof InstallationCommandInterface)) {
throw new \InvalidArgumentException('You need to extend Command and implement InstallationCommandInterface');
}
$this->installers[] = $installer;
}
}
interface InstallationCommandInterface extends CommandInterface
{
public function install();
}
class MyInstaller extends Command implements InstallationCommandInterface
{
public function install()
{
// do stuff
}
}
class ThirdPartyCommand extends Command {}
class ThirdPartyInstaller extends ThirdPartyCommand implements InstallationCommandInterface
{
public function install()
{
// do stuff
}
}
class InstallerConsumingCommand extends Command {
public function addInstaller(InstallationCommandInterface $installer) {
$this->installers[] = $installer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment