ConfiguratorController.php 3.6 KB

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