Closed franmomu closed 1 year ago
Maybe we should add handles="Presta\SitemapBundle\Messenger\DumpSitemapMessage"
as Symfony does in it's core configurations?
Edit: oh because ecd355fbfa0e2201ffa7625673ffcdffda336756 was not released yet..
Also I saw another two deprecation logs but they says the same:
The "Symfony\Component\Console\Command\Command::$defaultName" property is considered final. You should not override it in "Presta\SitemapBundle\Command\DumpSitemapsCommand".
Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "Presta\SitemapBundle\Command\DumpSitemapsCommand" class instead.
Maybe we should add
handles="Presta\SitemapBundle\Messenger\DumpSitemapMessage"
as Symfony does in it's core configurations?
Apparently it's not necessary: https://symfony.com/doc/current/messenger.html#manually-configuring-handlers
<service id="App\MessageHandler\SmsNotificationHandler">
<!-- handles is only needed if it can't be guessed by type-hint -->
<tag name="messenger.message_handler"
handles="App\Message\SmsNotification"/>
</service>
but if they have it I don't know why 🤷♂️
When it is declared Symfony does not need to guess what this handler handles, so imho from perf side it would be better even it's unnoticeable
When it is declared Symfony does not need to guess what this handler handles, so imho from perf side it would be better even it's unnoticeable
There is no need then to remove the interface 👍
I got another deprecation with symfony v6.2.6:
[2023-02-17T23:28:29.241934+00:00] deprecation.INFO: User Deprecated: Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "Presta\SitemapBundle\Command\DumpSitemapsCommand" class instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Since symfony/console 6.1: Relying on the static property \"$defaultName\" for setting a command name is deprecated. Add the \"Symfony\\Component\\Console\\Attribute\\AsCommand\" attribute to the \"Presta\\SitemapBundle\\Command\\DumpSitemapsCommand\" class instead. at /var/www/coupodo.com/html/vendor/symfony/console/Command/Command.php:85)"} []
Here is fix for it:
`<?php
/*
namespace Presta\SitemapBundle\Command;
use Presta\SitemapBundle\Service\DumperInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Console\Attribute\AsCommand;
/**
Command to dump the sitemaps to provided directory */
class DumpSitemapsCommand extends Command { /**
/**
/**
public function __construct(RouterInterface $router, DumperInterface $dumper, string $defaultTarget) { $this->router = $router; $this->dumper = $dumper; $this->defaultTarget = $defaultTarget;
parent::__construct();
}
/**
/**
@inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output): int { /* @var string $targetDir / $targetDir = $input->getArgument('target'); $targetDir = rtrim($targetDir, '/');
/* @var string|null $baseUrl / $baseUrl = $input->getOption('base-url'); if ($baseUrl) { $baseUrl = rtrim($baseUrl, '/') . '/';
//sanity check
if (!parse_url($baseUrl, PHP_URL_HOST)) {
throw new \InvalidArgumentException(
'Invalid base url. Use fully qualified base url, e.g. http://acme.com/',
-1
);
}
// Set Router's host used for generating URLs from configuration param
// There is no other way to manage domain in CLI
$request = Request::create($baseUrl);
$this->router->getContext()->fromRequest($request);
} else { $baseUrl = $this->getBaseUrl(); }
/* @var string|null $section /
$section = $input->getOption('section');
if ($section) {
$output->writeln(
sprintf(
"Dumping sitemaps section
$options = [ 'gzip' => (bool)$input->getOption('gzip'), ]; $filenames = $this->dumper->dump($targetDir, $baseUrl, $section, $options);
if (!is_array($filenames)) {
$output->writeln(
"
return 1;
}
$output->writeln("
return 0; }
private function getBaseUrl(): string { $context = $this->router->getContext();
if ('' === $host = $context->getHost()) {
throw new \RuntimeException(
'Router host must be configured to be able to dump the sitemap, please see documentation.'
);
}
$scheme = $context->getScheme();
$port = '';
if ('http' === $scheme && 80 != $context->getHttpPort()) {
$port = ':' . $context->getHttpPort();
} elseif ('https' === $scheme && 443 != $context->getHttpsPort()) {
$port = ':' . $context->getHttpsPort();
}
return rtrim($scheme . '://' . $host . $port, '/') . '/';
} }`
Could this get merged? :blush:
I will take some time to see if something more is required for us to release it, but trying to do it ASAP
The deprecation about MessageHandlerInterface
is still triggered. I guess we should conditionally create the class based on symfony version something like:
if (Kernel::VERSION_ID >= 60200) {
class DumpSitemapMessageHandler {}
} else {
class DumpSitemapMessageHandler implements MessageHandlerInterface {}
}
to avoid triggering it. or check if we need to implement it at all.
Here we go again with these ugly solutions ^^ I'm wondering whether it is actually BC ? If we remove the interface, but it is still working on EVERY symfony version we support, it should be OK right ? This code was never intended to be used directly, or extended, or... I believe that if someone has some static analysis tools plugged on, relying on this interface, he should be pissed we removed the interface, but does that exists anyway ? Do we have examples on how the community has handled these changes ?
I leaning to think that handles
part in config is enough and should work
When using the bundle with Symfony 6.2 there is this deprecation warning:
The "Presta\SitemapBundle\Messenger\DumpSitemapMessageHandler" class implements "Symfony\Component\Messenger\Handler\MessageHandlerInterface" that is deprecated since Symfony 6.2, use the {@see AsMessageHandler} attribute instead.
AFAIK the
MessageHandlerInterface
is just a marker to tell Symfony to autoconfigure the class, but since it's already defined and configured inhttps://github.com/prestaconcept/PrestaSitemapBundle/blob/61e6c07606e4a52dfd76a0b754b07e3cdd50e31a/config/messenger.xml#L7-L12
I think the interface is not necessary.
~Technically this is a BC break, but I guess this class is not meant to be extended by the user.~
Update: Following https://github.com/prestaconcept/PrestaSitemapBundle/pull/303#issuecomment-1384860212, it is resolved by adding
handles="Presta\SitemapBundle\Messenger\DumpSitemapMessage"
, there is no need to remove the interface for now.