WebController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Packagist\WebBundle\Form\ConfirmForm;
  13. use Packagist\WebBundle\Form\ConfirmFormType;
  14. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  15. use Packagist\WebBundle\Entity\Package;
  16. use Packagist\WebBundle\Entity\Version;
  17. use Packagist\WebBundle\Form\PackageType;
  18. use Packagist\WebBundle\Form\VersionType;
  19. use Symfony\Component\HttpFoundation\RedirectResponse;
  20. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  23. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  24. /**
  25. * @author Jordi Boggiano <j.boggiano@seld.be>
  26. */
  27. class WebController extends Controller
  28. {
  29. protected function getUser()
  30. {
  31. return $user = $this->get('security.context')->getToken()->getUser();
  32. }
  33. /**
  34. * @Template()
  35. * @Route("/", name="home")
  36. */
  37. public function indexAction()
  38. {
  39. $packages = $this->get('doctrine')
  40. ->getRepository('Packagist\WebBundle\Entity\Package')
  41. ->findAll();
  42. return array('packages' => $packages, 'page' => 'home');
  43. }
  44. /**
  45. * @Template()
  46. * @Route("/submit", name="submit")
  47. */
  48. public function submitPackageAction()
  49. {
  50. $package = new Package;
  51. $form = $this->get('form.factory')->create(new PackageType, $package);
  52. $request = $this->getRequest();
  53. if ($request->getMethod() == 'POST') {
  54. $form->bindRequest($request);
  55. $provider = $this->get('packagist.repository_provider');
  56. $repository = $provider->getRepository($package->getRepository());
  57. $composerFile = $repository->getComposerInformation('master');
  58. $package->setName($composerFile['name']);
  59. if ($form->isValid()) {
  60. $user = $this->getUser();
  61. $package->addMaintainers($user);
  62. $em = $this->getDoctrine()->getEntityManager();
  63. $em->persist($package);
  64. $em->flush();
  65. return new RedirectResponse($this->generateUrl('home'));
  66. }
  67. }
  68. return array('form' => $form->createView(), 'page' => 'submit');
  69. }
  70. /**
  71. * @Template()
  72. * @Route("/about", name="about")
  73. */
  74. public function aboutAction()
  75. {
  76. return array();
  77. }
  78. }