|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Sensio\Bundle\DistributionBundle\Controller; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\ContainerAware; |
|
|
15 |
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* ConfiguratorController. |
|
|
19 |
* |
|
|
20 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
21 |
*/ |
|
|
22 |
class ConfiguratorController extends ContainerAware |
|
|
23 |
{ |
|
|
24 |
/** |
|
|
25 |
* @return Response A Response instance |
|
|
26 |
*/ |
|
|
27 |
public function stepAction($index = 0) |
|
|
28 |
{ |
|
|
29 |
$configurator = $this->container->get('sensio.distribution.webconfigurator'); |
|
|
30 |
|
|
|
31 |
$step = $configurator->getStep($index); |
|
|
32 |
$form = $this->container->get('form.factory')->create($step->getFormType(), $step); |
|
|
33 |
|
|
|
34 |
$request = $this->container->get('request'); |
|
|
35 |
if ('POST' === $request->getMethod()) { |
|
|
36 |
$form->bindRequest($request); |
|
|
37 |
if ($form->isValid()) { |
|
|
38 |
$configurator->mergeParameters($step->update($form->getData())); |
|
|
39 |
$configurator->write(); |
|
|
40 |
|
|
|
41 |
$index++; |
|
|
42 |
|
|
|
43 |
if ($index < $configurator->getStepCount()) { |
|
|
44 |
return new RedirectResponse($this->container->get('router')->generate('_configurator_step', array('index' => $index))); |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
return new RedirectResponse($this->container->get('router')->generate('_configurator_final')); |
|
|
48 |
} |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
return $this->container->get('templating')->renderResponse($step->getTemplate(), array( |
|
|
52 |
'form' => $form->createView(), |
|
|
53 |
'index' => $index, |
|
|
54 |
'count' => $configurator->getStepCount(), |
|
|
55 |
'version' => $this->getVersion(), |
|
|
56 |
)); |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
public function checkAction() |
|
|
60 |
{ |
|
|
61 |
$configurator = $this->container->get('sensio.distribution.webconfigurator'); |
|
|
62 |
|
|
|
63 |
// Trying to get as much requirements as possible |
|
|
64 |
$majors = $configurator->getRequirements(); |
|
|
65 |
$minors = $configurator->getOptionalSettings(); |
|
|
66 |
|
|
|
67 |
$url = $this->container->get('router')->generate('_configurator_step', array('index' => 0)); |
|
|
68 |
|
|
|
69 |
if (empty($majors) && empty($minors)) { |
|
|
70 |
return new RedirectResponse($url); |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
return $this->container->get('templating')->renderResponse('SensioDistributionBundle::Configurator/check.html.twig', array( |
|
|
74 |
'majors' => $majors, |
|
|
75 |
'minors' => $minors, |
|
|
76 |
'url' => $url, |
|
|
77 |
'version' => $this->getVersion(), |
|
|
78 |
)); |
|
|
79 |
} |
|
|
80 |
|
|
|
81 |
public function finalAction() |
|
|
82 |
{ |
|
|
83 |
$configurator = $this->container->get('sensio.distribution.webconfigurator'); |
|
|
84 |
$configurator->clean(); |
|
|
85 |
|
|
|
86 |
try { |
|
|
87 |
$welcomeUrl = $this->container->get('router')->generate('_welcome'); |
|
|
88 |
} catch (\Exception $e) { |
|
|
89 |
$welcomeUrl = null; |
|
|
90 |
} |
|
|
91 |
|
|
|
92 |
return $this->container->get('templating')->renderResponse('SensioDistributionBundle::Configurator/final.html.twig', array( |
|
|
93 |
'welcome_url' => $welcomeUrl, |
|
|
94 |
'parameters' => $configurator->render(), |
|
|
95 |
'ini_path' => $this->container->getParameter('kernel.root_dir').'/config/parameters.ini', |
|
|
96 |
'is_writable' => $configurator->isFileWritable(), |
|
|
97 |
'version' => $this->getVersion(), |
|
|
98 |
)); |
|
|
99 |
} |
|
|
100 |
|
|
|
101 |
public function getVersion() |
|
|
102 |
{ |
|
|
103 |
$kernel = $this->container->get('kernel'); |
|
|
104 |
|
|
|
105 |
return $kernel::VERSION; |
|
|
106 |
} |
|
|
107 |
} |