Created
November 19, 2017 01:08
-
-
Save lpj145/c51e2a9a41af2eca29fc00fa03fe467e to your computer and use it in GitHub Desktop.
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
trait DispatchAction | |
{ | |
public function process(ServerRequestInterface $request, DelegateInterface $delegate) | |
{ | |
$dictionary = [ | |
'GET' => 'index', | |
'POST' => 'create', | |
'PUT' => 'edit', | |
'DELETE' => 'delete' | |
]; | |
if (method_exists($this, 'mapMethods')) { | |
$dictionary = array_merge($dictionary, $this->mapMethods()); | |
} | |
if (method_exists($this, $dictionary[$request->getMethod()])) { | |
return $this->{$dictionary[$request->getMethod()]}($request); | |
} | |
throw new \Exception('Not found action: '.$dictionary[$request->getMethod()].' on '.get_class($this)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment