ConfiguratorController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 = $step->getForm($this->container->get('form.context'));
  29. $form->bind($this->container->get('request'), $step);
  30. if ($form->isValid()) {
  31. $configurator->mergeParameters($step->update($form->getData()));
  32. $configurator->write();
  33. $index++;
  34. if ($index < $configurator->getStepCount()) {
  35. return new RedirectResponse($this->container->get('router')->generate('_configurator_step', array('index' => $index)));
  36. }
  37. return new RedirectResponse($this->container->get('router')->generate('_configurator_final'));
  38. }
  39. return $this->container->get('templating')->renderResponse($step->getTemplate(),
  40. array('form' => $form, 'index' => $index, 'count' => $configurator->getStepCount()));
  41. }
  42. public function checkAction()
  43. {
  44. $configurator = $this->container->get('symfony.webconfigurator');
  45. $steps = $configurator->getSteps();
  46. $majors = array();
  47. $minors = array();
  48. // Trying to get as much requirements as possible
  49. foreach ($steps as $step) {
  50. foreach ($step->checkRequirements() as $major) {
  51. $majors[] = $major;
  52. }
  53. foreach ($step->checkOptionalSettings() as $minor) {
  54. $minors[] = $minor;
  55. }
  56. }
  57. $url = $this->container->get('router')->generate('_configurator_step', array('index' => 0));
  58. if (empty($majors) && empty($minors)) {
  59. return new RedirectResponse($url);
  60. }
  61. return $this->container->get('templating')->renderResponse('SymfonyWebConfiguratorBundle::check.html.twig',
  62. array(
  63. 'majors' => $majors,
  64. 'minors' => $minors,
  65. 'url' => $url,
  66. )
  67. );
  68. }
  69. public function finalAction()
  70. {
  71. $configurator = $this->container->get('symfony.webconfigurator');
  72. $configurator->clean();
  73. return $this->container->get('templating')->renderResponse('SymfonyWebConfiguratorBundle::final.html.twig',
  74. array(
  75. 'parameters' => $configurator->render(),
  76. 'is_writable' => $configurator->isFileWritable(),
  77. )
  78. );
  79. }
  80. }