4
* This file is part of Packagist.
6
* (c) Jordi Boggiano <j.boggiano@seld.be>
7
* Nils Adermann <naderman@naderman.de>
9
* For the full copyright and license information, please view the LICENSE
10
* file that was distributed with this source code.
13
namespace Packagist\WebBundle\Controller;
15
use Packagist\WebBundle\Form\ConfirmPackageType;
16
use Packagist\WebBundle\Form\ConfirmForm;
17
use Packagist\WebBundle\Form\ConfirmFormType;
18
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
19
use Packagist\WebBundle\Entity\Package;
20
use Packagist\WebBundle\Entity\Version;
21
use Packagist\WebBundle\Form\PackageType;
22
use Packagist\WebBundle\Form\VersionType;
23
use Symfony\Component\HttpFoundation\RedirectResponse;
24
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
25
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
27
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
30
* @author Jordi Boggiano <j.boggiano@seld.be>
32
class WebController extends Controller
34
protected function getUser()
36
return $user = $this->get('security.context')->getToken()->getUser();
41
* @Route("/", name="home")
43
public function indexAction()
45
$packages = $this->get('doctrine')
46
->getRepository('Packagist\WebBundle\Entity\Package')
49
return array('packages' => $packages, 'page' => 'home');
54
* @Route("/submit", name="submit")
56
public function submitPackageAction()
58
$package = new Package;
59
$form = $this->createForm(new PackageType, $package);
61
$request = $this->getRequest();
62
if ($request->getMethod() == 'POST') {
63
$form->bindRequest($request);
64
$children = $form->getChildren();
65
if($children['repository']->isValid()) {
66
$this->get('session')->set('repository', $package->getRepository());
68
return new RedirectResponse($this->generateUrl('confirm'));
72
return array('form' => $form->createView(), 'page' => 'submit');
77
* @Route("/submit/confirm", name="confirm")
79
public function confirmPackageAction()
81
$session = $this->get('session');
82
$em = $this->getDoctrine()->getEntityManager();
83
$package = new Package;
85
if($repository = $session->get('repository')) {
86
$session->remove('repository');
87
$package->setRepository($repository);
88
$package->fromProvider($this->get('packagist.repository_provider'));
91
$form = $this->createForm(new ConfirmPackageType, $package);
93
$request = $this->getRequest();
94
if ($request->getMethod() == 'POST') {
95
$form->bindRequest($request);
96
$package->fromProvider($this->get('packagist.repository_provider'));
98
$children = $form->getChildren();
99
if ($children['repository']->isValid()) {
100
$user = $this->getUser();
101
$package->addMaintainers($user);
103
$em = $this->getDoctrine()->getEntityManager();
104
$em->persist($package);
107
$this->get('session')->remove('repository');
109
return new RedirectResponse($this->generateUrl('home'));
111
} elseif (!$repository) {
112
return new RedirectResponse($this->generateUrl('submit'));
115
return array('form' => $form->createView(), 'package' => $package, 'page' => 'submit');
120
* @Route("/about", name="about")
122
public function aboutAction()