Skip to content

Commit

Permalink
Merge pull request ezsystems#90 from ezsystems/sf3_compat
Browse files Browse the repository at this point in the history
Symfony 3.x compatibility
  • Loading branch information
emodric authored Apr 20, 2017
2 parents e66c3df + eaa924d commit 3bdb710
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor/
composer.lock
ezpublish_legacy
var
bin
config.php
.php_cs.cache
Expand Down
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ return PhpCsFixer\Config::create()
->in(__DIR__)
->exclude([
'vendor',
'ezpublish_legacy',
])
->files()->name('*.php')
)
Expand Down
2 changes: 1 addition & 1 deletion bundle/Controller/LegacyRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions bundle/Controller/LegacySetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
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;
use eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger;
use eZINI;
use eZCache;

class LegacySetupController extends ContainerAware
class LegacySetupController implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* The legacy kernel instance (eZ Publish 4).
*
Expand Down Expand Up @@ -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')) {
Expand Down
14 changes: 7 additions & 7 deletions bundle/Controller/WebsiteToolbarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
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;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute;

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;
Expand All @@ -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;
}

Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
}
5 changes: 5 additions & 0 deletions bundle/DependencyInjection/Compiler/RoutingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
5 changes: 3 additions & 2 deletions bundle/DependencyInjection/Compiler/TwigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
}
4 changes: 2 additions & 2 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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%"
Expand Down Expand Up @@ -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%"
Expand Down
1 change: 0 additions & 1 deletion bundle/Resources/config/templating.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions bundle/Routing/FallbackRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])) {
Expand All @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions mvc/Kernel/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mvc/LegacyEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bdb710

Please sign in to comment.