From 5fd34e03fc36bc7332e4f19a9069974421f1579e Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 14 Jan 2018 09:13:49 +0100 Subject: [PATCH] Added new app config param to allow disabling short URL visits tracking --- .../Plugin/ApplicationConfigCustomizer.php | 13 ++++++++--- .../CLI/src/Model/CustomizableAppConfig.php | 1 + .../ApplicationConfigCustomizerTest.php | 8 ++++--- module/Core/src/Options/AppOptions.php | 22 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/module/CLI/src/Install/Plugin/ApplicationConfigCustomizer.php b/module/CLI/src/Install/Plugin/ApplicationConfigCustomizer.php index 6a6e1a45..70a64a90 100644 --- a/module/CLI/src/Install/Plugin/ApplicationConfigCustomizer.php +++ b/module/CLI/src/Install/Plugin/ApplicationConfigCustomizer.php @@ -24,14 +24,21 @@ class ApplicationConfigCustomizer implements ConfigCustomizerInterface return; } + $validator = function ($value) { + return $value; + }; $appConfig->setApp([ 'SECRET' => $io->ask( 'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one)', null, - function ($value) { - return $value; - } + $validator ) ?: $this->generateRandomString(32), + 'DISABLE_TRACK_PARAM' => $io->ask( + 'Provide a parameter name that you will be able to use to disable tracking on specific request to ' + . 'short URLs (leave empty and this feature won\'t be enabled)', + null, + $validator + ), ]); } } diff --git a/module/CLI/src/Model/CustomizableAppConfig.php b/module/CLI/src/Model/CustomizableAppConfig.php index 5784f753..b228baa8 100644 --- a/module/CLI/src/Model/CustomizableAppConfig.php +++ b/module/CLI/src/Model/CustomizableAppConfig.php @@ -225,6 +225,7 @@ final class CustomizableAppConfig implements ArraySerializableInterface $config = [ 'app_options' => [ 'secret_key' => $this->app['SECRET'], + 'disable_track_param' => $this->app['DISABLE_TRACK_PARAM'], ], 'entity_manager' => [ 'connection' => [ diff --git a/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerTest.php b/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerTest.php index a156923a..5450d0b1 100644 --- a/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerTest.php +++ b/module/CLI/test/Install/Plugin/ApplicationConfigCustomizerTest.php @@ -34,7 +34,7 @@ class ApplicationConfigCustomizerTest extends TestCase */ public function configIsRequestedToTheUser() { - $askSecret = $this->io->ask(Argument::cetera())->willReturn('the_secret'); + $ask = $this->io->ask(Argument::cetera())->willReturn('the_secret'); $config = new CustomizableAppConfig(); $this->plugin->process($this->io->reveal(), $config); @@ -42,8 +42,9 @@ class ApplicationConfigCustomizerTest extends TestCase $this->assertTrue($config->hasApp()); $this->assertEquals([ 'SECRET' => 'the_secret', + 'DISABLE_TRACK_PARAM' => 'the_secret', ], $config->getApp()); - $askSecret->shouldHaveBeenCalledTimes(1); + $ask->shouldHaveBeenCalledTimes(2); } /** @@ -62,8 +63,9 @@ class ApplicationConfigCustomizerTest extends TestCase $this->assertEquals([ 'SECRET' => 'the_new_secret', + 'DISABLE_TRACK_PARAM' => 'the_new_secret', ], $config->getApp()); - $ask->shouldHaveBeenCalledTimes(1); + $ask->shouldHaveBeenCalledTimes(2); $confirm->shouldHaveBeenCalledTimes(1); } diff --git a/module/Core/src/Options/AppOptions.php b/module/Core/src/Options/AppOptions.php index edb46f08..0220dbd8 100644 --- a/module/Core/src/Options/AppOptions.php +++ b/module/Core/src/Options/AppOptions.php @@ -22,6 +22,10 @@ class AppOptions extends AbstractOptions * @var string */ protected $secretKey = ''; + /** + * @var string|null + */ + protected $disableTrackParam; /** * AppOptions constructor. @@ -86,6 +90,24 @@ class AppOptions extends AbstractOptions return $this; } + /** + * @return string|null + */ + public function getDisableTrackParam() + { + return $this->disableTrackParam; + } + + /** + * @param string|null $disableTrackParam + * @return $this|self + */ + protected function setDisableTrackParam($disableTrackParam): self + { + $this->disableTrackParam = $disableTrackParam; + return $this; + } + /** * @return string */