Created
May 29, 2016 16:16
-
-
Save m4munib/3b27b808b28cfc4a993322c2c7d1e950 to your computer and use it in GitHub Desktop.
Abstract Class - PHP Command
This file contains hidden or 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