public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$this->isABadgeController($event->getRequest()->get('_controller'))) {
         return;
     }
     $badge = $this->useCase->createErrorBadge($event->getException(), 'svg');
     $image = $this->imageFactory->createFromBadge($badge);
     $response = ResponseFactory::createFromImage($image, Response::HTTP_INTERNAL_SERVER_ERROR);
     $event->setResponse($response);
 }
예제 #2
0
 /**
  * License action.
  *
  * @param string $repository repository
  *
  * @Route("/{repository}/license",
  *     name="pugx_badge_license",
  *     requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
  *     )
  *
  * @Method({"GET"})
  * @Cache(maxage="3600", smaxage="3600", public=true)
  *
  * @return Response
  */
 public function licenseAction(Request $request, $repository, $format = 'svg')
 {
     $this->useCase = $this->container->get('use_case_badge_license');
     $this->imageFactory = $this->container->get('image_factory');
     if ($request->query->get('format') == 'plastic') {
         $format = 'plastic';
     }
     $badge = $this->useCase->createLicenseBadge($repository, $format);
     $image = $this->imageFactory->createFromBadge($badge);
     return ResponseFactory::createFromImage($image, 200);
 }
예제 #3
0
 /**
  * Downloads action.
  *
  * @param string $repository repository
  * @param string $type       badge type
  * @param string $format
  *
  * @Route("/{repository}/downloads",
  *     name         = "pugx_badge_download",
  *     defaults     = {"type" = "total"},
  *     requirements = {
  *          "repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
  *       }
  *     )
  * @Route("/{repository}/d/{type}",
  *     name         = "pugx_badge_download_type",
  *     requirements = {
  *         "type"       = "total|daily|monthly",
  *         "repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
  *         }
  *     )
  * @Method({"GET"})
  * @Cache(maxage="3600", smaxage="3600", public=true)
  *
  * @todo: remove container
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function downloadsAction(Request $request, $repository, $type, $format = 'svg')
 {
     $this->useCase = $this->container->get('use_case_badge_downloads');
     $this->imageFactory = $this->container->get('image_factory');
     if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
         $format = $request->query->get('format');
     }
     $badge = $this->useCase->createDownloadsBadge($repository, $type, $format);
     $image = $this->imageFactory->createFromBadge($badge);
     return ResponseFactory::createFromImage($image, 200);
 }
예제 #4
0
 /**
  * Version action.
  *
  * @param string $repository repository
  * @param string $latest     latest
  *
  * @Route("/{repository}/version",
  *     name="pugx_badge_version",
  *     defaults     = {"latest" = "stable"},
  *     requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
  *     )
  * @Route("/{repository}/v/{latest}",
  *     name         = "pugx_badge_version_latest",
  *     requirements = {
  *         "latest"     = "stable|unstable",
  *         "repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
  *         }
  *     )
  * @Method({"GET"})
  * @Cache(maxage="3600", smaxage="3600", public=true)
  *
  * @return Response
  */
 public function versionAction(Request $request, $repository, $latest, $format = 'svg')
 {
     if ($request->query->get('format') == 'plastic') {
         $format = 'plastic';
     }
     $this->useCase = $this->container->get('use_case_badge_version');
     $this->imageFactory = $this->container->get('image_factory');
     $function = 'create' . ucfirst($latest) . 'Badge';
     $badge = $this->useCase->{$function}($repository, $format);
     $image = $this->imageFactory->createFromBadge($badge);
     return ResponseFactory::createFromImage($image, 200);
 }