Migrated UrlShortenerOptions to immutable object

This commit is contained in:
Alejandro Celaya
2022-09-17 15:54:43 +02:00
parent 42af057316
commit 8d244c8d34
10 changed files with 58 additions and 113 deletions

View File

@@ -4,69 +4,17 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\Options;
use Laminas\Stdlib\AbstractOptions;
use const Shlinkio\Shlink\DEFAULT_SHORT_CODES_LENGTH;
class UrlShortenerOptions extends AbstractOptions
final class UrlShortenerOptions
{
protected $__strictMode__ = false; // phpcs:ignore
private array $domain = [];
private int $defaultShortCodesLength = DEFAULT_SHORT_CODES_LENGTH;
private bool $autoResolveTitles = false;
private bool $appendExtraPath = false;
private bool $multiSegmentSlugsEnabled = false;
public function domain(): array
{
return $this->domain;
}
protected function setDomain(array $domain): self
{
$this->domain = $domain;
return $this;
}
public function defaultShortCodesLength(): int
{
return $this->defaultShortCodesLength;
}
protected function setDefaultShortCodesLength(int $defaultShortCodesLength): self
{
$this->defaultShortCodesLength = $defaultShortCodesLength;
return $this;
}
public function autoResolveTitles(): bool
{
return $this->autoResolveTitles;
}
protected function setAutoResolveTitles(bool $autoResolveTitles): void
{
$this->autoResolveTitles = $autoResolveTitles;
}
public function appendExtraPath(): bool
{
return $this->appendExtraPath;
}
protected function setAppendExtraPath(bool $appendExtraPath): void
{
$this->appendExtraPath = $appendExtraPath;
}
public function multiSegmentSlugsEnabled(): bool
{
return $this->multiSegmentSlugsEnabled;
}
protected function setMultiSegmentSlugsEnabled(bool $multiSegmentSlugsEnabled): void
{
$this->multiSegmentSlugsEnabled = $multiSegmentSlugsEnabled;
public function __construct(
/** @var array{schema: ?string, hostname: ?string} */
public readonly array $domain = ['schema' => null, 'hostname' => null],
public readonly int $defaultShortCodesLength = DEFAULT_SHORT_CODES_LENGTH,
public readonly bool $autoResolveTitles = false,
public readonly bool $appendExtraPath = false,
public readonly bool $multiSegmentSlugsEnabled = false,
) {
}
}