123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Bundle\WebConfiguratorBundle\Controller;
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Symfony\Bundle\WebConfiguratorBundle\Exception\StepRequirementException;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- /**
- * ConfiguratorController.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
- class ConfiguratorController extends ContainerAware
- {
- /**
- * @return Response A Response instance
- */
- public function stepAction($index = 0)
- {
- $configurator = $this->container->get('symfony.webconfigurator');
- $step = $configurator->getStep($index);
- $form = $this->container->get('form.factory')->create($step->getFormType(), $step);
- $request = $this->container->get('request');
- if ('POST' === $request->getMethod()) {
- $form->bindRequest($request);
- if ($form->isValid()) {
- $configurator->mergeParameters($step->update($form->getData()));
- $configurator->write();
- $index++;
- if ($index < $configurator->getStepCount()) {
- return new RedirectResponse($this->container->get('router')->generate('_configurator_step', array('index' => $index)));
- }
- return new RedirectResponse($this->container->get('router')->generate('_configurator_final'));
- }
- }
- return $this->container->get('templating')->renderResponse($step->getTemplate(), array(
- 'form' => $form->createView(),
- 'index' => $index,
- 'count' => $configurator->getStepCount(),
- 'version' => $this->getVersion(),
- ));
- }
- public function checkAction()
- {
- $configurator = $this->container->get('symfony.webconfigurator');
- $steps = $configurator->getSteps();
- $majors = array();
- $minors = array();
- // Trying to get as much requirements as possible
- foreach ($steps as $step) {
- foreach ($step->checkRequirements() as $major) {
- $majors[] = $major;
- }
- foreach ($step->checkOptionalSettings() as $minor) {
- $minors[] = $minor;
- }
- }
- $url = $this->container->get('router')->generate('_configurator_step', array('index' => 0));
- if (empty($majors) && empty($minors)) {
- return new RedirectResponse($url);
- }
- return $this->container->get('templating')->renderResponse('SymfonyWebConfiguratorBundle::check.html.twig', array(
- 'majors' => $majors,
- 'minors' => $minors,
- 'url' => $url,
- 'version' => $this->getVersion(),
- ));
- }
- public function finalAction()
- {
- $configurator = $this->container->get('symfony.webconfigurator');
- $configurator->clean();
- return $this->container->get('templating')->renderResponse('SymfonyWebConfiguratorBundle::final.html.twig', array(
- 'parameters' => $configurator->render(),
- 'ini_path' => $this->container->getParameter('kernel.root_dir').'/config/parameters.ini',
- 'is_writable' => $configurator->isFileWritable(),
- 'version' => $this->getVersion(),
- ));
- }
-
- public function getVersion()
- {
- $kernel = $this->container->get('kernel');
- return $kernel::VERSION;
- }
- }
|