mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 07:13:11 +08:00
Centralized how routes are configured to support multi-segment slugs
This commit is contained in:
30
module/Core/src/Config/MultiSegmentSlugProcessor.php
Normal file
30
module/Core/src/Config/MultiSegmentSlugProcessor.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Config;
|
||||
|
||||
use function Functional\map;
|
||||
use function str_replace;
|
||||
|
||||
class MultiSegmentSlugProcessor
|
||||
{
|
||||
private const SINGLE_SHORT_CODE_PATTERN = '{shortCode}';
|
||||
private const MULTI_SHORT_CODE_PATTERN = '{shortCode:.+}';
|
||||
|
||||
public function __invoke(array $config): array
|
||||
{
|
||||
$multiSegmentEnabled = $config['url_shortener']['multi_segment_slugs_enabled'] ?? false;
|
||||
if (! $multiSegmentEnabled) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
$config['routes'] = map($config['routes'] ?? [], static function (array $route): array {
|
||||
['path' => $path] = $route;
|
||||
$route['path'] = str_replace(self::SINGLE_SHORT_CODE_PATTERN, self::MULTI_SHORT_CODE_PATTERN, $path);
|
||||
return $route;
|
||||
});
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -84,13 +84,13 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
|
||||
->where('1=1');
|
||||
|
||||
$dateRange = $filtering->dateRange();
|
||||
if ($dateRange?->startDate() !== null) {
|
||||
if ($dateRange?->startDate !== null) {
|
||||
$qb->andWhere($qb->expr()->gte('s.dateCreated', ':startDate'));
|
||||
$qb->setParameter('startDate', $dateRange->startDate(), ChronosDateTimeType::CHRONOS_DATETIME);
|
||||
$qb->setParameter('startDate', $dateRange->startDate, ChronosDateTimeType::CHRONOS_DATETIME);
|
||||
}
|
||||
if ($dateRange?->endDate() !== null) {
|
||||
if ($dateRange?->endDate !== null) {
|
||||
$qb->andWhere($qb->expr()->lte('s.dateCreated', ':endDate'));
|
||||
$qb->setParameter('endDate', $dateRange->endDate(), ChronosDateTimeType::CHRONOS_DATETIME);
|
||||
$qb->setParameter('endDate', $dateRange->endDate, ChronosDateTimeType::CHRONOS_DATETIME);
|
||||
}
|
||||
|
||||
$searchTerm = $filtering->searchTerm();
|
||||
|
||||
@@ -245,11 +245,11 @@ class VisitRepository extends EntitySpecificationRepository implements VisitRepo
|
||||
{
|
||||
$conn = $this->getEntityManager()->getConnection();
|
||||
|
||||
if ($dateRange?->startDate() !== null) {
|
||||
$qb->andWhere($qb->expr()->gte('v.date', $conn->quote($dateRange->startDate()->toDateTimeString())));
|
||||
if ($dateRange?->startDate !== null) {
|
||||
$qb->andWhere($qb->expr()->gte('v.date', $conn->quote($dateRange->startDate->toDateTimeString())));
|
||||
}
|
||||
if ($dateRange?->endDate() !== null) {
|
||||
$qb->andWhere($qb->expr()->lte('v.date', $conn->quote($dateRange->endDate()->toDateTimeString())));
|
||||
if ($dateRange?->endDate !== null) {
|
||||
$qb->andWhere($qb->expr()->lte('v.date', $conn->quote($dateRange->endDate->toDateTimeString())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ class InDateRange extends BaseSpecification
|
||||
{
|
||||
$criteria = [];
|
||||
|
||||
if ($this->dateRange?->startDate() !== null) {
|
||||
$criteria[] = Spec::gte($this->field, $this->dateRange->startDate()->toDateTimeString());
|
||||
if ($this->dateRange?->startDate !== null) {
|
||||
$criteria[] = Spec::gte($this->field, $this->dateRange->startDate->toDateTimeString());
|
||||
}
|
||||
|
||||
if ($this->dateRange?->endDate() !== null) {
|
||||
$criteria[] = Spec::lte($this->field, $this->dateRange->endDate()->toDateTimeString());
|
||||
if ($this->dateRange?->endDate !== null) {
|
||||
$criteria[] = Spec::lte($this->field, $this->dateRange->endDate->toDateTimeString());
|
||||
}
|
||||
|
||||
return Spec::andX(...$criteria);
|
||||
|
||||
Reference in New Issue
Block a user