diff --git a/.gitignore b/.gitignore index 8026716a..f0006536 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /vendor/ composer.lock ezpublish_legacy +var bin config.php .php_cs.cache diff --git a/.php_cs b/.php_cs index 32371235..13ae857b 100644 --- a/.php_cs +++ b/.php_cs @@ -19,6 +19,7 @@ return PhpCsFixer\Config::create() ->in(__DIR__) ->exclude([ 'vendor', + 'ezpublish_legacy', ]) ->files()->name('*.php') ) diff --git a/bundle/Controller/LegacyRestController.php b/bundle/Controller/LegacyRestController.php index 159488ff..3f59a8aa 100644 --- a/bundle/Controller/LegacyRestController.php +++ b/bundle/Controller/LegacyRestController.php @@ -36,7 +36,7 @@ public function restAction() $result = ezpKernelRest::getResponse(); if ($result === null) { - throw new Exception('Rest Kernel run failed'); + throw new \Exception('Rest Kernel run failed'); } return new Response( diff --git a/bundle/Controller/LegacySetupController.php b/bundle/Controller/LegacySetupController.php index b9b4b73c..28717b6d 100644 --- a/bundle/Controller/LegacySetupController.php +++ b/bundle/Controller/LegacySetupController.php @@ -10,7 +10,8 @@ namespace eZ\Bundle\EzPublishLegacyBundle\Controller; use eZ\Publish\Core\MVC\Legacy\Kernel\Loader; -use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\HttpFoundation\Response; use eZ\Publish\Core\MVC\Symfony\ConfigDumperInterface; use eZ\Bundle\EzPublishLegacyBundle\DependencyInjection\Configuration\LegacyConfigResolver; @@ -18,8 +19,10 @@ use eZINI; use eZCache; -class LegacySetupController extends ContainerAware +class LegacySetupController implements ContainerAwareInterface { + use ContainerAwareTrait; + /** * The legacy kernel instance (eZ Publish 4). * @@ -87,7 +90,7 @@ public function init() $this->kernelFactory->setBuildEventsEnabled(false); /** @var $request \Symfony\Component\HttpFoundation\ParameterBag */ - $request = $this->container->get('request')->request; + $request = $this->container->get('request_stack')->getCurrentRequest()->request; // inject the extra ezpublish-community folders we want permissions checked for switch ($request->get('eZSetup_current_step')) { diff --git a/bundle/Controller/WebsiteToolbarController.php b/bundle/Controller/WebsiteToolbarController.php index 289a3b7e..2c12a076 100644 --- a/bundle/Controller/WebsiteToolbarController.php +++ b/bundle/Controller/WebsiteToolbarController.php @@ -14,7 +14,7 @@ use eZ\Publish\Core\Helper\ContentPreviewHelper; use eZ\Publish\Core\MVC\Symfony\Controller\Controller; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; +use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Templating\EngineInterface; @@ -22,8 +22,8 @@ class WebsiteToolbarController extends Controller { - /** @var \Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface */ - private $csrfProvider; + /** @var \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface */ + private $csrfTokenManager; /** @var \Symfony\Component\Templating\EngineInterface */ private $legacyTemplateEngine; @@ -46,13 +46,13 @@ public function __construct( LocationService $locationService, AuthorizationCheckerInterface $authChecker, ContentPreviewHelper $previewHelper, - CsrfProviderInterface $csrfProvider = null + CsrfTokenManagerInterface $csrfTokenManager = null ) { $this->legacyTemplateEngine = $engine; $this->contentService = $contentService; $this->locationService = $locationService; $this->authChecker = $authChecker; - $this->csrfProvider = $csrfProvider; + $this->csrfTokenManager = $csrfTokenManager; $this->previewHelper = $previewHelper; } @@ -70,8 +70,8 @@ public function websiteToolbarAction($locationId, Request $request) { $response = new Response(); - if (isset($this->csrfProvider)) { - $parameters['form_token'] = $this->csrfProvider->generateCsrfToken('legacy'); + if (isset($this->csrfTokenManager)) { + $parameters['form_token'] = $this->csrfTokenManager->getToken('legacy')->getValue(); } if ($this->previewHelper->isPreviewActive()) { diff --git a/bundle/DependencyInjection/Compiler/RememberMeListenerPass.php b/bundle/DependencyInjection/Compiler/RememberMeListenerPass.php index 3ac49a63..c44b9d1b 100644 --- a/bundle/DependencyInjection/Compiler/RememberMeListenerPass.php +++ b/bundle/DependencyInjection/Compiler/RememberMeListenerPass.php @@ -21,7 +21,8 @@ public function process(ContainerBuilder $container) return; } - $listenerDef = $container->findDefinition('security.authentication.listener.rememberme'); - $listenerDef->addMethodCall('setConfigResolver', array(new Reference('ezpublish.config.resolver'))); + $container->findDefinition('security.authentication.listener.rememberme') + ->setClass('eZ\Bundle\EzPublishLegacyBundle\Security\RememberMeListener') + ->addMethodCall('setConfigResolver', array(new Reference('ezpublish.config.resolver'))); } } diff --git a/bundle/DependencyInjection/Compiler/RoutingPass.php b/bundle/DependencyInjection/Compiler/RoutingPass.php index c8373742..35ef6235 100644 --- a/bundle/DependencyInjection/Compiler/RoutingPass.php +++ b/bundle/DependencyInjection/Compiler/RoutingPass.php @@ -29,5 +29,10 @@ public function process(ContainerBuilder $container) 'setLegacyAwareRoutes', ['%ezpublish.default_router.legacy_aware_routes%'] ); + + if ($container->hasDefinition('ezpublish_rest.templated_router')) { + $container->getDefinition('ezpublish_rest.templated_router') + ->setClass('eZ\Bundle\EzPublishLegacyBundle\Routing\DefaultRouter'); + } } } diff --git a/bundle/DependencyInjection/Compiler/TwigPass.php b/bundle/DependencyInjection/Compiler/TwigPass.php index 671e1b06..8c7b198a 100644 --- a/bundle/DependencyInjection/Compiler/TwigPass.php +++ b/bundle/DependencyInjection/Compiler/TwigPass.php @@ -26,7 +26,8 @@ public function process(ContainerBuilder $container) // Adding setLegacyEngine method call here to avoid side effect in redefining the twig service completely. // Mentioned side effects are losing extensions/loaders addition for which method calls are added in the TwigEnvironmentPass - $def = $container->getDefinition('twig'); - $def->addMethodCall('setEzLegacyEngine', array(new Reference('templating.engine.eztpl'))); + $container->getDefinition('twig') + ->setClass('eZ\Publish\Core\MVC\Legacy\Templating\Twig\Environment') + ->addMethodCall('setEzLegacyEngine', array(new Reference('templating.engine.eztpl'))); } } diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index 49f4af0f..52227e0e 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -7,7 +7,6 @@ parameters: # Core overrides ezpublish.security.login_listener.class: eZ\Bundle\EzPublishLegacyBundle\Security\SecurityListener - security.authentication.listener.rememberme.class: eZ\Bundle\EzPublishLegacyBundle\Security\RememberMeListener ezpublish_legacy.kernel.lazy_loader.class: eZ\Publish\Core\MVC\Legacy\Kernel\Loader ezpublish_legacy.kernel_handler.class: ezpKernelHandler @@ -95,6 +94,7 @@ services: - "@?logger" calls: - [setContainer, ["@service_container"]] + - [setRequestStack, ["@request_stack"]] ezpublish_legacy.rest.kernel_handler: class: "%ezpublish_legacy.kernel_handler.rest.class%" @@ -173,7 +173,7 @@ services: - "@ezpublish.api.service.location" - "@security.authorization_checker" - "@ezpublish.content_preview_helper" - - "@?form.csrf_provider" + - "@?security.csrf.token_manager" ezpublish_legacy.router: class: "%ezpublish_legacy.router.class%" diff --git a/bundle/Resources/config/templating.yml b/bundle/Resources/config/templating.yml index 8dcf4c59..e9e9794f 100644 --- a/bundle/Resources/config/templating.yml +++ b/bundle/Resources/config/templating.yml @@ -12,7 +12,6 @@ parameters: # eZ Template as a real template engine templating.engine.eztpl.class: eZ\Publish\Core\MVC\Legacy\Templating\LegacyEngine assetic.eztpl_formula_loader.class: eZ\Publish\Core\MVC\Legacy\Templating\LegacyFormulaLoader - twig.class: eZ\Publish\Core\MVC\Legacy\Templating\Twig\Environment twig.loader.string.class: eZ\Publish\Core\MVC\Legacy\Templating\Twig\LoaderString services: diff --git a/bundle/Routing/FallbackRouter.php b/bundle/Routing/FallbackRouter.php index 4b1abe38..bd54a88e 100644 --- a/bundle/Routing/FallbackRouter.php +++ b/bundle/Routing/FallbackRouter.php @@ -94,7 +94,7 @@ public function getRouteCollection() * * @param string $name The name of the route * @param mixed $parameters An array of parameters - * @param bool $absolute Whether to generate an absolute URL + * @param int $referenceType The type of reference to be generated (one of the constants) * * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException * @throws \InvalidArgumentException @@ -103,7 +103,7 @@ public function getRouteCollection() * * @api */ - public function generate($name, $parameters = array(), $absolute = false) + public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { if ($name === self::ROUTE_NAME) { if (!isset($parameters['module_uri'])) { @@ -113,7 +113,7 @@ public function generate($name, $parameters = array(), $absolute = false) $moduleUri = $parameters['module_uri']; unset($parameters['module_uri']); - return $this->urlGenerator->generate($moduleUri, $parameters, $absolute); + return $this->urlGenerator->generate($moduleUri, $parameters, $referenceType); } throw new RouteNotFoundException(); diff --git a/mvc/Kernel/Loader.php b/mvc/Kernel/Loader.php index 5848f9e9..d0842eef 100644 --- a/mvc/Kernel/Loader.php +++ b/mvc/Kernel/Loader.php @@ -21,6 +21,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\RequestStack; /** * Legacy kernel loader. @@ -68,6 +69,11 @@ class Loader /** @var ezpKernelHandler */ private $restHandler; + /** + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + private $requestStack; + public function __construct($legacyRootDir, $webrootDir, EventDispatcherInterface $eventDispatcher, URIHelper $uriHelper, LoggerInterface $logger = null) { $this->legacyRootDir = $legacyRootDir; @@ -77,6 +83,14 @@ public function __construct($legacyRootDir, $webrootDir, EventDispatcherInterfac $this->logger = $logger; } + /** + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + */ + public function setRequestStack(RequestStack $requestStack) + { + $this->requestStack = $requestStack; + } + /** * @param bool $enabled */ @@ -152,7 +166,7 @@ public function buildLegacyKernelHandlerWeb($webHandlerClass, array $defaultLega $legacyParameters = new ParameterBag($defaultLegacyOptions); $legacyParameters->set('service-container', $container); - $request = $container->get('request'); + $request = $this->requestStack->getCurrentRequest(); if ($that->getBuildEventsEnabled()) { // PRE_BUILD_LEGACY_KERNEL for non request related stuff @@ -277,7 +291,7 @@ public function buildLegacyKernelHandlerRest($mvcConfiguration) chdir($legacyRootDir); $legacyParameters = new ParameterBag(); - $request = $container->get('request'); + $request = $this->requestStack->getCurrentRequest(); if ($that->getBuildEventsEnabled()) { // PRE_BUILD_LEGACY_KERNEL for non request related stuff diff --git a/mvc/LegacyEvents.php b/mvc/LegacyEvents.php index 26a6c065..4d811506 100644 --- a/mvc/LegacyEvents.php +++ b/mvc/LegacyEvents.php @@ -25,7 +25,7 @@ final class LegacyEvents const PRE_BUILD_LEGACY_KERNEL_WEB = 'ezpublish_legacy.build_kernel_web_handler'; /** - * The PRE_BUID_LEGACY_KERNEL occurs right before the build of the legacy handler (whatever the handler is used). + * The PRE_BUILD_LEGACY_KERNEL occurs right before the build of the legacy handler (whatever the handler is used). * This event allows to inject parameters in the legacy kernel (such as INI settings). * * The event listener method receives a