Skip to content

Instantly share code, notes, and snippets.

@m4munib
Created May 29, 2016 17:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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