diff --git a/app/config/services.neon b/app/config/services.neon index 97eb42ae6..872d783d1 100644 --- a/app/config/services.neon +++ b/app/config/services.neon @@ -3,7 +3,6 @@ services: cliArgs: type: MichalSpacekCz\Application\Cli\CliArgs imported: true - - MichalSpacekCz\Application\ComponentParameters - MichalSpacekCz\Application\Error - MichalSpacekCz\Application\LinkGenerator localeLinkGenerator: MichalSpacekCz\Application\Locale\LocaleLinkGenerator(languages: %locales.languages%) diff --git a/app/src/Application/AppRequest.php b/app/src/Application/AppRequest.php index a588f85fc..f4dc82fae 100644 --- a/app/src/Application/AppRequest.php +++ b/app/src/Application/AppRequest.php @@ -4,7 +4,6 @@ namespace MichalSpacekCz\Application; use MichalSpacekCz\Application\Exceptions\NoOriginalRequestException; -use MichalSpacekCz\Application\Exceptions\ParameterNotStringException; use MichalSpacekCz\ShouldNotHappenException; use Nette\Application\Request; use Throwable; @@ -28,26 +27,6 @@ public function getOriginalRequest(?Request $request): Request } - /** - * @return array - * @throws NoOriginalRequestException - * @throws ParameterNotStringException - */ - public function getOriginalRequestStringParameters(?Request $request): array - { - $params = []; - foreach ($this->getOriginalRequest($request)->getParameters() as $name => $value) { - $name = (string)$name; - if ($value === null || is_string($value)) { - $params[$name] = $value; - } else { - throw new ParameterNotStringException($name, get_debug_type($value)); - } - } - return $params; - } - - public function getException(Request $request): Throwable { $e = $request->getParameter('exception'); diff --git a/app/src/Application/ComponentParameters.php b/app/src/Application/ComponentParameters.php deleted file mode 100644 index bbb14c96b..000000000 --- a/app/src/Application/ComponentParameters.php +++ /dev/null @@ -1,30 +0,0 @@ - - * @throws ParameterNotStringException - */ - public function getStringParameters(Component $component): array - { - $params = []; - foreach ($component->getParameters() as $name => $value) { - $name = (string)$name; - if ($value === null || is_string($value)) { - $params[$name] = $value; - } else { - throw new ParameterNotStringException($name, get_debug_type($value)); - } - } - return $params; - } - -} diff --git a/app/src/Application/Exceptions/ParameterNotStringException.php b/app/src/Application/Exceptions/ParameterNotStringException.php deleted file mode 100644 index 6063d7f25..000000000 --- a/app/src/Application/Exceptions/ParameterNotStringException.php +++ /dev/null @@ -1,16 +0,0 @@ - $args + * @param array $args * @throws InvalidLinkException */ public function link(string $destination, array $args = [], ?NetteLinkGenerator $linkGenerator = null): string diff --git a/app/src/Application/Locale/LocaleLinkGenerator.php b/app/src/Application/Locale/LocaleLinkGenerator.php index 2c78a5b89..105599bf6 100644 --- a/app/src/Application/Locale/LocaleLinkGenerator.php +++ b/app/src/Application/Locale/LocaleLinkGenerator.php @@ -40,7 +40,7 @@ public function __construct( * Generates localized URLs. * * @param string $destination destination in format "[[[module:]presenter:]action] [#fragment]" - * @param array|array> $params of locale => [position|name => value] + * @param array|array> $params of locale => [position|name => value] * @return array of locale => URL * @throws InvalidLinkException */ @@ -70,8 +70,8 @@ public function links(string $destination, array $params = []): array /** * Return default params for all locales. * - * @param array $params - * @return array> + * @param array $params + * @return array> */ public function defaultParams(array $params): array { @@ -114,9 +114,9 @@ public function allLinks(string $destination, array $params = []): array /** - * @param array|array> $params + * @param array|array> $params * @param string $locale - * @return list|array + * @return list|array */ private function getParams(array $params, string $locale): array { diff --git a/app/src/Training/TrainingLocales.php b/app/src/Training/TrainingLocales.php index e674fe182..07965ad99 100644 --- a/app/src/Training/TrainingLocales.php +++ b/app/src/Training/TrainingLocales.php @@ -47,8 +47,8 @@ public function getLocaleActions(string $action): array /** * Translated locale parameters for trainings. * - * @param array $defaultParams - * @return array> + * @param array $defaultParams + * @return array> */ public function getLocaleLinkParams(?string $trainingAction, array $defaultParams): array { diff --git a/app/src/Www/Presenters/BasePresenter.php b/app/src/Www/Presenters/BasePresenter.php index 1a21ac210..c75e0ef23 100644 --- a/app/src/Www/Presenters/BasePresenter.php +++ b/app/src/Www/Presenters/BasePresenter.php @@ -4,8 +4,6 @@ namespace MichalSpacekCz\Www\Presenters; use DateTimeInterface; -use MichalSpacekCz\Application\ComponentParameters; -use MichalSpacekCz\Application\Exceptions\ParameterNotStringException; use MichalSpacekCz\Application\Locale\LocaleLink; use MichalSpacekCz\Application\Locale\LocaleLinkGenerator; use MichalSpacekCz\Css\CriticalCss; @@ -37,8 +35,6 @@ abstract class BasePresenter extends Presenter private CriticalCssFactory $criticalCssFactory; - private ComponentParameters $componentParameters; - private FourOhFourButFound $fourOhFourButFound; @@ -87,15 +83,6 @@ public function injectCriticalCssFactory(CriticalCssFactory $criticalCssFactory) } - /** - * @internal - */ - public function injectComponentParameters(ComponentParameters $componentParameters): void - { - $this->componentParameters = $componentParameters; - } - - /** * @internal */ @@ -117,9 +104,6 @@ protected function startup(): void } - /** - * @throws ParameterNotStringException - */ #[Override] public function beforeRender(): void { @@ -138,8 +122,7 @@ protected function getLocaleLinksGeneratorDestination(): string /** - * @return array> - * @throws ParameterNotStringException + * @return array> */ protected function getLocaleLinksGeneratorParams(): array { @@ -170,12 +153,11 @@ protected function getLocaleLinkAction(): string /** * Default parameters for locale links. * - * @return array> - * @throws ParameterNotStringException + * @return array> */ protected function getLocaleLinkParams(): array { - return $this->localeLinkGenerator->defaultParams($this->componentParameters->getStringParameters($this)); + return $this->localeLinkGenerator->defaultParams($this->getParameters()); } diff --git a/app/src/Www/Presenters/CompanyTrainingsPresenter.php b/app/src/Www/Presenters/CompanyTrainingsPresenter.php index 91e78f002..80df7422f 100644 --- a/app/src/Www/Presenters/CompanyTrainingsPresenter.php +++ b/app/src/Www/Presenters/CompanyTrainingsPresenter.php @@ -4,8 +4,6 @@ namespace MichalSpacekCz\Www\Presenters; use Contributte\Translation\Translator; -use MichalSpacekCz\Application\ComponentParameters; -use MichalSpacekCz\Application\Exceptions\ParameterNotStringException; use MichalSpacekCz\Formatter\TexyFormatter; use MichalSpacekCz\Training\Company\CompanyTrainings; use MichalSpacekCz\Training\Discontinued\DiscontinuedTrainings; @@ -32,7 +30,6 @@ public function __construct( private readonly TrainingReviews $trainingReviews, private readonly Prices $prices, private readonly Translator $translator, - private readonly ComponentParameters $componentParameters, ) { parent::__construct(); } @@ -72,13 +69,12 @@ public function actionTraining(string $name): void /** * Translated locale parameters for trainings. * - * @return array> - * @throws ParameterNotStringException + * @return array> */ #[Override] protected function getLocaleLinkParams(): array { - return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->componentParameters->getStringParameters($this)); + return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->getParameters()); } } diff --git a/app/src/Www/Presenters/ErrorPresenter.php b/app/src/Www/Presenters/ErrorPresenter.php index 022f08d43..db7b65175 100644 --- a/app/src/Www/Presenters/ErrorPresenter.php +++ b/app/src/Www/Presenters/ErrorPresenter.php @@ -6,7 +6,6 @@ use Contributte\Translation\Translator; use MichalSpacekCz\Application\AppRequest; use MichalSpacekCz\Application\Exceptions\NoOriginalRequestException; -use MichalSpacekCz\Application\Exceptions\ParameterNotStringException; use MichalSpacekCz\Application\Locale\LocaleLink; use MichalSpacekCz\Application\Locale\LocaleLinkGenerator; use MichalSpacekCz\ShouldNotHappenException; @@ -112,15 +111,14 @@ protected function getLocaleLinkAction(): string /** * Get original parameters for locale links. * - * @return array> + * @return array> * @throws NoOriginalRequestException - * @throws ParameterNotStringException */ #[Override] protected function getLocaleLinkParams(): array { - $params = $this->appRequest->getOriginalRequestStringParameters($this->getRequest()); - return $this->localeLinkGenerator->defaultParams($params); + $requestParam = $this->appRequest->getOriginalRequest($this->getRequest()); + return $this->localeLinkGenerator->defaultParams($requestParam->getParameters()); } } diff --git a/app/src/Www/Presenters/TrainingsPresenter.php b/app/src/Www/Presenters/TrainingsPresenter.php index 65afb4369..639277801 100644 --- a/app/src/Www/Presenters/TrainingsPresenter.php +++ b/app/src/Www/Presenters/TrainingsPresenter.php @@ -4,8 +4,6 @@ namespace MichalSpacekCz\Www\Presenters; use Contributte\Translation\Translator; -use MichalSpacekCz\Application\ComponentParameters; -use MichalSpacekCz\Application\Exceptions\ParameterNotStringException; use MichalSpacekCz\CompanyInfo\CompanyInfo; use MichalSpacekCz\Form\TrainingApplicationFormFactory; use MichalSpacekCz\Form\TrainingApplicationPreliminaryFormFactory; @@ -66,7 +64,6 @@ public function __construct( private readonly Translator $translator, private readonly Session $sessionHandler, private readonly Robots $robots, - private readonly ComponentParameters $componentParameters, ) { parent::__construct(); } @@ -308,13 +305,12 @@ protected function createComponentOtherUpcomingDatesList(): UpcomingTrainingDate /** * Translated locale parameters for trainings. * - * @return array> - * @throws ParameterNotStringException + * @return array> */ #[Override] protected function getLocaleLinkParams(): array { - return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->componentParameters->getStringParameters($this)); + return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->getParameters()); } diff --git a/app/tests/Application/AppRequestTest.phpt b/app/tests/Application/AppRequestTest.phpt index c4908f5b6..780dabfa3 100644 --- a/app/tests/Application/AppRequestTest.phpt +++ b/app/tests/Application/AppRequestTest.phpt @@ -8,7 +8,6 @@ use DateTime; use Error; use Exception; use MichalSpacekCz\Application\Exceptions\NoOriginalRequestException; -use MichalSpacekCz\Application\Exceptions\ParameterNotStringException; use MichalSpacekCz\ShouldNotHappenException; use MichalSpacekCz\Test\TestCaseRunner; use Nette\Application\Request; @@ -64,26 +63,6 @@ class AppRequestTest extends TestCase } - public function testGetOriginalRequestStringParameters(): void - { - $original = new Request('bar', params: ['foo' => 'bar', 1 => 'one']); - $request = new Request('foo'); - $request->setParameters(['request' => $original]); - Assert::same(['foo' => 'bar', '1' => 'one'], $this->appRequest->getOriginalRequestStringParameters($request)); - } - - - public function testGetOriginalRequestStringParametersException(): void - { - $original = new Request('bar', params: ['foo' => 'bar', 'one' => 1]); - $request = new Request('foo'); - $request->setParameters(['request' => $original]); - Assert::exception(function () use ($request): void { - $this->appRequest->getOriginalRequestStringParameters($request); - }, ParameterNotStringException::class, "Component parameter 'one' is not a string but it's a int"); - } - - public function testGetExceptionNoException(): void { Assert::exception(function (): void { diff --git a/app/tests/Application/ComponentParametersTest.phpt b/app/tests/Application/ComponentParametersTest.phpt deleted file mode 100644 index ee9a441b6..000000000 --- a/app/tests/Application/ComponentParametersTest.phpt +++ /dev/null @@ -1,46 +0,0 @@ -component = new class extends Component { - }; - } - - - public function testGetStringParameters(): void - { - $this->component->loadState([]); - Assert::same([], $this->componentParameters->getStringParameters($this->component)); - - $this->component->loadState(['foo' => 'bar', 'baz' => 'quux', 1 => 'one']); - Assert::same(['foo' => 'bar', 'baz' => 'quux', '1' => 'one'], $this->componentParameters->getStringParameters($this->component)); - - $this->component->loadState(['foo' => 'bar', 'number' => 1, 'baz' => 'quux']); - Assert::exception(function (): void { - $this->componentParameters->getStringParameters($this->component); - }, ParameterNotStringException::class, "Component parameter 'number' is not a string but it's a int"); - } - -} - -TestCaseRunner::run(ComponentParametersTest::class);