Abstract Class - PHP Command
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 | |
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