Skip to content

Commit

Permalink
feat(CoreBundle): Refactored node routing
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Jan 24, 2024
1 parent 2c32df2 commit eea6399
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 397 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ HOSTNAME_PMA=`pma.roadiz-core-app.test`,`pma.roadiz-core-app.local`
HOSTNAME_SOLR=`solr.roadiz-core-app.test`,`solr.roadiz-core-app.local`
HOSTNAME_MAILER=`mail.roadiz-core-app.test`,`mail.roadiz-core-app.local`

DEFAULT_GATEWAY=172.58.0.1
DEFAULT_GATEWAY=172.58.0.0
###> rezozero/intervention-request-bundle ###
IR_DEFAULT_QUALITY=90
IR_MAX_PIXEL_SIZE=2500
Expand Down
32 changes: 8 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ services:
links:
- db:db
networks:
frontproxynet:
aliases:
- ${APP_NAMESPACE}_pma
default:
aliases:
- pma
- frontproxynet
- default
labels:
- "traefik.enable=true"
- "traefik.http.services.${APP_NAMESPACE}_pma.loadbalancer.server.scheme=http"
Expand Down Expand Up @@ -91,12 +87,8 @@ services:
- solr-precreate
- ${SOLR_CORE_NAME}
networks:
frontproxynet:
aliases:
- ${APP_NAMESPACE}_solr
default:
aliases:
- solr
- frontproxynet
- default
labels:
- "traefik.enable=true"
- "traefik.http.services.${APP_NAMESPACE}_solr.loadbalancer.server.scheme=http"
Expand Down Expand Up @@ -174,12 +166,8 @@ services:
volumes:
- ./:/var/www/html:cached
networks:
frontproxynet:
aliases:
- ${APP_NAMESPACE}_nginx
default:
aliases:
- nginx
- frontproxynet
- default
labels:
- "traefik.enable=true"
- "traefik.http.services.${APP_NAMESPACE}.loadbalancer.server.scheme=http"
Expand All @@ -205,12 +193,8 @@ services:
- ${PUBLIC_MAILER_PORT}:8025/tcp
- ${SMTP_MAILER_PORT}:1025/tcp
networks:
frontproxynet:
aliases:
- ${APP_NAMESPACE}_mailer
default:
aliases:
- mailer
- frontproxynet
- default
labels:
- "traefik.enable=true"
- "traefik.http.services.${APP_NAMESPACE}_mailer.loadbalancer.server.scheme=http"
Expand Down
26 changes: 13 additions & 13 deletions lib/RoadizCompatBundle/src/Routing/ThemeAwareNodeRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace RZ\Roadiz\CompatBundle\Routing;

use Psr\Cache\InvalidArgumentException;
use RZ\Roadiz\CompatBundle\Theme\ThemeResolverInterface;
use RZ\Roadiz\CoreBundle\Routing\NodeRouter;
use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface;
Expand All @@ -15,17 +16,14 @@

final class ThemeAwareNodeRouter implements RouterInterface, RequestMatcherInterface, VersatileGeneratorInterface
{
private ThemeResolverInterface $themeResolver;
private NodeRouter $innerRouter;

/**
* @param ThemeResolverInterface $themeResolver
* @param NodeRouter $innerRouter
*/
public function __construct(ThemeResolverInterface $themeResolver, NodeRouter $innerRouter)
{
$this->themeResolver = $themeResolver;
$this->innerRouter = $innerRouter;
public function __construct(
private readonly ThemeResolverInterface $themeResolver,
private readonly NodeRouter $innerRouter
) {
}

public function setContext(RequestContext $context): void
Expand All @@ -48,6 +46,10 @@ public function getRouteCollection(): RouteCollection
return $this->innerRouter->getRouteCollection();
}

/**
* @inheritDoc
* @throws InvalidArgumentException
*/
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
{
$this->innerRouter->setTheme($this->themeResolver->findTheme($this->getContext()->getHost()));
Expand All @@ -59,12 +61,10 @@ public function match(string $pathinfo): array
return $this->innerRouter->match($pathinfo);
}

public function supports(string $name): bool
{
return $this->innerRouter->supports($name);
}

public function getRouteDebugMessage(string $name, array $parameters = []): string
/**
* @inheritDoc
*/
public function getRouteDebugMessage(mixed $name, array $parameters = []): string
{
return $this->innerRouter->getRouteDebugMessage($name, $parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,14 @@

final class NodesSourcesPathGeneratingEvent extends Event
{
/**
* @var bool
*/
protected $forceLocaleWithUrlAlias;
/**
* @var Theme|null
*/
private $theme;
/**
* @var NodesSources|null
*/
private $nodeSource;
/**
* @var array|null
*/
private $parameters;
/**
* @var RequestContext|null
*/
private $requestContext;
/**
* @var bool
*/
private $forceLocale = false;
/**
* @var string|null
*/
private $path;
private ?string $path;
/**
* @var bool Tells Node Router to prepend request context information to path or not.
*/
private $isComplete = false;
/**
* @var bool
*/
protected $containsScheme = false;
private bool $isComplete = false;
protected bool $containsScheme = false;

/**
* NodesSourcesPathGeneratingEvent constructor.
*
* @param Theme|null $theme
* @param NodesSources|null $nodeSource
* @param RequestContext|null $requestContext
Expand All @@ -59,19 +27,13 @@ final class NodesSourcesPathGeneratingEvent extends Event
* @param bool $forceLocaleWithUrlAlias
*/
public function __construct(
?Theme $theme,
?NodesSources $nodeSource,
?RequestContext $requestContext,
array $parameters = [],
bool $forceLocale = false,
bool $forceLocaleWithUrlAlias = false
private readonly ?Theme $theme,
private ?NodesSources $nodeSource,
private readonly ?RequestContext $requestContext,
private array $parameters = [],
private readonly bool $forceLocale = false,
private bool $forceLocaleWithUrlAlias = false
) {
$this->theme = $theme;
$this->nodeSource = $nodeSource;
$this->requestContext = $requestContext;
$this->forceLocale = $forceLocale;
$this->parameters = $parameters;
$this->forceLocaleWithUrlAlias = $forceLocaleWithUrlAlias;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@

class NodeSourcePathSubscriber implements EventSubscriberInterface
{
protected NodesSourcesPathAggregator $pathAggregator;

/**
* @param NodesSourcesPathAggregator $pathAggregator
*/
public function __construct(NodesSourcesPathAggregator $pathAggregator)
{
$this->pathAggregator = $pathAggregator;
public function __construct(
protected readonly NodesSourcesPathAggregator $pathAggregator
) {
}

/**
Expand All @@ -28,7 +23,6 @@ public static function getSubscribedEvents(): array
{
return [
NodesSourcesPathGeneratingEvent::class => [['onNodesSourcesPath', -100]],
'\RZ\Roadiz\Core\Events\NodesSources\NodesSourcesPathGeneratingEvent' => [['onNodesSourcesPath', -100]],
];
}

Expand All @@ -39,7 +33,6 @@ public function onNodesSourcesPath(NodesSourcesPathGeneratingEvent $event): void
{
$urlGenerator = new NodesSourcesUrlGenerator(
$this->pathAggregator,
null,
$event->getNodeSource(),
$event->isForceLocale(),
$event->isForceLocaleWithUrlAlias()
Expand Down
29 changes: 0 additions & 29 deletions lib/RoadizCoreBundle/src/Routing/DeferredRouteCollection.php

This file was deleted.

20 changes: 3 additions & 17 deletions lib/RoadizCoreBundle/src/Routing/DynamicUrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace RZ\Roadiz\CoreBundle\Routing;

use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use RZ\Roadiz\CoreBundle\Preview\PreviewResolverInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
Expand All @@ -18,25 +17,12 @@
*/
abstract class DynamicUrlMatcher extends UrlMatcher
{
protected Stopwatch $stopwatch;
protected LoggerInterface $logger;
protected PreviewResolverInterface $previewResolver;

/**
* @param RequestContext $context
* @param PreviewResolverInterface $previewResolver
* @param Stopwatch $stopwatch
* @param LoggerInterface|null $logger
*/
public function __construct(
RequestContext $context,
PreviewResolverInterface $previewResolver,
Stopwatch $stopwatch,
?LoggerInterface $logger = null
protected readonly PreviewResolverInterface $previewResolver,
protected readonly Stopwatch $stopwatch,
protected readonly LoggerInterface $logger
) {
parent::__construct(new RouteCollection(), $context);
$this->stopwatch = $stopwatch;
$this->logger = $logger ?? new NullLogger();
$this->previewResolver = $previewResolver;
}
}
Loading

0 comments on commit eea6399

Please sign in to comment.