Skip to content

Commit

Permalink
Restore methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny van Wijk committed Nov 4, 2024
1 parent b4c0040 commit 4029475
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 2 deletions.
7 changes: 7 additions & 0 deletions UPGRADE-7.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ PagePartBundle
--------------

- Not passing a HasPagePartsInterface as second parameter in PagePartEvent is deprecated and will be required in 8.0.


MultiDomainBundle
-----------------

- The multidomain-bundle has now some improved logic in the router itself. Using the old router logic is deprecated and the new will be the default in 8.0.
To enable the new and improved router, set the `kunstmaan_multi_domain.enable_improved_domain_based_local_router` config to `true`.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->end()
->end();
->end()
->booleanNode('enable_improved_domain_based_local_router')->defaultFalse()->end()
->end();

return $treeBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public function load(array $configs, ContainerBuilder $container): void

$adminFirewall = $container->getParameter('kunstmaan_admin.admin_firewall_name');
$container->getDefinition(LogoutHostOverrideCleanupEventSubscriber::class)->addTag('kernel.event_subscriber', ['dispatcher' => 'security.event_dispatcher.' . $adminFirewall]);

$enableImprovedRouter = $config['enable_improved_domain_based_local_router'] ?? false;
if (!$enableImprovedRouter) {
trigger_deprecation('kunstmaan/multidomain-bundle', '7.2', 'Not setting the "kunstmaan_multi_domain.enable_improved_domain_based_local_router" config to true is deprecated, it will always be true in 8.0.');
}
if ($container->hasDefinition('kunstmaan_node.slugrouter')) {
$slugRouter = $container->findDefinition('kunstmaan_node.slugrouter');
if ($slugRouter->getClass() === $container->getParameter('kunstmaan_multi_domain.router.class')) {
$slugRouter->addMethodCall('enabledImprovedDomainBasedLocaleRouter', [$enableImprovedRouter]);
}
}
}

/**
Expand Down
77 changes: 77 additions & 0 deletions src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@

class DomainBasedLocaleRouter extends SlugRouter
{
/**
* @var RouteCollection
* @deprecated routeCollectionMultiLanguage property is deprecated in 7.2 and will be removed in 8.0. There is no replacement for this property.
*/
protected $routeCollectionMultiLanguage;

private ?array $otherSite = null;
private array $cachedNodeTranslations = [];

/**
* NEXT_MAJOR: Remove method/property
*
* @internal
*/
private bool $enabledImprovedDomainBasedLocaleRouter = false;

/**
* Generate an url for a supplied route
*
Expand Down Expand Up @@ -148,6 +161,21 @@ private function getReverseLocaleMap(): array
*/
public function getRouteCollection(): RouteCollection
{
if (!$this->enabledImprovedDomainBasedLocaleRouter) {
trigger_deprecation('kunstmaan/multidomain-bundle', '7.2', 'Not enabling the improved router is deprecated and the changed and improved router will be the default in 8.0. Set the "kunstmaan_multi_domain.enable_improved_domain_based_local_router" config to true.');

if (($this->otherSite && $this->isMultiLanguage($this->otherSite['host'])) || (!$this->otherSite && $this->isMultiLanguage())) {
if (!$this->routeCollectionMultiLanguage) {
$this->routeCollectionMultiLanguage = new RouteCollection();

$this->addMultiLangPreviewRoute();
$this->addMultiLangSlugRoute();
}

return $this->routeCollectionMultiLanguage;
}
}

if (!$this->routeCollection) {
$this->routeCollection = new RouteCollection();

Expand All @@ -167,6 +195,45 @@ protected function addSlugRoute()
$this->addRoute('_slug', $routeParameters);
}

/**
* Add the slug route to the route collection
*/
protected function addMultiLangPreviewRoute()
{
trigger_deprecation('kunstmaan/multidomain-bundle', '7.2', 'This method is deprecated and will be removed in 8.0.');

$routeParameters = $this->getPreviewRouteParameters();
$this->addMultiLangRoute('_slug_preview', $routeParameters);
}

/**
* Add the slug route to the route collection multilanguage
*/
protected function addMultiLangSlugRoute()
{
trigger_deprecation('kunstmaan/multidomain-bundle', '7.2', 'This method is deprecated and will be removed in 8.0.');

$routeParameters = $this->getSlugRouteParameters();
$this->addMultiLangRoute('_slug', $routeParameters);
}

/**
* @param string $name
*/
protected function addMultiLangRoute($name, array $parameters = [])
{
trigger_deprecation('kunstmaan/multidomain-bundle', '7.2', 'This method is deprecated and will be removed in 8.0.');

$this->routeCollectionMultiLanguage->add(
$name,
new Route(
$parameters['path'],
$parameters['defaults'],
$parameters['requirements']
)

Check failure on line 233 in src/Kunstmaan/MultiDomainBundle/Router/DomainBasedLocaleRouter.php

View workflow job for this annotation

GitHub Actions / PHPStan

Instantiated class Kunstmaan\MultiDomainBundle\Router\Route not found.
);
}

/**
* Return slug route parameters
*
Expand Down Expand Up @@ -206,4 +273,14 @@ protected function getSlugRouteParameters()
'requirements' => $slugRequirements,
];
}

/**
* NEXT_MAJOR: Remove method/property
*
* @interal
*/
public function enabledImprovedDomainBasedLocaleRouter(bool $enabled): void
{
$this->enabledImprovedDomainBasedLocaleRouter = $enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function testProcessedValueContainsRequiredValue()
],
],
],
'enable_improved_domain_based_local_router' => true,
];

$this->assertProcessedConfigurationEquals([$array], $array);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Kunstmaan\MultiDomainBundle\DependencyInjection\KunstmaanMultiDomainExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;

class KunstmaanMultiDomainExtensionTest extends AbstractExtensionTestCase
{
use ExpectDeprecationTrait;

/**
* @return ExtensionInterface[]
*/
Expand Down Expand Up @@ -38,10 +41,40 @@ public function testCorrectParametersHaveBeenSet()
],
],
],
'enable_improved_domain_based_local_router' => true,
]);

$this->assertContainerBuilderHasParameter('kunstmaan_multi_domain.hosts');

$this->assertContainerBuilderHasAlias('kunstmaan_admin.domain_configuration', 'kunstmaan_multi_domain.domain_configuration');
}

/**
* @group legacy
*/
public function testImprovedRouterConfigDeprecation()
{
$this->expectDeprecation('Since kunstmaan/multidomain-bundle 7.2: Not setting the "kunstmaan_multi_domain.enable_improved_domain_based_local_router" config to true is deprecated, it will always be true in 8.0.');

$this->setParameter('kunstmaan_admin.admin_firewall_name', 'main');
$this->load([
'hosts' => [
'host_one' => [
'host' => 'cia.gov',
'protocol' => 'https',
'aliases' => ['cia.com'],
'type' => 'single_lang',
'root' => 'homepage',
'default_locale' => 'nl',
'locales' => [
[
'uri_locale' => '/nl',
'locale' => 'nl',
'extra' => 'huh?',
],
],
],
],
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function testAddMultiLangSlugRoute()
$request = $this->getRequest('http://singlelangdomain.tld/');

$object = new DomainBasedLocaleRouter($domainConfiguration, $this->getRequestStack($request), $this->getEntityManager(new NodeTranslation()), 'admin');
$object->enabledImprovedDomainBasedLocaleRouter(true);

$mirror = new \ReflectionClass(DomainBasedLocaleRouter::class);
$property = $mirror->getProperty('otherSite');
Expand Down Expand Up @@ -140,6 +141,7 @@ public function testGetRouteCollection()

/** @var Container $container */
$object = new DomainBasedLocaleRouter($domainConfiguration, $this->getRequestStack($request), $this->getEntityManager(new NodeTranslation()), 'admin');
$object->enabledImprovedDomainBasedLocaleRouter(true);
$mirror = new \ReflectionClass(DomainBasedLocaleRouter::class);
$property = $mirror->getProperty('otherSite');
$property->setAccessible(true);
Expand Down Expand Up @@ -216,6 +218,9 @@ private function getNodeTranslationRepository($nodeTranslation = null)

private function getDomainBasedLocaleRouter($request, $nodeTranslation = null)
{
return new DomainBasedLocaleRouter($this->getDomainConfiguration(), $this->getRequestStack($request), $this->getEntityManager($nodeTranslation), 'admin');
$router = new DomainBasedLocaleRouter($this->getDomainConfiguration(), $this->getRequestStack($request), $this->getEntityManager($nodeTranslation), 'admin');
$router->enabledImprovedDomainBasedLocaleRouter(true);

return $router;
}
}

0 comments on commit 4029475

Please sign in to comment.