Skip to content

Instantly share code, notes, and snippets.

@m4munib
Created May 29, 2016 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4munib/3b27b808b28cfc4a993322c2c7d1e950 to your computer and use it in GitHub Desktop.
Save m4munib/3b27b808b28cfc4a993322c2c7d1e950 to your computer and use it in GitHub Desktop.
Abstract Class - PHP Command
<?php
interface InterfaceCommand {
function execute();
}
abstract class AbstractCommand implements InterfaceCommand {
/**
*
* @var bool
*/
protected $isExecuted = false;
/**
*
* @var mixed
*/
protected $response;
/**
*
* @return mixed
*/
public function getResponse() {
return $this->response;
}
/**
*
* @return bool
*/
public function isExecuted() {
return $this->isExecuted;
}
/**
* This method will be invoked before Actual Command's execution
*/
public function preExecution() {
}
/**
* Abstract Method
* Execute a Command
* @return mixed | $response
*/
abstract protected function processCommand();
/**
* This method will be invoked after Actual Command's execution
*/
public function postExecution() {
}
/**
* Execute Command
* @uses: processCommand()
*
* @param void
* @return mixed | $response
*/
public final function execute() {
$this->preExecution();
$this->response = $this->processCommand();
if ($this->response == true) {
$this->isExecuted = true;
}
$this->postExecution();
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment