diff --git a/composer.json b/composer.json index de7645f..3246bdb 100644 --- a/composer.json +++ b/composer.json @@ -11,29 +11,28 @@ } ], "require": { - "php": ">=5.3.9", + "php": ">=7.0", "doctrine/annotations": "~1.0", "phpmentors/domain-kata": "~1.0", - "piece/stagehand-fsm": "~2.6", - "symfony/config": "~2.8|~3.0|~4.0", - "symfony/console": "~2.8|~3.0|~4.0", - "symfony/dependency-injection": "~2.8|~3.0|~4.0", - "symfony/form": "~2.8|~3.0|~4.0", - "symfony/framework-bundle": "~2.8|~3.0|~4.0", - "symfony/http-foundation": "~2.8|~3.0|~4.0", - "symfony/http-kernel": "~2.8|~3.0|~4.0", - "symfony/routing": "~2.8|~3.0|~4.0", - "symfony/security": "~2.8|~3.0|~4.0", - "symfony/validator": "~2.8|~3.0|~4.0" + "phpmentors/stagehand-fsm": "dev-symfony5", + "symfony/config": "~4.0|~5.0", + "symfony/console": "~4.0|~5.0", + "symfony/dependency-injection": "~4.0|~5.0", + "symfony/form": "~4.0|~5.0", + "symfony/framework-bundle": "~4.0|~5.0", + "symfony/http-foundation": "~4.0|~5.0", + "symfony/http-kernel": "~4.0|~5.0", + "symfony/routing": "~4.0|~5.0", + "symfony/validator": "~4.0|~5.0" }, "require-dev": { "phpunit/phpunit": "~4.0", - "symfony/browser-kit": "~2.8|~3.0|~4.0", - "symfony/css-selector": "~2.8|~3.0|~4.0", - "symfony/filesystem": "~2.8|~3.0|~4.0", - "symfony/templating": "~2.8|~3.0|~4.0", - "symfony/twig-bridge": "~2.8|~3.0|~4.0", - "symfony/twig-bundle": "~2.8|~3.0|~4.0" + "symfony/browser-kit": "~4.0|~5.0", + "symfony/css-selector": "~4.0|~5.0", + "symfony/filesystem": "~4.0|~5.0", + "symfony/templating": "~4.0|~5.0", + "symfony/twig-bridge": "~4.0|~5.0", + "symfony/twig-bundle": "~4.0|~5.0" }, "suggest": { "symfony/twig-bridge": ">=2.8.0 provides the `ConversationContext` object as `app.conversation` in Twig templates", diff --git a/src/DependencyInjection/Compiler/ReplaceSessionDefinitionPass.php b/src/DependencyInjection/Compiler/ReplaceSessionDefinitionPass.php deleted file mode 100644 index bb1203b..0000000 --- a/src/DependencyInjection/Compiler/ReplaceSessionDefinitionPass.php +++ /dev/null @@ -1,40 +0,0 @@ -, - * All rights reserved. - * - * This file is part of PHPMentorsPageflowerBundle. - * - * This program and the accompanying materials are made available under - * the terms of the BSD 2-Clause License which accompanies this - * distribution, and is available at http://opensource.org/licenses/BSD-2-Clause - */ - -namespace PHPMentors\PageflowerBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; - -class ReplaceSessionDefinitionPass implements CompilerPassInterface -{ - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) - { - $conversationalSessionDefinition = $container->getDefinition('phpmentors_pageflower.conversational_session'); - $sessionDefinition = $container->getDefinition('session'); - - /* - * As of version 3.4.39, the 'session.attribute_bag' and 'session.flash_bag' arguments have been removed from the 'session' definition. - * See https://github.com/symfony/symfony/pull/36063 for more details. - */ - if (count($sessionDefinition->getArguments()) == 1) { - $conversationalSessionDefinition->replaceArgument(1, null); - $conversationalSessionDefinition->replaceArgument(2, null); - } - - $container->setDefinition('session', $conversationalSessionDefinition); - $container->removeDefinition('phpmentors_pageflower.conversational_session'); - } -} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7188ee0..42ca1f7 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -22,8 +22,8 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $treeBuilder->root('phpmentors_pageflower') + $treeBuilder = new TreeBuilder('phpmentors_pageflower'); + $treeBuilder->getRootNode() ->children() ->arrayNode('conversation') ->addDefaultsIfNotSet() diff --git a/src/EventListener/ConversationListener.php b/src/EventListener/ConversationListener.php index e941344..fe48a12 100644 --- a/src/EventListener/ConversationListener.php +++ b/src/EventListener/ConversationListener.php @@ -20,8 +20,8 @@ use PHPMentors\PageflowerBundle\Conversation\EndableConversationSpecification; use PHPMentors\PageflowerBundle\Pageflow\Pageflow; use PHPMentors\PageflowerBundle\Pageflow\PageflowRepository; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Util\SecureRandomInterface; @@ -64,15 +64,13 @@ class ConversationListener implements ConversationContextAwareInterface * @param ConversationRepository $conversationRepository * @param PageflowRepository $pageflowRepository * @param ReflectionConversationalControllerRepository $reflectionConversationalControllerRepository - * @param SecureRandomInterface $secureRandom * @param EndableConversationSpecification $endableConversationSpecification */ - public function __construct(ConversationRepository $conversationRepository, PageflowRepository $pageflowRepository, ReflectionConversationalControllerRepository $reflectionConversationalControllerRepository, SecureRandomInterface $secureRandom = null, EndableConversationSpecification $endableConversationSpecification) + public function __construct(ConversationRepository $conversationRepository, PageflowRepository $pageflowRepository, ReflectionConversationalControllerRepository $reflectionConversationalControllerRepository, EndableConversationSpecification $endableConversationSpecification) { $this->conversationRepository = $conversationRepository; $this->pageflowRepository = $pageflowRepository; $this->reflectionConversationalControllerRepository = $reflectionConversationalControllerRepository; - $this->secureRandom = $secureRandom; $this->endableConversationSpecification = $endableConversationSpecification; } @@ -85,11 +83,11 @@ public function setConversationContext(ConversationContext $conversationContext) } /** - * @param FilterControllerEvent $event + * @param ControllerEvent $event * * @throws \UnexpectedValueException */ - public function onKernelController(FilterControllerEvent $event) + public function onKernelController(ControllerEvent $event) { if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { $controllerName = $event->getRequest()->attributes->get('_controller'); @@ -98,7 +96,7 @@ public function onKernelController(FilterControllerEvent $event) if ($pageflow !== null) { list($conversationalController, $action) = $event->getController(); - $this->conversationRepository->setConversationCollection($event->getRequest()->getSession()->getConversationBag()); + $this->conversationRepository->setConversationCollection($event->getRequest()->getSession()->getBag('conversations')); if ($event->getRequest()->request->has($this->conversationContext->getConversationParameterName())) { $conversationId = $event->getRequest()->request->get($this->conversationContext->getConversationParameterName()); @@ -184,9 +182,9 @@ public function onKernelController(FilterControllerEvent $event) } /** - * @param FilterResponseEvent $event + * @param ResponseEvent $event */ - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(ResponseEvent $event) { if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { $conversation = $this->conversationContext->getConversation(); @@ -254,6 +252,6 @@ private function createPageflow(Pageflow $pageflow) */ private function generateConversationId() { - return sha1($this->secureRandom === null ? random_bytes(24) : $this->secureRandom->nextBytes(24)); + return sha1(random_bytes(24)); } } diff --git a/src/Form/Extension/Conversation/Type/FormTypeConversationExtension.php b/src/Form/Extension/Conversation/Type/FormTypeConversationExtension.php index 99c8426..927bca6 100644 --- a/src/Form/Extension/Conversation/Type/FormTypeConversationExtension.php +++ b/src/Form/Extension/Conversation/Type/FormTypeConversationExtension.php @@ -68,10 +68,8 @@ public function finishView(FormView $view, FormInterface $conversationForm, arra /** * {@inheritdoc} */ - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return 'Symfony\Component\Form\Extension\Core\Type\FormType'; - - return 'form'; + return ['Symfony\Component\Form\Extension\Core\Type\FormType']; } } diff --git a/src/PHPMentorsPageflowerBundle.php b/src/PHPMentorsPageflowerBundle.php index 20fcf74..de90214 100644 --- a/src/PHPMentorsPageflowerBundle.php +++ b/src/PHPMentorsPageflowerBundle.php @@ -28,7 +28,6 @@ class PHPMentorsPageflowerBundle extends Bundle public function build(ContainerBuilder $container) { $container->addCompilerPass(new GeneratePageflowDefinitionsPass()); - $container->addCompilerPass(new ReplaceSessionDefinitionPass()); $container->addCompilerPass(new ReplaceTemplatingGlobalsDefinitionPass()); $container->addCompilerPass(new ReplaceAppVariableDefinitionPass()); } diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index c985563..dc9a7e2 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -8,7 +8,6 @@ PHPMentors\PageflowerBundle\Conversation\ConversationRepository PHPMentors\PageflowerBundle\Templating\ConversationalAppVariable PHPMentors\PageflowerBundle\Templating\ConversationalGlobalVariables - PHPMentors\PageflowerBundle\Session\ConversationalSession PHPMentors\PageflowerBundle\Conversation\EndableConversationSpecification PHPMentors\PageflowerBundle\Form\Extension\Conversation\Type\FormTypeConversationExtension PHPMentors\PageflowerBundle\Pageflow\Pageflow @@ -33,7 +32,6 @@ - @@ -42,11 +40,8 @@ - - - - - + + diff --git a/src/Session/ConversationBag.php b/src/Session/ConversationBag.php index 8b2f876..3f1d2af 100644 --- a/src/Session/ConversationBag.php +++ b/src/Session/ConversationBag.php @@ -14,9 +14,10 @@ use PHPMentors\PageflowerBundle\Conversation\Conversation; use PHPMentors\PageflowerBundle\Conversation\ConversationCollectionInterface; +use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; use Symfony\Component\HttpFoundation\Session\SessionBagInterface; -class ConversationBag implements ConversationCollectionInterface, SessionBagInterface +class ConversationBag extends AttributeBag implements ConversationCollectionInterface { /** * @var array diff --git a/src/Session/ConversationalSession.php b/src/Session/ConversationalSession.php deleted file mode 100644 index 8bc7e9d..0000000 --- a/src/Session/ConversationalSession.php +++ /dev/null @@ -1,45 +0,0 @@ -, - * All rights reserved. - * - * This file is part of PHPMentorsPageflowerBundle. - * - * This program and the accompanying materials are made available under - * the terms of the BSD 2-Clause License which accompanies this - * distribution, and is available at http://opensource.org/licenses/BSD-2-Clause - */ - -namespace PHPMentors\PageflowerBundle\Session; - -use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; -use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; - -class ConversationalSession extends Session -{ - /** - * @var string - */ - private $conversationName; - - /** - * {@inheritdoc} - */ - public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null, ConversationBag $conversations = null) - { - parent::__construct($storage, $attributes, $flashes); - - $this->conversationName = $conversations->getName(); - $this->registerBag($conversations); - } - - /** - * @return ConversationBag - */ - public function getConversationBag() - { - return $this->getBag($this->conversationName); - } -} diff --git a/src/Session/SessionFactoryConversationBag.php b/src/Session/SessionFactoryConversationBag.php new file mode 100644 index 0000000..e9c6fca --- /dev/null +++ b/src/Session/SessionFactoryConversationBag.php @@ -0,0 +1,32 @@ +delegate = $delegate; + } + + /** + * {@inheritDoc} + */ + public function createSession(): SessionInterface + { + $session = $this->delegate->createSession(); + $session->registerBag(new ConversationBag('_pageflower_conversations')); + return $session; + } +}