Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony5 compatible #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 0 additions & 40 deletions src/DependencyInjection/Compiler/ReplaceSessionDefinitionPass.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 9 additions & 11 deletions src/EventListener/ConversationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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');
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
1 change: 0 additions & 1 deletion src/PHPMentorsPageflowerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
9 changes: 2 additions & 7 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<parameter key="phpmentors_pageflower.conversation_repository.class">PHPMentors\PageflowerBundle\Conversation\ConversationRepository</parameter>
<parameter key="phpmentors_pageflower.conversational_app_variable.class">PHPMentors\PageflowerBundle\Templating\ConversationalAppVariable</parameter>
<parameter key="phpmentors_pageflower.conversational_global_variables.class">PHPMentors\PageflowerBundle\Templating\ConversationalGlobalVariables</parameter>
<parameter key="phpmentors_pageflower.conversational_session.class">PHPMentors\PageflowerBundle\Session\ConversationalSession</parameter>
<parameter key="phpmentors_pageflower.endable_conversation_specification.class">PHPMentors\PageflowerBundle\Conversation\EndableConversationSpecification</parameter>
<parameter key="phpmentors_pageflower.form_type_conversation_extension.class">PHPMentors\PageflowerBundle\Form\Extension\Conversation\Type\FormTypeConversationExtension</parameter>
<parameter key="phpmentors_pageflower.pageflow.class">PHPMentors\PageflowerBundle\Pageflow\Pageflow</parameter>
Expand All @@ -33,7 +32,6 @@
<argument type="service" id="phpmentors_pageflower.conversation_repository"/>
<argument type="service" id="phpmentors_pageflower.pageflow_repository"/>
<argument type="service" id="phpmentors_pageflower.reflection_conversational_controller_repository"/>
<argument type="service" id="security.secure_random" on-invalid="ignore"/>
<argument type="service" id="phpmentors_pageflower.endable_conversation_specification"/>
<call method="setConversationContext">
<argument type="service" id="phpmentors_pageflower.conversation_context"/>
Expand All @@ -42,11 +40,8 @@
<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse"/>
</service>
<service id="phpmentors_pageflower.conversation_repository" class="%phpmentors_pageflower.conversation_repository.class%" public="false"/>
<service id="phpmentors_pageflower.conversational_session" class="%phpmentors_pageflower.conversational_session.class%">
<argument type="service" id="session.storage"/>
<argument type="service" id="session.attribute_bag"/>
<argument type="service" id="session.flash_bag"/>
<argument type="service" id="phpmentors_pageflower.conversation_bag"/>
<service id="PHPMentors\PageflowerBundle\Session\SessionFactoryConversationBag" decorates="session.factory">
<argument type="service" id=".inner"/>
</service>
<service id="phpmentors_pageflower.conversational_app_variable" class="%phpmentors_pageflower.conversational_app_variable.class%" public="false">
<argument type="service" id="phpmentors_pageflower.conversation_context"/>
Expand Down
3 changes: 2 additions & 1 deletion src/Session/ConversationBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 0 additions & 45 deletions src/Session/ConversationalSession.php

This file was deleted.

32 changes: 32 additions & 0 deletions src/Session/SessionFactoryConversationBag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace PHPMentors\PageflowerBundle\Session;

use Symfony\Component\HttpFoundation\Session\SessionFactoryInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class SessionFactoryConversationBag implements SessionFactoryInterface
{
/**
* @var SessionFactoryInterface
*/
private $delegate;

/**
* @param SessionFactoryInterface $delegate
*/
public function __construct(SessionFactoryInterface $delegate)
{
$this->delegate = $delegate;
}

/**
* {@inheritDoc}
*/
public function createSession(): SessionInterface
{
$session = $this->delegate->createSession();
$session->registerBag(new ConversationBag('_pageflower_conversations'));
return $session;
}
}