vendor/craue/formflow-bundle/EventListener/FlowExpiredEventListener.php line 20

Open in your IDE?
  1. <?php
  2. namespace Craue\FormFlowBundle\EventListener;
  3. use Craue\FormFlowBundle\Event\FlowExpiredEvent;
  4. use Symfony\Component\Form\FormError;
  5. use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. /**
  8.  * @internal
  9.  */
  10. abstract class BaseFlowExpiredEventListener {
  11.     /**
  12.      * @var TranslatorInterface|LegacyTranslatorInterface
  13.      */
  14.     protected $translator;
  15.     public function onFlowExpired(FlowExpiredEvent $event) {
  16.         $event->getCurrentStepForm()->addError($this->getFlowExpiredFormError());
  17.     }
  18.     /**
  19.      * @return FormError
  20.      */
  21.     protected function getFlowExpiredFormError() {
  22.         $messageId 'craueFormFlow.flowExpired';
  23.         $messageParameters = [];
  24.         return new FormError($this->translator->trans($messageId$messageParameters'validators'), $messageId$messageParameters);
  25.     }
  26. }
  27. // TODO revert to one clean class definition as soon as Symfony >= 4.2 is required
  28. if (!interface_exists(LegacyTranslatorInterface::class)) {
  29.     /**
  30.      * Adds a validation error to the current step's form if an expired flow is detected.
  31.      *
  32.      * @author Tim Behrendsen <tim@siliconengine.com>
  33.      * @copyright 2011-2020 Christian Raue
  34.      * @license http://opensource.org/licenses/mit-license.php MIT License
  35.      */
  36.     class FlowExpiredEventListener extends BaseFlowExpiredEventListener {
  37.         public function setTranslator(TranslatorInterface $translator) {
  38.             $this->translator $translator;
  39.         }
  40.     }
  41. } else {
  42.     /**
  43.      * Adds a validation error to the current step's form if an expired flow is detected.
  44.      *
  45.      * @author Tim Behrendsen <tim@siliconengine.com>
  46.      * @copyright 2011-2020 Christian Raue
  47.      * @license http://opensource.org/licenses/mit-license.php MIT License
  48.      */
  49.     class FlowExpiredEventListener extends BaseFlowExpiredEventListener {
  50.         public function setTranslator(LegacyTranslatorInterface $translator) {
  51.             $this->translator $translator;
  52.         }
  53.     }
  54. }