SecretStep.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Step;
  11. use Symfony\Bundle\WebConfiguratorBundle\Exception\StepRequirementException;
  12. use Symfony\Bundle\WebConfiguratorBundle\Form\SecretStepType;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15. * Secret Step.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class SecretStep implements StepInterface
  20. {
  21. /**
  22. * @Assert\NotBlank
  23. */
  24. public $secret;
  25. public function __construct(array $parameters)
  26. {
  27. $this->secret = $parameters['secret'];
  28. if ('ThisTokenIsNotSoSecretChangeIt' == $this->secret) {
  29. $this->secret = hash('sha1', uniqid(mt_rand()));
  30. }
  31. }
  32. /**
  33. * @see StepInterface
  34. */
  35. public function getFormType()
  36. {
  37. return new SecretStepType();
  38. }
  39. /**
  40. * @see StepInterface
  41. */
  42. public function checkRequirements()
  43. {
  44. return array();
  45. }
  46. /**
  47. * checkOptionalSettings
  48. */
  49. public function checkOptionalSettings()
  50. {
  51. return array();
  52. }
  53. /**
  54. * @see StepInterface
  55. */
  56. public function update(StepInterface $data)
  57. {
  58. return array('secret' => $data->secret);
  59. }
  60. /**
  61. * @see StepInterface
  62. */
  63. public function getTemplate()
  64. {
  65. return 'SymfonyWebConfiguratorBundle:Step:secret.html.twig';
  66. }
  67. }