Created
May 29, 2016 17:07
-
-
Save m4munib/0560c121d0213f0800b847891b73d780 to your computer and use it in GitHub Desktop.
User Signup using PHP Command Pattern
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 | |
class SignupCommand extends AbstractCommand { | |
private $oUser = null; | |
private $data = array(); | |
function __construct($oUser, $data) { | |
$this->oUser = $oUser; | |
$this->data = $data; | |
} | |
protected function processCommand() { | |
return $this->oUser->Create($this->data); | |
} | |
} | |
$oUser = new User(); /* Dummy User Object*/ | |
$data = array( | |
'name' => "John Doe", | |
'username' => "jdoe", | |
'email' => "john@doe.com", | |
); | |
/* Example */ | |
$oSignupCommand = new SignupCommand($oUser, $data); | |
$isExecuted = $oSignupCommand->execute()->isExecuted(); | |
if($isExecuted){ | |
//handle success | |
}else{ | |
//handle error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment