mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Migrated AppOptions to immutable object
This commit is contained in:
@@ -17,7 +17,7 @@ class ApplicationFactory
|
|||||||
$appOptions = $container->get(AppOptions::class);
|
$appOptions = $container->get(AppOptions::class);
|
||||||
|
|
||||||
$commands = $config['commands'] ?? [];
|
$commands = $config['commands'] ?? [];
|
||||||
$app = new CliApp($appOptions->getName(), $appOptions->getVersion());
|
$app = new CliApp($appOptions->name, $appOptions->version);
|
||||||
$app->setCommandLoader(new ContainerCommandLoader($container, $commands));
|
$app->setCommandLoader(new ContainerCommandLoader($container, $commands));
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ return [
|
|||||||
ErrorHandler\NotFoundRedirectHandler::class => ConfigAbstractFactory::class,
|
ErrorHandler\NotFoundRedirectHandler::class => ConfigAbstractFactory::class,
|
||||||
ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class,
|
ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class,
|
||||||
|
|
||||||
Options\AppOptions::class => ConfigAbstractFactory::class,
|
Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'],
|
||||||
Options\DeleteShortUrlsOptions::class => ConfigAbstractFactory::class,
|
Options\DeleteShortUrlsOptions::class => ConfigAbstractFactory::class,
|
||||||
Options\NotFoundRedirectOptions::class => ConfigAbstractFactory::class,
|
Options\NotFoundRedirectOptions::class => ConfigAbstractFactory::class,
|
||||||
Options\RedirectOptions::class => ConfigAbstractFactory::class,
|
Options\RedirectOptions::class => ConfigAbstractFactory::class,
|
||||||
@@ -86,7 +86,6 @@ return [
|
|||||||
Domain\DomainService::class,
|
Domain\DomainService::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
Options\AppOptions::class => ['config.app_options'],
|
|
||||||
Options\DeleteShortUrlsOptions::class => ['config.delete_short_urls'],
|
Options\DeleteShortUrlsOptions::class => ['config.delete_short_urls'],
|
||||||
Options\NotFoundRedirectOptions::class => ['config.not_found_redirects'],
|
Options\NotFoundRedirectOptions::class => ['config.not_found_redirects'],
|
||||||
Options\RedirectOptions::class => ['config.redirects'],
|
Options\RedirectOptions::class => ['config.redirects'],
|
||||||
|
|||||||
@@ -4,35 +4,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Core\Options;
|
namespace Shlinkio\Shlink\Core\Options;
|
||||||
|
|
||||||
use Laminas\Stdlib\AbstractOptions;
|
|
||||||
|
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
class AppOptions extends AbstractOptions
|
final class AppOptions
|
||||||
{
|
{
|
||||||
private string $name = 'Shlink';
|
public function __construct(public string $name = 'Shlink', public string $version = '3.0.0')
|
||||||
private string $version = '3.0.0';
|
|
||||||
|
|
||||||
public function getName(): string
|
|
||||||
{
|
{
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setName(string $name): self
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getVersion(): string
|
|
||||||
{
|
|
||||||
return $this->version;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setVersion(string $version): self
|
|
||||||
{
|
|
||||||
$this->version = $version;
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ class NotifyVisitToWebHooksTest extends TestCase
|
|||||||
['webhooks' => $webhooks, 'notify_orphan_visits_to_webhooks' => $notifyOrphanVisits],
|
['webhooks' => $webhooks, 'notify_orphan_visits_to_webhooks' => $notifyOrphanVisits],
|
||||||
),
|
),
|
||||||
new ShortUrlDataTransformer(new ShortUrlStringifier([])),
|
new ShortUrlDataTransformer(new ShortUrlStringifier([])),
|
||||||
new AppOptions(['name' => 'Shlink', 'version' => '1.2.3']),
|
new AppOptions('Shlink', '1.2.3'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class HealthAction extends AbstractRestAction
|
|||||||
$statusCode = $connected ? self::STATUS_OK : self::STATUS_SERVICE_UNAVAILABLE;
|
$statusCode = $connected ? self::STATUS_OK : self::STATUS_SERVICE_UNAVAILABLE;
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'status' => $connected ? self::STATUS_PASS : self::STATUS_FAIL,
|
'status' => $connected ? self::STATUS_PASS : self::STATUS_FAIL,
|
||||||
'version' => $this->options->getVersion(),
|
'version' => $this->options->version,
|
||||||
'links' => [
|
'links' => [
|
||||||
'about' => 'https://shlink.io',
|
'about' => 'https://shlink.io',
|
||||||
'project' => 'https://github.com/shlinkio/shlink',
|
'project' => 'https://github.com/shlinkio/shlink',
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class HealthActionTest extends TestCase
|
|||||||
$em = $this->prophesize(EntityManagerInterface::class);
|
$em = $this->prophesize(EntityManagerInterface::class);
|
||||||
$em->getConnection()->willReturn($this->conn->reveal());
|
$em->getConnection()->willReturn($this->conn->reveal());
|
||||||
|
|
||||||
$this->action = new HealthAction($em->reveal(), new AppOptions(['version' => '1.2.3']));
|
$this->action = new HealthAction($em->reveal(), new AppOptions(version: '1.2.3'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|||||||
Reference in New Issue
Block a user