Skip to content

Commit f3ff675

Browse files
committed
Revert "Ensure presenter action parameters are strings"
This reverts commit e297212.
1 parent fdb8784 commit f3ff675

File tree

10 files changed

+5
-168
lines changed

10 files changed

+5
-168
lines changed

app/config/services.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ services:
33
cliArgs:
44
type: MichalSpacekCz\Application\Cli\CliArgs
55
imported: true
6-
- MichalSpacekCz\Application\ComponentParameters
76
- MichalSpacekCz\Application\Error
87
- MichalSpacekCz\Application\LinkGenerator
98
localeLinkGenerator: MichalSpacekCz\Application\Locale\LocaleLinkGenerator(languages: %locales.languages%)

app/src/Application/AppRequest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace MichalSpacekCz\Application;
55

66
use MichalSpacekCz\Application\Exceptions\NoOriginalRequestException;
7-
use MichalSpacekCz\Application\Exceptions\ParameterNotStringException;
87
use MichalSpacekCz\ShouldNotHappenException;
98
use Nette\Application\Request;
109
use Throwable;
@@ -28,26 +27,6 @@ public function getOriginalRequest(?Request $request): Request
2827
}
2928

3029

31-
/**
32-
* @return array<string, string|null>
33-
* @throws NoOriginalRequestException
34-
* @throws ParameterNotStringException
35-
*/
36-
public function getOriginalRequestStringParameters(?Request $request): array
37-
{
38-
$params = [];
39-
foreach ($this->getOriginalRequest($request)->getParameters() as $name => $value) {
40-
$name = (string)$name;
41-
if ($value === null || is_string($value)) {
42-
$params[$name] = $value;
43-
} else {
44-
throw new ParameterNotStringException($name, get_debug_type($value));
45-
}
46-
}
47-
return $params;
48-
}
49-
50-
5130
public function getException(Request $request): Throwable
5231
{
5332
$e = $request->getParameter('exception');

app/src/Application/ComponentParameters.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/src/Application/Exceptions/ParameterNotStringException.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/src/Www/Presenters/BasePresenter.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace MichalSpacekCz\Www\Presenters;
55

66
use DateTimeInterface;
7-
use MichalSpacekCz\Application\ComponentParameters;
8-
use MichalSpacekCz\Application\Exceptions\ParameterNotStringException;
97
use MichalSpacekCz\Application\Locale\LocaleLink;
108
use MichalSpacekCz\Application\Locale\LocaleLinkGenerator;
119
use MichalSpacekCz\Css\CriticalCss;
@@ -37,8 +35,6 @@ abstract class BasePresenter extends Presenter
3735

3836
private CriticalCssFactory $criticalCssFactory;
3937

40-
private ComponentParameters $componentParameters;
41-
4238
private FourOhFourButFound $fourOhFourButFound;
4339

4440

@@ -87,15 +83,6 @@ public function injectCriticalCssFactory(CriticalCssFactory $criticalCssFactory)
8783
}
8884

8985

90-
/**
91-
* @internal
92-
*/
93-
public function injectComponentParameters(ComponentParameters $componentParameters): void
94-
{
95-
$this->componentParameters = $componentParameters;
96-
}
97-
98-
9986
/**
10087
* @internal
10188
*/
@@ -117,9 +104,6 @@ protected function startup(): void
117104
}
118105

119106

120-
/**
121-
* @throws ParameterNotStringException
122-
*/
123107
#[Override]
124108
public function beforeRender(): void
125109
{
@@ -139,7 +123,6 @@ protected function getLocaleLinksGeneratorDestination(): string
139123

140124
/**
141125
* @return array<string, array<string, string|null>>
142-
* @throws ParameterNotStringException
143126
*/
144127
protected function getLocaleLinksGeneratorParams(): array
145128
{
@@ -171,11 +154,10 @@ protected function getLocaleLinkAction(): string
171154
* Default parameters for locale links.
172155
*
173156
* @return array<string, array<string, string|null>>
174-
* @throws ParameterNotStringException
175157
*/
176158
protected function getLocaleLinkParams(): array
177159
{
178-
return $this->localeLinkGenerator->defaultParams($this->componentParameters->getStringParameters($this));
160+
return $this->localeLinkGenerator->defaultParams($this->getParameters());
179161
}
180162

181163

app/src/Www/Presenters/CompanyTrainingsPresenter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace MichalSpacekCz\Www\Presenters;
55

66
use Contributte\Translation\Translator;
7-
use MichalSpacekCz\Application\ComponentParameters;
8-
use MichalSpacekCz\Application\Exceptions\ParameterNotStringException;
97
use MichalSpacekCz\Formatter\TexyFormatter;
108
use MichalSpacekCz\Training\Company\CompanyTrainings;
119
use MichalSpacekCz\Training\Discontinued\DiscontinuedTrainings;
@@ -32,7 +30,6 @@ public function __construct(
3230
private readonly TrainingReviews $trainingReviews,
3331
private readonly Prices $prices,
3432
private readonly Translator $translator,
35-
private readonly ComponentParameters $componentParameters,
3633
) {
3734
parent::__construct();
3835
}
@@ -73,12 +70,11 @@ public function actionTraining(string $name): void
7370
* Translated locale parameters for trainings.
7471
*
7572
* @return array<string, array<string, string|null>>
76-
* @throws ParameterNotStringException
7773
*/
7874
#[Override]
7975
protected function getLocaleLinkParams(): array
8076
{
81-
return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->componentParameters->getStringParameters($this));
77+
return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->getParameters());
8278
}
8379

8480
}

app/src/Www/Presenters/ErrorPresenter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Contributte\Translation\Translator;
77
use MichalSpacekCz\Application\AppRequest;
88
use MichalSpacekCz\Application\Exceptions\NoOriginalRequestException;
9-
use MichalSpacekCz\Application\Exceptions\ParameterNotStringException;
109
use MichalSpacekCz\Application\Locale\LocaleLink;
1110
use MichalSpacekCz\Application\Locale\LocaleLinkGenerator;
1211
use MichalSpacekCz\ShouldNotHappenException;
@@ -114,13 +113,12 @@ protected function getLocaleLinkAction(): string
114113
*
115114
* @return array<string, array<string, string|null>>
116115
* @throws NoOriginalRequestException
117-
* @throws ParameterNotStringException
118116
*/
119117
#[Override]
120118
protected function getLocaleLinkParams(): array
121119
{
122-
$params = $this->appRequest->getOriginalRequestStringParameters($this->getRequest());
123-
return $this->localeLinkGenerator->defaultParams($params);
120+
$requestParam = $this->appRequest->getOriginalRequest($this->getRequest());
121+
return $this->localeLinkGenerator->defaultParams($requestParam->getParameters());
124122
}
125123

126124
}

app/src/Www/Presenters/TrainingsPresenter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace MichalSpacekCz\Www\Presenters;
55

66
use Contributte\Translation\Translator;
7-
use MichalSpacekCz\Application\ComponentParameters;
8-
use MichalSpacekCz\Application\Exceptions\ParameterNotStringException;
97
use MichalSpacekCz\CompanyInfo\CompanyInfo;
108
use MichalSpacekCz\Form\TrainingApplicationFormFactory;
119
use MichalSpacekCz\Form\TrainingApplicationPreliminaryFormFactory;
@@ -66,7 +64,6 @@ public function __construct(
6664
private readonly Translator $translator,
6765
private readonly Session $sessionHandler,
6866
private readonly Robots $robots,
69-
private readonly ComponentParameters $componentParameters,
7067
) {
7168
parent::__construct();
7269
}
@@ -309,12 +306,11 @@ protected function createComponentOtherUpcomingDatesList(): UpcomingTrainingDate
309306
* Translated locale parameters for trainings.
310307
*
311308
* @return array<string, array<string, string|null>>
312-
* @throws ParameterNotStringException
313309
*/
314310
#[Override]
315311
protected function getLocaleLinkParams(): array
316312
{
317-
return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->componentParameters->getStringParameters($this));
313+
return $this->trainingLocales->getLocaleLinkParams($this->trainingAction, $this->getParameters());
318314
}
319315

320316

app/tests/Application/AppRequestTest.phpt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use DateTime;
88
use Error;
99
use Exception;
1010
use MichalSpacekCz\Application\Exceptions\NoOriginalRequestException;
11-
use MichalSpacekCz\Application\Exceptions\ParameterNotStringException;
1211
use MichalSpacekCz\ShouldNotHappenException;
1312
use MichalSpacekCz\Test\TestCaseRunner;
1413
use Nette\Application\Request;
@@ -64,26 +63,6 @@ class AppRequestTest extends TestCase
6463
}
6564

6665

67-
public function testGetOriginalRequestStringParameters(): void
68-
{
69-
$original = new Request('bar', params: ['foo' => 'bar', 1 => 'one']);
70-
$request = new Request('foo');
71-
$request->setParameters(['request' => $original]);
72-
Assert::same(['foo' => 'bar', '1' => 'one'], $this->appRequest->getOriginalRequestStringParameters($request));
73-
}
74-
75-
76-
public function testGetOriginalRequestStringParametersException(): void
77-
{
78-
$original = new Request('bar', params: ['foo' => 'bar', 'one' => 1]);
79-
$request = new Request('foo');
80-
$request->setParameters(['request' => $original]);
81-
Assert::exception(function () use ($request): void {
82-
$this->appRequest->getOriginalRequestStringParameters($request);
83-
}, ParameterNotStringException::class, "Component parameter 'one' is not a string but it's a int");
84-
}
85-
86-
8766
public function testGetExceptionNoException(): void
8867
{
8968
Assert::exception(function (): void {

app/tests/Application/ComponentParametersTest.phpt

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)