/**
  * @Route("/{reference}", methods={"PUT"}, name="manifest_put")
  *
  * @ParamConverter("manifest", options={"repository_method": "findOneByReferenceOrCreate", "map_method_signature": true})
  *
  * @Security("is_granted('REPO_WRITE', repository)")
  *
  * @link http://docs.docker.com/registry/spec/api/#put-manifest
  */
 public function uploadAction(Request $request, Repository $repository, Manifest $manifest, $reference)
 {
     $manifest->setContent($request->getContent());
     if ($reference !== $manifest->getTag() && $reference !== $manifest->getDigest()) {
         throw new BadRequestHttpException('Provided reference does not match with tag or digest.');
     }
     // TODO: validate layers & signatures
     $this->get('doctrine')->getRepository('AppBundle:Manifest')->save($manifest);
     // Dispatch event
     $event = new ManifestEvent($manifest);
     $this->get('event_dispatcher')->dispatch('delayed', new DelayedEvent('kernel.terminate', 'manifest.push', $event));
     return new Response('', Response::HTTP_CREATED, ['Location' => $this->generateUrl('manifest_get', ['name' => $manifest->getRepository()->getName(), 'reference' => $manifest->getDigest()], UrlGeneratorInterface::ABSOLUTE_URL), 'Docker-Content-Digest' => $manifest->getDigest()]);
 }
 /**
  * @Given I have manifests:
  */
 public function iHaveManifests(TableNode $table)
 {
     $manifestsPath = __DIR__ . '/../fixtures/manifests/';
     $em = $this->getEntityManager();
     foreach ($table->getRows() as $row) {
         $content = file_get_contents($manifestsPath . $row[0]);
         $repository = $em->getRepository('AppBundle:Repository')->findOneByName(json_decode($content, true)['name']);
         $manifest = new Manifest($repository);
         $manifest->setContent($content);
         $em->persist($manifest);
     }
     $em->flush();
 }
    public function incrementPulls(Manifest $manifest)
    {
        // Increment Manifest
        $this->_em->createQuery(<<<DQL
UPDATE AppBundle:Manifest m
SET m.pulls = m.pulls + 1
WHERE m.id = :manifest
DQL
)->setParameter('manifest', $manifest->getId())->execute();
        // Increment Repository
        $this->_em->createQuery(<<<DQL
UPDATE AppBundle:Repository r
SET r.pulls = r.pulls + 1
WHERE r.id = :repository
DQL
)->setParameter('repository', $manifest->getRepository()->getId())->execute();
    }
 private function getPayload(Manifest $manifest)
 {
     $repository = $manifest->getRepository();
     $data = ['push_data' => ['pushed_at' => time()], 'repository' => ['status' => 'Active', 'description' => $repository->getTitle(), 'full_description' => $repository->getDescription(), 'repo_name' => $repository->getName(), 'is_private' => $repository->isPrivate(), 'star_count' => $repository->getStars()]];
     return json_encode($data);
 }