/** * @Route("/{id}", name="icap_badge_api_badge_get", requirements={"id" = "\d+"}, defaults={"_format" = "json"}) */ public function getAction($id) { /** @var \Icap\BadgeBundle\Entity\Badge $badge */ $badge = $this->badgeRepository->find($id); if (null === $badge) { throw new NotFoundHttpException('Badge not found'); } $view = View::create()->setStatusCode(200)->setData($badge); return $this->viewHandler->handle($view); }
/** * {@inheritdoc} * * @throws InvalidConfigurationException if the parameter name is missing * @throws AccessDeniedHttpException if the current user is not authenticated */ public function apply(Request $request, ParamConverter $configuration) { $slug = $request->attributes->get('slug'); $options = $configuration->getOptions(); if (isset($options['check_deleted']) && !$options['check_deleted']) { $this->entityManager->getFilters()->disable('softdeleteable'); } $badge = $this->badgeRepository->findBySlug($slug); if (null === $badge) { throw new NotFoundHttpException(); } $parameterName = $configuration->getName(); $request->attributes->set($parameterName, $badge); return true; }