Skip to content

Commit

Permalink
Make command lazy (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 authored Jun 25, 2022
1 parent 577e970 commit c36a71d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
}
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true
},
"sort-packages": true
}
}
42 changes: 23 additions & 19 deletions src/Command/SitemapGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sonata\Exporter\Writer\SitemapWriter;
use Sonata\SeoBundle\Sitemap\Source;
use Sonata\SeoBundle\Sitemap\SourceManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -32,8 +33,13 @@
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
#[AsCommand(name: 'sonata:seo:sitemap', description: 'Create a sitemap')]
final class SitemapGeneratorCommand extends Command
{
// TODO: Remove static properties when support for Symfony < 5.4 is dropped.
protected static $defaultName = 'sonata:seo:sitemap';
protected static $defaultDescription = 'Create a sitemap';

private RouterInterface $router;

private SourceManager $sitemapManager;
Expand All @@ -54,27 +60,25 @@ public function __construct(

public function configure(): void
{
$this->setName('sonata:seo:sitemap');

$this->addArgument('dir', InputArgument::REQUIRED, 'The directory to store the sitemap.xml file');
$this->addArgument('host', InputArgument::REQUIRED, 'Set the host');
$this->addOption('scheme', null, InputOption::VALUE_OPTIONAL, 'Set the scheme', 'http');
$this->addOption('baseurl', null, InputOption::VALUE_OPTIONAL, 'Set the base url', '');
$this->addOption(
'sitemap_path',
null,
InputOption::VALUE_OPTIONAL,
'Set the sitemap relative path (if in a specific directory)',
''
);
\assert(null !== static::$defaultDescription);

$this->setDescription('Create a sitemap');
$this->setHelp(
<<<'EOT'
$this
// TODO: Remove setDescription when support for Symfony < 5.4 is dropped.
->setDescription(static::$defaultDescription)
->setHelp(<<<'EOT'
The <info>sonata:seo:sitemap</info> command create new sitemap files (index + sitemap).

EOT
);
EOT)
->addArgument('dir', InputArgument::REQUIRED, 'The directory to store the sitemap.xml file')
->addArgument('host', InputArgument::REQUIRED, 'Set the host')
->addOption('scheme', null, InputOption::VALUE_OPTIONAL, 'Set the scheme', 'http')
->addOption('baseurl', null, InputOption::VALUE_OPTIONAL, 'Set the base url', '')
->addOption(
'sitemap_path',
null,
InputOption::VALUE_OPTIONAL,
'Set the sitemap relative path (if in a specific directory)',
''
);
}

public function execute(InputInterface $input, OutputInterface $output): int
Expand Down

0 comments on commit c36a71d

Please sign in to comment.