Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 9.4.0 #234

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [9.4.0] - 2024-12-27
### Added
* Add config option for `REDIRECT_EXTRA_PATH_MODE`
* Add config option for `DB_USE_ENCRYPTION`

### Changed
* *Nothing*

### Deprecated
* Deprecate `AppendExtraPathConfigOption`.

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [9.3.0] - 2024-11-24
### Added
* *Nothing*
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
],
"require": {
"php": "^8.2",
"laminas/laminas-config-aggregator": "^1.15",
"laminas/laminas-servicemanager": "^4.2 || ^3.22",
"laminas/laminas-stdlib": "^3.19",
"shlinkio/shlink-config": "^3.1",
"symfony/console": "^7.1",
"symfony/filesystem": "^7.1",
"symfony/process": "^7.1",
"laminas/laminas-config-aggregator": "^1.17",
"laminas/laminas-servicemanager": "^4.3 || ^3.23",
"laminas/laminas-stdlib": "^3.20",
"shlinkio/shlink-config": "^3.4",
"symfony/console": "^7.2",
"symfony/filesystem": "^7.2",
"symfony/process": "^7.2",
"webimpress/safe-writer": "^2.2"
},
"require-dev": {
"devster/ubench": "^2.1",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^11.3",
"phpunit/phpunit": "^11.5",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.4.0",
"symfony/var-dumper": "^7.1"
"symfony/var-dumper": "^7.2"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'Database > Password' => Config\Option\Database\DatabasePasswordConfigOption::class,
'Database > Unix socket (Mysql/MariaDB)'
=> Config\Option\Database\DatabaseUnixSocketConfigOption::class,
'Database > Use encryption' => Config\Option\Database\DatabaseUseEncryptionConfigOption::class,
],
'URL SHORTENER' => [
'URL shortener > Short domain' => Config\Option\UrlShortener\ShortDomainHostConfigOption::class,
Expand All @@ -60,6 +61,7 @@
'URL shortener > Auto resolve titles'
=> Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class,
'URL shortener > Append extra path' => Config\Option\UrlShortener\AppendExtraPathConfigOption::class,
'URL shortener > Extra path mode' => Config\Option\UrlShortener\ExtraPathModeConfigOption::class,
'URL shortener > Multi-segment slugs'
=> Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class,
'URL shortener > Trailing slashes' => Config\Option\UrlShortener\EnableTrailingSlashConfigOption::class,
Expand Down Expand Up @@ -142,13 +144,15 @@
Config\Option\Database\DatabaseUserConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabasePasswordConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseUnixSocketConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseUseEncryptionConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\BaseUrlRedirectConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\InvalidShortUrlRedirectConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\Regular404RedirectConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ShortDomainHostConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ShortDomainSchemaConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AppendExtraPathConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ExtraPathModeConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\EnableMultiSegmentSlugsConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\EnableTrailingSlashConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ShortUrlModeConfigOption::class => InvokableFactory::class,
Expand Down
24 changes: 24 additions & 0 deletions src/Config/Option/Database/DatabaseUseEncryptionConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\Database;

use Symfony\Component\Console\Style\StyleInterface;

class DatabaseUseEncryptionConfigOption extends AbstractNonSqliteDependentConfigOption
{
public function getEnvVar(): string
{
return 'DB_USE_ENCRYPTION';
}

public function ask(StyleInterface $io, array $currentOptions): bool
{
return $io->confirm(
'Do you want the database connection to be encrypted? Enabling this will make database connections fail if '
. 'your database server does not support or enforce encryption.',
default: false,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

/** @deprecated */
class AppendExtraPathConfigOption extends BaseConfigOption
{
public function getEnvVar(): string
Expand Down
45 changes: 45 additions & 0 deletions src/Config/Option/UrlShortener/ExtraPathModeConfigOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer\Config\Option\UrlShortener;

use Shlinkio\Shlink\Installer\Config\Option\BaseConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class ExtraPathModeConfigOption extends BaseConfigOption
{
public const MODES = [
'default' => 'Match strictly',
'append' => 'Append extra path',
'ignore' => 'Discard extra path',
];

public function getEnvVar(): string
{
return 'REDIRECT_EXTRA_PATH_MODE';
}

public function ask(StyleInterface $io, array $currentOptions): string
{
return $io->choice(
question: <<<QUESTION
Do you want Shlink to redirect short URLs as soon as the first segment of the path matches a short code?

append:
* {shortDomain}/{shortCode}/[...extraPath] -> {longUrl}/[...extraPath]
* https://s.test/abc123 -> https://www.example.com
* https://s.test/abc123/shlinkio -> https://www.example.com/shlinkio

ignore:
* {shortDomain}/{shortCode}/[...extraPath] -> {longUrl}
* https://s.test/abc123 -> https://www.example.com
* https://s.test/abc123/shlinkio -> https://www.example.com


QUESTION,
choices: self::MODES,
default: 'default',
);
}
}
3 changes: 1 addition & 2 deletions src/Config/Option/UrlShortener/ShortUrlModeConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ public function getEnvVar(): string

public function ask(StyleInterface $io, array $currentOptions): string
{
$options = self::MODES;
return $io->choice(
'How do you want short URLs to be matched?'
. PHP_EOL
. '<options=bold;fg=yellow> Warning!</> <comment>This feature is experimental. It only applies to public '
. 'routes (short URLs and QR codes). REST API routes always use strict match.</comment>'
. PHP_EOL,
$options,
self::MODES,
'strict',
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Installer\Config\Option\Database;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Installer\Config\Option\Database\DatabaseUseEncryptionConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class DatabaseUseEncryptionConfigOptionTest extends TestCase
{
private DatabaseUseEncryptionConfigOption $configOption;

public function setUp(): void
{
$this->configOption = new DatabaseUseEncryptionConfigOption();
}

#[Test]
public function returnsExpectedEnvVar(): void
{
self::assertEquals('DB_USE_ENCRYPTION', $this->configOption->getEnvVar());
}

#[Test]
#[TestWith([true])]
#[TestWith([false])]
public function expectedQuestionIsAsked(bool $expectedAnswer): void
{
$io = $this->createMock(StyleInterface::class);
$io->expects($this->once())->method('confirm')->with(
'Do you want the database connection to be encrypted? Enabling this will make database connections fail if '
. 'your database server does not support or enforce encryption.',
false,
)->willReturn($expectedAnswer);

$answer = $this->configOption->ask($io, []);

self::assertEquals($expectedAnswer, $answer);
}
}
63 changes: 63 additions & 0 deletions test/Config/Option/UrlShortener/ExtraPathModeConfigOptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Installer\Config\Option\UrlShortener;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Installer\Config\Option\UrlShortener\ExtraPathModeConfigOption;
use Symfony\Component\Console\Style\StyleInterface;

class ExtraPathModeConfigOptionTest extends TestCase
{
private ExtraPathModeConfigOption $configOption;

public function setUp(): void
{
$this->configOption = new ExtraPathModeConfigOption();
}

#[Test]
public function returnsExpectedEnvVar(): void
{
self::assertEquals('REDIRECT_EXTRA_PATH_MODE', $this->configOption->getEnvVar());
}

#[Test, DataProvider('provideChoices')]
public function expectedQuestionIsAsked(string $choice): void
{
$io = $this->createMock(StyleInterface::class);
$io->expects($this->once())->method('choice')->with(
<<<QUESTION
Do you want Shlink to redirect short URLs as soon as the first segment of the path matches a short code?

append:
* {shortDomain}/{shortCode}/[...extraPath] -> {longUrl}/[...extraPath]
* https://s.test/abc123 -> https://www.example.com
* https://s.test/abc123/shlinkio -> https://www.example.com/shlinkio

ignore:
* {shortDomain}/{shortCode}/[...extraPath] -> {longUrl}
* https://s.test/abc123 -> https://www.example.com
* https://s.test/abc123/shlinkio -> https://www.example.com


QUESTION,
ExtraPathModeConfigOption::MODES,
'default',
)->willReturn($choice);

$answer = $this->configOption->ask($io, []);

self::assertEquals($choice, $answer);
}

public static function provideChoices(): iterable
{
foreach (ExtraPathModeConfigOption::MODES as $mode => $_) {
yield $mode => [$mode];
}
}
}