ApiController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\Controller;
  12. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  16. /**
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. */
  19. class ApiController extends Controller
  20. {
  21. /**
  22. * @Template()
  23. * @Route("/packages.json", name="packages")
  24. */
  25. public function packagesAction()
  26. {
  27. $version = $this->get('request')->query->get('version');
  28. $packages = $this->get('doctrine')
  29. ->getRepository('Packagist\WebBundle\Entity\Package')
  30. ->findAll();
  31. $data = '{';
  32. $cnt = count($packages);
  33. foreach ($packages as $idx => $package) {
  34. $data .= '"'.$package->getName().'":'.$package->toJson();
  35. if ($cnt > $idx+1) {
  36. $data .= ',';
  37. }
  38. }
  39. $data .= '}';
  40. return new Response($data, 200, array('Content-Type' => 'application/json'));
  41. }
  42. }