Skip to content

Commit b606f32

Browse files
Merge pull request #263 from eliashaeussler/feature/strategy-names
2 parents 68473af + c45eee6 commit b606f32

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

src/Command/CacheWarmupCommand.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ protected function configure(): void
7070
$configurableCrawlerInterface = Crawler\ConfigurableCrawlerInterface::class;
7171
$textFormatter = Formatter\TextFormatter::getType();
7272
$jsonFormatter = Formatter\JsonFormatter::getType();
73+
$sortByChangeFrequencyStrategy = Crawler\Strategy\SortByChangeFrequencyStrategy::getName();
74+
$sortByLastModificationDateStrategy = Crawler\Strategy\SortByLastModificationDateStrategy::getName();
75+
$sortByPriorityStrategy = Crawler\Strategy\SortByPriorityStrategy::getName();
7376

7477
$this->setDescription('Warms up caches of URLs provided by a given set of XML sitemaps.');
7578
$this->setHelp(<<<HELP
@@ -143,13 +146,13 @@ protected function configure(): void
143146
URLs can be crawled using a specific crawling strategy, e.g. by sorting them by a specific property.
144147
For this, use the <comment>--strategy</comment> option together with a predefined value:
145148
146-
<comment>%command.full_name% --strategy sort-by-priority</comment>
149+
<comment>%command.full_name% --strategy {$sortByPriorityStrategy}</comment>
147150
148151
The following strategies are currently available:
149152
150-
* <comment>sort-by-changefreq</comment>
151-
* <comment>sort-by-lastmod</comment>
152-
* <comment>sort-by-priority</comment>
153+
* <comment>{$sortByChangeFrequencyStrategy}</comment>
154+
* <comment>{$sortByLastModificationDateStrategy}</comment>
155+
* <comment>{$sortByPriorityStrategy}</comment>
153156
154157
<info>Allow failures</info>
155158
<info>==============</info>
@@ -372,9 +375,9 @@ private function initializeCacheWarmer(
372375

373376
// Initialize crawling strategy
374377
$strategy = match ($input->getOption('strategy')) {
375-
'sort-by-changefreq' => new Crawler\Strategy\SortByChangeFrequencyStrategy(),
376-
'sort-by-lastmod' => new Crawler\Strategy\SortByLastModificationDateStrategy(),
377-
'sort-by-priority' => new Crawler\Strategy\SortByPriorityStrategy(),
378+
Crawler\Strategy\SortByChangeFrequencyStrategy::getName() => new Crawler\Strategy\SortByChangeFrequencyStrategy(),
379+
Crawler\Strategy\SortByLastModificationDateStrategy::getName() => new Crawler\Strategy\SortByLastModificationDateStrategy(),
380+
Crawler\Strategy\SortByPriorityStrategy::getName() => new Crawler\Strategy\SortByPriorityStrategy(),
378381
null => null,
379382
default => throw new Console\Exception\RuntimeException('The given crawling strategy is invalid.', 1677618007),
380383
};

src/Crawler/Strategy/CrawlingStrategy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ interface CrawlingStrategy
3939
* @return list<Sitemap\Url>
4040
*/
4141
public function prepareUrls(array $urls): array;
42+
43+
/**
44+
* @return non-empty-string
45+
*/
46+
public static function getName(): string;
4247
}

src/Crawler/Strategy/SortByChangeFrequencyStrategy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
*/
3434
final class SortByChangeFrequencyStrategy extends SortingStrategy
3535
{
36+
public static function getName(): string
37+
{
38+
return 'sort-by-changefreq';
39+
}
40+
3641
protected function sortUrls(Sitemap\Url $a, Sitemap\Url $b): int
3742
{
3843
return $this->mapChangeFrequency($a->getChangeFrequency())

src/Crawler/Strategy/SortByLastModificationDateStrategy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
*/
3434
final class SortByLastModificationDateStrategy extends SortingStrategy
3535
{
36+
public static function getName(): string
37+
{
38+
return 'sort-by-lastmod';
39+
}
40+
3641
protected function sortUrls(Sitemap\Url $a, Sitemap\Url $b): int
3742
{
3843
return ($this->resolveLastModificationDate($a) <=> $this->resolveLastModificationDate($b)) * -1;

src/Crawler/Strategy/SortByPriorityStrategy.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
*/
3434
final class SortByPriorityStrategy extends SortingStrategy
3535
{
36+
public static function getName(): string
37+
{
38+
return 'sort-by-priority';
39+
}
40+
3641
protected function sortUrls(Sitemap\Url $a, Sitemap\Url $b): int
3742
{
3843
return ($a->getPriority() <=> $b->getPriority()) * -1;

0 commit comments

Comments
 (0)