/** * Retrieves post with id $id or throws an exception if it doesn't exist * * @param $id * * @return Post * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function getPost($id) { $post = $this->postManager->findOneBy(array('id' => $id)); if (null === $post) { throw new NotFoundHttpException(sprintf('Post (%d) not found', $id)); } return $post; }