Skip to content

Instantly share code, notes, and snippets.

@bramstroker
Last active August 29, 2015 14:11
Show Gist options
  • Save bramstroker/619a801ded18996dc59c to your computer and use it in GitHub Desktop.
Save bramstroker/619a801ded18996dc59c to your computer and use it in GitHub Desktop.
class MyResource extends AbstractResourceListener implements ResourceInterface
{
public function fetch($id)
{
$entity = $this->getEntityById($id, false);
if ($entity === null) {
return new ApiProblemResponse(new ApiProblem(404, 'Entity with ID ' . $id . ' not found'));
}
return $entity;
}
}
case 'get':
$id = $this->getIdentifier($routeMatch, $request);
if ($id !== false) {
$action = 'get';
$return = $this->get($id);
break;
}
$action = 'getList';
$return = $this->getList();
break;
// HEAD
case 'head':
$id = $this->getIdentifier($routeMatch, $request);
if ($id === false) {
$id = null;
}
$action = 'head';
$this->head($id);
$response = $e->getResponse();
$response->setContent('');
$return = $response;
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment