ConfiguratorController.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Sensio\Bundle\DistributionBundle\Controller;
  11. use Symfony\Component\DependencyInjection\ContainerAware;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. /**
  14. * ConfiguratorController.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class ConfiguratorController extends ContainerAware
  19. {
  20. /**
  21. * @return Response A Response instance
  22. */
  23. public function stepAction($index = 0)
  24. {
  25. $configurator = $this->container->get('sensio.distribution.webconfigurator');
  26. $step = $configurator->getStep($index);
  27. $form = $this->container->get('form.factory')->create($step->getFormType(), $step);
  28. $request = $this->container->get('request');
  29. if ('POST' === $request->getMethod()) {
  30. $form->bindRequest($request);
  31. if ($form->isValid()) {
  32. $configurator->mergeParameters($step->update($form->getData()));
  33. $configurator->write();
  34. $index++;
  35. if ($index < $configurator->getStepCount()) {
  36. return new RedirectResponse($this->container->get('router')->generate('_configurator_step', array('index' => $index)));
  37. }
  38. return new RedirectResponse($this->container->get('router')->generate('_configurator_final'));
  39. }
  40. }
  41. return $this->container->get('templating')->renderResponse($step->getTemplate(), array(
  42. 'form' => $form->createView(),
  43. 'index' => $index,
  44. 'count' => $configurator->getStepCount(),
  45. 'version' => $this->getVersion(),
  46. ));
  47. }
  48. public function checkAction()
  49. {
  50. $configurator = $this->container->get('sensio.distribution.webconfigurator');
  51. // Trying to get as much requirements as possible
  52. $majors = $configurator->getRequirements();
  53. $minors = $configurator->getOptionalSettings();
  54. $url = $this->container->get('router')->generate('_configurator_step', array('index' => 0));
  55. if (empty($majors) && empty($minors)) {
  56. return new RedirectResponse($url);
  57. }
  58. return $this->container->get('templating')->renderResponse('SensioDistributionBundle::Configurator/check.html.twig', array(
  59. 'majors' => $majors,
  60. 'minors' => $minors,
  61. 'url' => $url,
  62. 'version' => $this->getVersion(),
  63. ));
  64. }
  65. public function finalAction()
  66. {
  67. $configurator = $this->container->get('sensio.distribution.webconfigurator');
  68. $configurator->clean();
  69. try {
  70. $welcomeUrl = $this->container->get('router')->generate('_welcome');
  71. } catch (\Exception $e) {
  72. $welcomeUrl = null;
  73. }
  74. return $this->container->get('templating')->renderResponse('SensioDistributionBundle::Configurator/final.html.twig', array(
  75. 'welcome_url' => $welcomeUrl,
  76. 'parameters' => $configurator->render(),
  77. 'ini_path' => $this->container->getParameter('kernel.root_dir').'/config/parameters.ini',
  78. 'is_writable' => $configurator->isFileWritable(),
  79. 'version' => $this->getVersion(),
  80. ));
  81. }
  82. public function getVersion()
  83. {
  84. $kernel = $this->container->get('kernel');
  85. return $kernel::VERSION;
  86. }
  87. }