* Nils Adermann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Packagist\WebBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; /** * @author Jordi Boggiano */ class ApiController extends Controller { /** * @Template() * @Route("/packages.json", name="packages") */ public function packagesAction() { $version = $this->get('request')->query->get('version'); $packages = $this->get('doctrine') ->getRepository('Packagist\WebBundle\Entity\Package') ->findAll(); $data = array(); foreach ($packages as $package) { $data[$package->getName()] = $package->toArray(); } return new Response(json_encode($data), 200, array('Content-Type' => 'application/json')); } }