Ejemplo n.º 1
0
 /**
  * @param int|string $id
  * @param string $provider
  * @return Response
  */
 public function showAction($id, $provider)
 {
     // this handled by routing loader, but not throw error in this conditional case here
     if (null === ($poserProvider = $this->manager->get($provider))) {
         throw new NotFoundHttpException(sprintf('Provider for badge "%s" not found', $provider));
     }
     $poser = $poserProvider->getPoser($id);
     $content = $this->poser->generate($poser->getSubject(), $poser->getStatus(), $poser->getColor(), 'flat');
     return new Response($content, 200, ['Cache-Control' => 's-maxage=' . $this->badgeLifetime . ', public', 'Content-Disposition' => sprintf('inline; filename="%s-%s.svg"', $provider, $id), 'Content-Type' => 'image/svg+xml;charset=utf-8']);
 }
Ejemplo n.º 2
0
 /**
  * @param Statistics $statistics
  * @return Image
  */
 private function createOpenIssuesBadge(Statistics $statistics)
 {
     $ratio = $statistics->openIssuesRatio;
     if ($ratio < 0.1) {
         $color = self::COLOR_OK;
     } elseif ($ratio < 0.2) {
         $color = self::COLOR_WARNING;
     } else {
         $color = self::COLOR_DANGER;
     }
     return $this->poser->generate('open issues', round($ratio * 100) . '%', $color, 'svg');
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $subject = $input->getArgument('subject');
     $status = $input->getArgument('status');
     $color = $input->getArgument('color');
     if ($input->getOption('format')) {
         $this->format = $input->getOption('format');
     }
     try {
         $imageContent = $this->poser->generate($subject, $status, $color, $this->format);
         if ($input->getOption('path')) {
             $this->storeImage($output, $input->getOption('path'), $imageContent);
         } else {
             $this->flushImage($output, $imageContent);
         }
     } catch (\Exception $e) {
         $this->printHeaderOnce($output);
         throw $e;
     }
 }
Ejemplo n.º 4
0
 public function createFromBadge(Badge $badge)
 {
     $content = $this->generator->generate($badge->getSubject(), $badge->getStatus(), trim($badge->getHexColor(), '#'), $badge->getFormat());
     return Image::create((string) $badge, $content, $badge->getFormat());
 }