ConfiguratorController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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(), array(
  40. 'form' => $form,
  41. 'index' => $index,
  42. 'count' => $configurator->getStepCount(),
  43. 'version' => file_get_contents($this->container->getParameter('kernel.root_dir').'/../VERSION'),
  44. ));
  45. }
  46. public function checkAction()
  47. {
  48. $configurator = $this->container->get('symfony.webconfigurator');
  49. $steps = $configurator->getSteps();
  50. $majors = array();
  51. $minors = array();
  52. // Trying to get as much requirements as possible
  53. foreach ($steps as $step) {
  54. foreach ($step->checkRequirements() as $major) {
  55. $majors[] = $major;
  56. }
  57. foreach ($step->checkOptionalSettings() as $minor) {
  58. $minors[] = $minor;
  59. }
  60. }
  61. $url = $this->container->get('router')->generate('_configurator_step', array('index' => 0));
  62. if (empty($majors) && empty($minors)) {
  63. return new RedirectResponse($url);
  64. }
  65. return $this->container->get('templating')->renderResponse('SymfonyWebConfigurator::check.html.twig', array(
  66. 'majors' => $majors,
  67. 'minors' => $minors,
  68. 'url' => $url,
  69. 'version' => file_get_contents($this->container->getParameter('kernel.root_dir').'/../VERSION'),
  70. ));
  71. }
  72. public function finalAction()
  73. {
  74. $configurator = $this->container->get('symfony.webconfigurator');
  75. $configurator->clean();
  76. return $this->container->get('templating')->renderResponse('SymfonyWebConfigurator::final.html.twig', array(
  77. 'parameters' => $configurator->render(),
  78. 'ini_path' => $this->container->getParameter('kernel.root_dir').'/config/parameters.ini',
  79. 'is_writable' => $configurator->isFileWritable(),
  80. 'version' => file_get_contents($this->container->getParameter('kernel.root_dir').'/../VERSION'),
  81. ));
  82. }
  83. }