Skip to content

Commit 4bb65bb

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: (24 commits) Fix Twig tests [Scheduler] Fix tests [TwigBridge] Add FormLayoutTestCase class Fix CS Allow sending scheduled messages through the slack API [TwigBridge] Add `AppVariable::getEnabledLocales()` to retrieve the enabled locales [RateLimiter] Add missing dependency [RateLimiter] Add SlidingWindowLimiter::reserve() [Messenger] Add WrappedExceptionsInterface for nested exceptions [Mime] Add `TemplatedEmail::locale()` to set the locale for the email rendering Fix CS [Messenger][Scheduler] Add AsCronTask & AsPeriodicTask attributes [Scheduler] Make debug:scheduler output more useful [Notifier] Tweak some phpdocs [FrameworkBundle] Change BrowserKitAssertionsTrait::getClient() to be protected Fix CS [FrameworkBundle] Allow BrowserKit relative URL redirect assert [Messenger] RejectRedeliveredMessageException should not be retried [Serializer] Make `ProblemNormalizer` give details about Messenger’s `ValidationFailedException` [WebProfilerBundle] Support `!` negation operator in url filter ...
2 parents d9c7865 + 1de484b commit 4bb65bb

File tree

16 files changed

+159
-7
lines changed

16 files changed

+159
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ CHANGELOG
4949
* Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead
5050
* Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead
5151
* Add `array $tokenAttributes = []` optional parameter to `KernelBrowser::loginUser()`
52+
* Add support for relative URLs in BrowserKit's redirect assertion.
53+
* Change BrowserKitAssertionsTrait::getClient() to be protected
5254

5355
6.3
5456
---
@@ -71,6 +73,7 @@ CHANGELOG
7173
* Deprecate the `Http\Client\HttpClient` service, use `Psr\Http\Client\ClientInterface` instead
7274
* Add `stop_worker_on_signals` configuration option to `messenger` to define signals which would stop a worker
7375
* Add support for `--all` option to clear all cache pools with `cache:pool:clear` command
76+
* Add `--show-aliases` option to `debug:router` command
7477

7578
6.2
7679
---

Command/RouterDebugCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected function configure(): void
5656
->setDefinition([
5757
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
5858
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
59+
new InputOption('show-aliases', null, InputOption::VALUE_NONE, 'Show aliases in overview'),
5960
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
6061
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
6162
])
@@ -92,6 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9293
'format' => $input->getOption('format'),
9394
'raw_text' => $input->getOption('raw'),
9495
'show_controllers' => $input->getOption('show-controllers'),
96+
'show_aliases' => $input->getOption('show-aliases'),
9597
'output' => $io,
9698
]);
9799

@@ -120,6 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120122
'format' => $input->getOption('format'),
121123
'raw_text' => $input->getOption('raw'),
122124
'show_controllers' => $input->getOption('show-controllers'),
125+
'show_aliases' => $input->getOption('show-aliases'),
123126
'output' => $io,
124127
'container' => $container,
125128
]);

Console/Descriptor/Descriptor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,19 @@ protected function sortByPriority(array $tag): array
260260
return $tag;
261261
}
262262

263+
/**
264+
* @return array<string, string[]>
265+
*/
266+
protected function getReverseAliases(RouteCollection $routes): array
267+
{
268+
$reverseAliases = [];
269+
foreach ($routes->getAliases() as $name => $alias) {
270+
$reverseAliases[$alias->getId()][] = $name;
271+
}
272+
273+
return $reverseAliases;
274+
}
275+
263276
public static function getClassDescription(string $class, string &$resolvedClass = null): string
264277
{
265278
$resolvedClass = $class;

Console/Descriptor/JsonDescriptor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
3737
$data = [];
3838
foreach ($routes->all() as $name => $route) {
3939
$data[$name] = $this->getRouteData($route);
40+
if (($showAliases ??= $options['show_aliases'] ?? false) && $aliases = ($reverseAliases ??= $this->getReverseAliases($routes))[$name] ?? []) {
41+
$data[$name]['aliases'] = $aliases;
42+
}
4043
}
4144

4245
$this->writeData($data, $options);

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
3939
$this->write("\n\n");
4040
}
4141
$this->describeRoute($route, ['name' => $name]);
42+
if (($showAliases ??= $options['show_aliases'] ?? false) && $aliases = ($reverseAliases ??= $this->getReverseAliases($routes))[$name] ?? []) {
43+
$this->write(sprintf("- Aliases: \n%s", implode("\n", array_map(static fn (string $alias): string => sprintf(' - %s', $alias), $aliases))));
44+
}
4245
}
4346
$this->write("\n");
4447
}

Console/Descriptor/TextDescriptor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
5353
$tableHeaders[] = 'Controller';
5454
}
5555

56+
if ($showAliases = $options['show_aliases'] ?? false) {
57+
$tableHeaders[] = 'Aliases';
58+
}
59+
5660
$tableRows = [];
5761
foreach ($routes->all() as $name => $route) {
5862
$controller = $route->getDefault('_controller');
@@ -69,6 +73,10 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
6973
$row[] = $controller ? $this->formatControllerLink($controller, $this->formatCallable($controller), $options['container'] ?? null) : '';
7074
}
7175

76+
if ($showAliases) {
77+
$row[] = implode('|', ($reverseAliases ??= $this->getReverseAliases($routes))[$name] ?? []);
78+
}
79+
7280
$tableRows[] = $row;
7381
}
7482

Console/Descriptor/XmlDescriptor.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class XmlDescriptor extends Descriptor
3535
{
3636
protected function describeRouteCollection(RouteCollection $routes, array $options = []): void
3737
{
38-
$this->writeDocument($this->getRouteCollectionDocument($routes));
38+
$this->writeDocument($this->getRouteCollectionDocument($routes, $options));
3939
}
4040

4141
protected function describeRoute(Route $route, array $options = []): void
@@ -141,13 +141,21 @@ private function writeDocument(\DOMDocument $dom): void
141141
$this->write($dom->saveXML());
142142
}
143143

144-
private function getRouteCollectionDocument(RouteCollection $routes): \DOMDocument
144+
private function getRouteCollectionDocument(RouteCollection $routes, array $options): \DOMDocument
145145
{
146146
$dom = new \DOMDocument('1.0', 'UTF-8');
147147
$dom->appendChild($routesXML = $dom->createElement('routes'));
148148

149149
foreach ($routes->all() as $name => $route) {
150150
$routeXML = $this->getRouteDocument($route, $name);
151+
if (($showAliases ??= $options['show_aliases'] ?? false) && $aliases = ($reverseAliases ??= $this->getReverseAliases($routes))[$name] ?? []) {
152+
$routeXML->firstChild->appendChild($aliasesXML = $routeXML->createElement('aliases'));
153+
foreach ($aliases as $alias) {
154+
$aliasesXML->appendChild($aliasXML = $routeXML->createElement('alias'));
155+
$aliasXML->appendChild(new \DOMText($alias));
156+
}
157+
}
158+
151159
$routesXML->appendChild($routesXML->ownerDocument->importNode($routeXML->childNodes->item(0), true));
152160
}
153161

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class UnusedTagsPass implements CompilerPassInterface
8282
'routing.loader',
8383
'routing.route_loader',
8484
'scheduler.schedule_provider',
85+
'scheduler.task',
8586
'security.authenticator.login_linker',
8687
'security.expression_language_provider',
8788
'security.remember_me_handler',

DependencyInjection/FrameworkExtension.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
use Symfony\Component\RateLimiter\Storage\CacheStorage;
140140
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
141141
use Symfony\Component\RemoteEvent\RemoteEvent;
142+
use Symfony\Component\Scheduler\Attribute\AsCronTask;
143+
use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;
142144
use Symfony\Component\Scheduler\Attribute\AsSchedule;
143145
use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
144146
use Symfony\Component\Security\Core\AuthenticationEvents;
@@ -687,6 +689,26 @@ public function load(array $configs, ContainerBuilder $container): void
687689
$container->registerAttributeForAutoconfiguration(AsSchedule::class, static function (ChildDefinition $definition, AsSchedule $attribute): void {
688690
$definition->addTag('scheduler.schedule_provider', ['name' => $attribute->name]);
689691
});
692+
foreach ([AsPeriodicTask::class, AsCronTask::class] as $taskAttributeClass) {
693+
$container->registerAttributeForAutoconfiguration(
694+
$taskAttributeClass,
695+
static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribute, \ReflectionClass|\ReflectionMethod $reflector): void {
696+
$tagAttributes = get_object_vars($attribute) + [
697+
'trigger' => match ($attribute::class) {
698+
AsPeriodicTask::class => 'every',
699+
AsCronTask::class => 'cron',
700+
},
701+
];
702+
if ($reflector instanceof \ReflectionMethod) {
703+
if (isset($tagAttributes['method'])) {
704+
throw new LogicException(sprintf('"%s" attribute cannot declare a method on "%s::%s()".', $attribute::class, $reflector->class, $reflector->name));
705+
}
706+
$tagAttributes['method'] = $reflector->getName();
707+
}
708+
$definition->addTag('scheduler.task', $tagAttributes);
709+
}
710+
);
711+
}
690712

691713
if (!$container->getParameter('kernel.debug')) {
692714
// remove tagged iterator argument for resource checkers

Resources/config/scheduler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
15+
use Symfony\Component\Scheduler\Messenger\ServiceCallMessageHandler;
1516

1617
return static function (ContainerConfigurator $container) {
1718
$container->services()
19+
->set('scheduler.messenger.service_call_message_handler', ServiceCallMessageHandler::class)
20+
->args([
21+
tagged_locator('scheduler.task'),
22+
])
23+
->tag('messenger.message_handler')
1824
->set('scheduler.messenger_transport_factory', SchedulerTransportFactory::class)
1925
->args([
2026
tagged_locator('scheduler.schedule_provider', 'name'),

0 commit comments

Comments
 (0)