Skip to content

Instantly share code, notes, and snippets.

@lpj145
Created November 19, 2017 01:08
Show Gist options
  • Save lpj145/c51e2a9a41af2eca29fc00fa03fe467e to your computer and use it in GitHub Desktop.
Save lpj145/c51e2a9a41af2eca29fc00fa03fe467e to your computer and use it in GitHub Desktop.
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