Created
October 15, 2014 23:46
-
-
Save prodeveloper/608ab7d6bf887dfcab22 to your computer and use it in GitHub Desktop.
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
/** | |
* Ofcos the classes should be in different files | |
* Assumes you are using a command bus to raise events I happen to love Jeff Way https://github.com/laracasts/Commander | |
* | |
* With this architecture you don't need to modify any existing classes for new headers just add a new class and should work | |
* | |
* More than one class can handle the requests | |
*/ | |
class CommitComment extends GithubRequest { | |
} | |
class Deployment extends GithubRequest{ | |
} | |
class Push extends GithubRequest{ | |
} | |
abstract class GithubRequest{ | |
public $request; | |
function __construct($request) | |
{ | |
$this->request = $request; | |
} | |
} | |
class GitHubEvent{ | |
function __construct($request,$header){ | |
$class=$this->_eventClassFromHeader($header); | |
if(class_exists($class)){ | |
$this->raise(new $class($request)); | |
} | |
else{ | |
throw new UnknownGitHubRequest(); | |
} | |
} | |
/** | |
* @param $header | |
* @return string | |
*/ | |
protected function _eventClassFromHeader($header) | |
{ | |
return $class = studly_case($header); | |
} | |
} | |
class UnknownGitHubRequest extends \Exception { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment