Skip to content

Commit 73391b9

Browse files
committed
constants are PascalCase
1 parent 2c0820a commit 73391b9

15 files changed

+97
-87
lines changed

src/Application/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function run(): void
112112
public function createInitialRequest(): Request
113113
{
114114
$params = $this->router->match($this->httpRequest);
115-
$presenter = $params[UI\Presenter::PRESENTER_KEY] ?? null;
115+
$presenter = $params[UI\Presenter::PresenterKey] ?? null;
116116

117117
if ($params === null) {
118118
throw new BadRequestException('No route for HTTP request.');
@@ -122,7 +122,7 @@ public function createInitialRequest(): Request
122122
throw new BadRequestException('Invalid request. Presenter is not achievable.');
123123
}
124124

125-
unset($params[UI\Presenter::PRESENTER_KEY]);
125+
unset($params[UI\Presenter::PresenterKey]);
126126
return new Request(
127127
$presenter,
128128
$this->httpRequest->getMethod(),

src/Application/LinkGenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function link(string $dest, array $params = []): string
6262

6363
if (is_subclass_of($class, UI\Presenter::class)) {
6464
if ($action === '') {
65-
$action = UI\Presenter::DEFAULT_ACTION;
65+
$action = UI\Presenter::DefaultAction;
6666
}
6767

6868
if (
@@ -80,14 +80,14 @@ public function link(string $dest, array $params = []): string
8080
}
8181

8282
if ($action !== '') {
83-
$params[UI\Presenter::ACTION_KEY] = $action;
83+
$params[UI\Presenter::ActionKey] = $action;
8484
}
8585

86-
$params[UI\Presenter::PRESENTER_KEY] = $presenter;
86+
$params[UI\Presenter::PresenterKey] = $presenter;
8787

8888
$url = $this->router->constructUrl($params, $this->refUrl);
8989
if ($url === null) {
90-
unset($params[UI\Presenter::ACTION_KEY], $params[UI\Presenter::PRESENTER_KEY]);
90+
unset($params[UI\Presenter::ActionKey], $params[UI\Presenter::PresenterKey]);
9191
$paramsDecoded = urldecode(http_build_query($params, '', ', '));
9292
throw new UI\InvalidLinkException("No route for $dest($paramsDecoded)");
9393
}

src/Application/Routers/SimpleRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct($defaults = [], int $flags = 0)
3636

3737
$defaults = [
3838
self::PresenterKey => $presenter,
39-
'action' => $action === '' ? Application\UI\Presenter::DEFAULT_ACTION : $action,
39+
'action' => $action === '' ? Application\UI\Presenter::DefaultAction : $action,
4040
];
4141
}
4242

src/Application/UI/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function receiveHttpData(): ?array
142142
protected function beforeRender()
143143
{
144144
parent::beforeRender();
145-
$key = ($this->isMethod('post') ? '_' : '') . Presenter::SIGNAL_KEY;
145+
$key = ($this->isMethod('post') ? '_' : '') . Presenter::SignalKey;
146146
if (!isset($this[$key])) {
147147
$do = $this->lookupPath(Presenter::class) . self::NAME_SEPARATOR . 'submit';
148148
$this[$key] = (new Nette\Forms\Controls\HiddenField($do))->setOmitted();

src/Application/UI/Presenter.php

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,28 @@ abstract class Presenter extends Control implements Application\IPresenter
3333
{
3434
/** bad link handling {@link Presenter::$invalidLinkMode} */
3535
public const
36-
INVALID_LINK_SILENT = 0b0000,
37-
INVALID_LINK_WARNING = 0b0001,
38-
INVALID_LINK_EXCEPTION = 0b0010,
39-
INVALID_LINK_TEXTUAL = 0b0100;
36+
InvalidLinkSilent = 0b0000,
37+
InvalidLinkWarning = 0b0001,
38+
InvalidLinkException = 0b0010,
39+
InvalidLinkTextual = 0b0100;
4040

4141
/** @internal special parameter key */
4242
public const
43-
PRESENTER_KEY = 'presenter',
44-
SIGNAL_KEY = 'do',
45-
ACTION_KEY = 'action',
46-
FLASH_KEY = '_fid',
47-
DEFAULT_ACTION = 'default';
43+
PresenterKey = 'presenter',
44+
SignalKey = 'do',
45+
ActionKey = 'action',
46+
FlashKey = '_fid',
47+
DefaultAction = 'default';
48+
49+
public const INVALID_LINK_SILENT = self::InvalidLinkSilent;
50+
public const INVALID_LINK_WARNING = self::InvalidLinkWarning;
51+
public const INVALID_LINK_EXCEPTION = self::InvalidLinkException;
52+
public const INVALID_LINK_TEXTUAL = self::InvalidLinkTextual;
53+
public const PRESENTER_KEY = self::PresenterKey;
54+
public const SIGNAL_KEY = self::SignalKey;
55+
public const ACTION_KEY = self::ActionKey;
56+
public const FLASH_KEY = self::FlashKey;
57+
public const DEFAULT_ACTION = self::DefaultAction;
4858

4959
/** @var int */
5060
public $invalidLinkMode;
@@ -879,7 +889,7 @@ protected function createRequest(
879889
// PROCESS ARGUMENTS
880890
if (is_subclass_of($presenterClass, self::class)) {
881891
if ($action === '') {
882-
$action = self::DEFAULT_ACTION;
892+
$action = self::DefaultAction;
883893
}
884894

885895
$current = ($action === '*' || strcasecmp($action, (string) $this->action) === 0) && $presenterClass === static::class;
@@ -947,16 +957,16 @@ protected function createRequest(
947957

948958
// ADD ACTION & SIGNAL & FLASH
949959
if ($action) {
950-
$args[self::ACTION_KEY] = $action;
960+
$args[self::ActionKey] = $action;
951961
}
952962

953963
if (!empty($signal)) {
954-
$args[self::SIGNAL_KEY] = $component->getParameterId($signal);
955-
$current = $current && $args[self::SIGNAL_KEY] === $this->getParameter(self::SIGNAL_KEY);
964+
$args[self::SignalKey] = $component->getParameterId($signal);
965+
$current = $current && $args[self::SignalKey] === $this->getParameter(self::SignalKey);
956966
}
957967

958968
if (($mode === 'redirect' || $mode === 'forward') && $this->hasFlashSession()) {
959-
$args[self::FLASH_KEY] = $this->getFlashKey();
969+
$args[self::FlashKey] = $this->getFlashKey();
960970
}
961971

962972
$this->lastCreatedRequest = new Application\Request($presenter, Application\Request::FORWARD, $args);
@@ -1011,7 +1021,7 @@ protected function requestToUrl(Application\Request $request, ?bool $relative =
10111021
$url = $this->router->constructUrl($request->toArray(), $this->refUrlCache);
10121022
if ($url === null) {
10131023
$params = $request->getParameters();
1014-
unset($params[self::ACTION_KEY], $params[self::PRESENTER_KEY]);
1024+
unset($params[self::ActionKey], $params[self::PresenterKey]);
10151025
$params = urldecode(http_build_query($params, '', ', '));
10161026
throw new InvalidLinkException("No route for {$request->getPresenterName()}:{$request->getParameter('action')}($params)");
10171027
}
@@ -1104,13 +1114,13 @@ public static function argsToParams(
11041114
*/
11051115
protected function handleInvalidLink(InvalidLinkException $e): string
11061116
{
1107-
if ($this->invalidLinkMode & self::INVALID_LINK_EXCEPTION) {
1117+
if ($this->invalidLinkMode & self::InvalidLinkException) {
11081118
throw $e;
1109-
} elseif ($this->invalidLinkMode & self::INVALID_LINK_WARNING) {
1119+
} elseif ($this->invalidLinkMode & self::InvalidLinkWarning) {
11101120
trigger_error('Invalid link: ' . $e->getMessage(), E_USER_WARNING);
11111121
}
11121122

1113-
return $this->invalidLinkMode & self::INVALID_LINK_TEXTUAL
1123+
return $this->invalidLinkMode & self::InvalidLinkTextual
11141124
? '#error: ' . $e->getMessage()
11151125
: '#';
11161126
}
@@ -1149,7 +1159,7 @@ public function restoreRequest(string $key): void
11491159
$request = clone $session[$key][1];
11501160
unset($session[$key]);
11511161
$params = $request->getParameters();
1152-
$params[self::FLASH_KEY] = $this->getFlashKey();
1162+
$params[self::FlashKey] = $this->getFlashKey();
11531163
$request->setParameters($params);
11541164
if ($request->isMethod('POST')) {
11551165
$request->setFlag(Application\Request::RESTORED, true);
@@ -1284,12 +1294,12 @@ private function initGlobalParameters(): void
12841294
$selfParams = [];
12851295

12861296
$params = $this->request->getParameters();
1287-
if (($tmp = $this->request->getPost('_' . self::SIGNAL_KEY)) !== null) {
1288-
$params[self::SIGNAL_KEY] = $tmp;
1297+
if (($tmp = $this->request->getPost('_' . self::SignalKey)) !== null) {
1298+
$params[self::SignalKey] = $tmp;
12891299
} elseif ($this->isAjax()) {
12901300
$params += $this->request->getPost();
1291-
if (($tmp = $this->request->getPost(self::SIGNAL_KEY)) !== null) {
1292-
$params[self::SIGNAL_KEY] = $tmp;
1301+
if (($tmp = $this->request->getPost(self::SignalKey)) !== null) {
1302+
$params[self::SignalKey] = $tmp;
12931303
}
12941304
}
12951305

@@ -1304,7 +1314,7 @@ private function initGlobalParameters(): void
13041314
}
13051315

13061316
// init & validate $this->action & $this->view
1307-
$action = $selfParams[self::ACTION_KEY] ?? self::DEFAULT_ACTION;
1317+
$action = $selfParams[self::ActionKey] ?? self::DefaultAction;
13081318
if (!is_string($action) || !Nette\Utils\Strings::match($action, '#^[a-zA-Z0-9][a-zA-Z0-9_\x7f-\xff]*$#D')) {
13091319
$this->error('Action name is not valid.');
13101320
}
@@ -1313,8 +1323,8 @@ private function initGlobalParameters(): void
13131323

13141324
// init $this->signalReceiver and key 'signal' in appropriate params array
13151325
$this->signalReceiver = $this->getUniqueId();
1316-
if (isset($selfParams[self::SIGNAL_KEY])) {
1317-
$param = $selfParams[self::SIGNAL_KEY];
1326+
if (isset($selfParams[self::SignalKey])) {
1327+
$param = $selfParams[self::SignalKey];
13181328
if (!is_string($param)) {
13191329
$this->error('Signal name is not string.');
13201330
}
@@ -1354,7 +1364,7 @@ final public function popGlobalParameters(string $id): array
13541364

13551365
private function getFlashKey(): ?string
13561366
{
1357-
$flashKey = $this->getParameter(self::FLASH_KEY);
1367+
$flashKey = $this->getParameter(self::FlashKey);
13581368
return is_string($flashKey) && $flashKey !== ''
13591369
? $flashKey
13601370
: null;
@@ -1379,7 +1389,7 @@ public function getFlashSession(): Http\SessionSection
13791389
{
13801390
$flashKey = $this->getFlashKey();
13811391
if ($flashKey === null) {
1382-
$this->params[self::FLASH_KEY] = $flashKey = Nette\Utils\Random::generate(4);
1392+
$this->params[self::FlashKey] = $flashKey = Nette\Utils\Random::generate(4);
13831393
}
13841394

13851395
return $this->getSession('Nette.Application.Flash/' . $flashKey);

src/Bridges/ApplicationDI/ApplicationExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public function loadConfiguration()
7676
$builder->addExcludedClasses([UI\Presenter::class]);
7777

7878
$this->invalidLinkMode = $this->debugMode
79-
? UI\Presenter::INVALID_LINK_TEXTUAL | ($config->silentLinks ? 0 : UI\Presenter::INVALID_LINK_WARNING)
80-
: UI\Presenter::INVALID_LINK_WARNING;
79+
? UI\Presenter::InvalidLinkTextual | ($config->silentLinks ? 0 : UI\Presenter::InvalidLinkWarning)
80+
: UI\Presenter::InvalidLinkWarning;
8181

8282
$builder->addDefinition($this->prefix('application'))
8383
->setFactory(Nette\Application\Application::class)

src/Bridges/ApplicationTracy/RoutingPanel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ private function findSource(): void
180180
$rc = new \ReflectionClass($class);
181181

182182
if ($rc->isSubclassOf(Nette\Application\UI\Presenter::class)) {
183-
if (isset($params[Presenter::SIGNAL_KEY])) {
184-
$method = $class::formatSignalMethod($params[Presenter::SIGNAL_KEY]);
183+
if (isset($params[Presenter::SignalKey])) {
184+
$method = $class::formatSignalMethod($params[Presenter::SignalKey]);
185185

186-
} elseif (isset($params[Presenter::ACTION_KEY])) {
187-
$action = $params[Presenter::ACTION_KEY];
186+
} elseif (isset($params[Presenter::ActionKey])) {
187+
$action = $params[Presenter::ActionKey];
188188
$method = $class::formatActionMethod($action);
189189
if (!$rc->hasMethod($method)) {
190190
$method = $class::formatRenderMethod($action);

src/Bridges/ApplicationTracy/templates/RoutingPanel.panel.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ use Tracy\Helpers;
5656
<h1>
5757
<?php if ($matched === null): ?>
5858
no route
59-
<?php elseif (isset($matched[Presenter::PRESENTER_KEY])): ?>
60-
<?= Helpers::escapeHtml($matched[Presenter::PRESENTER_KEY] . ':' . (isset($matched[Presenter::ACTION_KEY]) ? $matched[Presenter::ACTION_KEY] : Presenter::DEFAULT_ACTION) . (isset($matched[Presenter::SIGNAL_KEY]) ? " {$matched[Presenter::SIGNAL_KEY]}!" : '')) ?>
59+
<?php elseif (isset($matched[Presenter::PresenterKey])): ?>
60+
<?= Helpers::escapeHtml($matched[Presenter::PresenterKey] . ':' . (isset($matched[Presenter::ActionKey]) ? $matched[Presenter::ActionKey] : Presenter::DefaultAction) . (isset($matched[Presenter::SignalKey]) ? " {$matched[Presenter::SignalKey]}!" : '')) ?>
6161
<?php endif ?>
6262
</h1>
6363

@@ -99,9 +99,9 @@ use Tracy\Helpers;
9999

100100
<td><?php if ($router->params): ?><code>
101101
<?php $params = $router->params; ?>
102-
<?php if (isset($params[Presenter::PRESENTER_KEY])): ?>
103-
<strong><?= Helpers::escapeHtml($params['presenter'] . ':' . (isset($params[Presenter::ACTION_KEY]) ? $params[Presenter::ACTION_KEY] : Presenter::DEFAULT_ACTION)) ?></strong><br />
104-
<?php unset($params[Presenter::PRESENTER_KEY], $params[Presenter::ACTION_KEY]) ?>
102+
<?php if (isset($params[Presenter::PresenterKey])): ?>
103+
<strong><?= Helpers::escapeHtml($params['presenter'] . ':' . (isset($params[Presenter::ActionKey]) ? $params[Presenter::ActionKey] : Presenter::DefaultAction)) ?></strong><br />
104+
<?php unset($params[Presenter::PresenterKey], $params[Presenter::ActionKey]) ?>
105105
<?php endif ?>
106106
<?php foreach ($params as $key => $value): ?>
107107
<?= Helpers::escapeHtml($key), '&nbsp;=&nbsp;', is_string($value) ? Helpers::escapeHtml($value) . '<br />' : Dumper::toHtml($value, [Dumper::COLLAPSE => true, Dumper::LIVE => true]) ?>

src/Bridges/ApplicationTracy/templates/RoutingPanel.tab.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ use Tracy\Helpers;
1111
<svg viewBox="0 0 2048 2048">
1212
<path fill="#d86b01" d="m1559.7 1024c0 17-6 32-19 45l-670 694.48c-13 13-28 19-45 19s-32-6-45-19-19-28-19-45v-306.48h-438.52c-17 0-32-6-45-19s-19-28-19-45v-642c0-17 6-32 19-45s28-19 45-19h438.52v-309.41c0-17 6-32 19-45s28-19 45-19 32 6 45 19l670 691.41c13 13 19 28 19 45z"/>
1313
<path d="m1914.7 1505c0 79-31 147-87 204-56 56-124 85-203 85h-320c-9 0-16-3-22-9-14-23-21-90 3-110 5-4 12-6 21-6h320c44 0 82-16 113-47s47-69 47-113v-962c0-44-16-82-47-113s-69-47-113-47h-312c-11 0-21-3-30-9-15-25-21-90 3-110 5-4 12-6 21-6h320c79 0 147 28 204 85 56 56 82 124 82 204-9 272 9 649 0 954z" fill-opacity=".5" fill="#d86b01"/>
14-
</svg><span class="tracy-label"><?php if ($matched === null): ?>no route<?php elseif (isset($matched[Presenter::PRESENTER_KEY])): echo Helpers::escapeHtml($matched[Presenter::PRESENTER_KEY] . ':' . (isset($matched[Presenter::ACTION_KEY]) ? $matched[Presenter::ACTION_KEY] : Presenter::DEFAULT_ACTION) . (isset($matched[Presenter::SIGNAL_KEY]) ? " {$matched[Presenter::SIGNAL_KEY]}!" : '')); endif ?></span>
14+
</svg><span class="tracy-label"><?php if ($matched === null): ?>no route<?php elseif (isset($matched[Presenter::PresenterKey])): echo Helpers::escapeHtml($matched[Presenter::PresenterKey] . ':' . (isset($matched[Presenter::ActionKey]) ? $matched[Presenter::ActionKey] : Presenter::DefaultAction) . (isset($matched[Presenter::SignalKey]) ? " {$matched[Presenter::SignalKey]}!" : '')); endif ?></span>
1515
</span>

tests/Bridges.DI/ApplicationExtension.invalidLink.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test('', function () {
3838

3939
$container = new Container4;
4040
Assert::same(
41-
Presenter::INVALID_LINK_TEXTUAL,
41+
Presenter::InvalidLinkTextual,
4242
$container->getService('presenter')->invalidLinkMode
4343
);
4444
});
@@ -58,7 +58,7 @@ test('', function () {
5858

5959
$container = new Container5;
6060
Assert::same(
61-
Presenter::INVALID_LINK_WARNING | Presenter::INVALID_LINK_TEXTUAL,
61+
Presenter::InvalidLinkWarning | Presenter::InvalidLinkTextual,
6262
$container->getService('presenter')->invalidLinkMode
6363
);
6464
});
@@ -78,7 +78,7 @@ test('', function () {
7878

7979
$container = new Container6;
8080
Assert::same(
81-
Presenter::INVALID_LINK_WARNING,
81+
Presenter::InvalidLinkWarning,
8282
$container->getService('presenter')->invalidLinkMode
8383
);
8484
});
@@ -98,7 +98,7 @@ test('', function () {
9898

9999
$container = new Container7;
100100
Assert::same(
101-
Presenter::INVALID_LINK_WARNING,
101+
Presenter::InvalidLinkWarning,
102102
$container->getService('presenter')->invalidLinkMode
103103
);
104104
});

0 commit comments

Comments
 (0)