Skip to content

Instantly share code, notes, and snippets.

@m4munib
Created May 29, 2016 17:07
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 m4munib/0560c121d0213f0800b847891b73d780 to your computer and use it in GitHub Desktop.
Save m4munib/0560c121d0213f0800b847891b73d780 to your computer and use it in GitHub Desktop.
User Signup using PHP Command Pattern
<?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