From 3c82c5fccca1018715fee86747b744879929231f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barto=C5=A1?= Date: Sat, 25 May 2024 20:43:17 +0200 Subject: [PATCH] Fix Nette deprecations --- composer.json | 14 +++---- src/UI/Control/BaseControl.php | 4 +- src/UI/DataGrid/DataGrid.php | 5 ++- src/UI/Form/Form.php | 2 +- src/UI/Form/FormFactory.php | 40 +++++++++---------- src/UI/Presenter/BasePresenter.php | 4 +- src/UI/Routing/ClassRoute.php | 6 +-- .../Locator/PresenterTemplateLocator.php | 4 +- 8 files changed, 41 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 343e8f8..998a82f 100644 --- a/composer.json +++ b/composer.json @@ -36,13 +36,13 @@ "league/mime-type-detection": "^1.11.0", "monolog/monolog": "^3.2.0", "nette/application": "^3.1.8", - "nette/di": "^3.0.14", - "nette/forms": "^3.1.8", - "nette/http": "^3.2.1", - "nette/neon": "^3.3.3", - "nette/php-generator": "^4.0.5", - "nette/schema": "^1.2.3", - "nette/utils": "^3.2.8|^4.0.0", + "nette/di": "^3.1.7", + "nette/forms": "^3.1.12", + "nette/http": "^3.2.2", + "nette/neon": "^3.4.1", + "nette/php-generator": "^4.1.1", + "nette/schema": "^1.2.5", + "nette/utils": "^3.2.8|^4.0.2", "nextras/dbal": "~4.0.5", "nextras/migrations": "~3.2.0", "nextras/orm": "~4.0.7", diff --git a/src/UI/Control/BaseControl.php b/src/UI/Control/BaseControl.php index 09ce19f..3c4b3d4 100644 --- a/src/UI/Control/BaseControl.php +++ b/src/UI/Control/BaseControl.php @@ -36,10 +36,10 @@ protected function getFirewall(): BaseUIFirewall return $this->firewall ??= $this->getPresenter()->getFirewall(); } - protected function createTemplate(): BaseControlTemplate + protected function createTemplate(string|null $class = null): BaseControlTemplate { $templateFactory = $this->getPresenter()->getTemplateFactory(); - $template = $templateFactory->createTemplate($this, $this->formatTemplateClass()); + $template = $templateFactory->createTemplate($this, $class ?? $this->formatTemplateClass()); assert($template instanceof BaseControlTemplate); $template->firewall = $this->getFirewall(); diff --git a/src/UI/DataGrid/DataGrid.php b/src/UI/DataGrid/DataGrid.php index 6bb58fa..45b6c88 100644 --- a/src/UI/DataGrid/DataGrid.php +++ b/src/UI/DataGrid/DataGrid.php @@ -345,7 +345,10 @@ private function processForm(Form $form): void $rows[] = $this->getCellValue($row, $rowPrimaryKey); } - $ids = array_intersect($rows, $form->getHttpData($form::DATA_TEXT, 'actions[items][]')); + $httpData = $form->getHttpData($form::DataText, 'actions[items][]'); + assert(is_array($httpData)); + + $ids = array_intersect($rows, $httpData); [, $callback] = $this->globalActions[$action]; $callback($ids, $this); $this->data = null; diff --git a/src/UI/Form/Form.php b/src/UI/Form/Form.php index 5568c2f..f41ecde 100644 --- a/src/UI/Form/Form.php +++ b/src/UI/Form/Form.php @@ -14,7 +14,7 @@ class Form extends NetteForm * @deprecated Translate values passed into form directly instead * @internal */ - public function setTranslator(Translator|null $translator = null): self + public function setTranslator(Translator|null $translator = null): static { throw Deprecated::create() ->withMessage('Do not use form built-in translator, translate values passed into form directly.'); diff --git a/src/UI/Form/FormFactory.php b/src/UI/Form/FormFactory.php index 52951c8..fc420ce 100644 --- a/src/UI/Form/FormFactory.php +++ b/src/UI/Form/FormFactory.php @@ -26,27 +26,27 @@ private function initialize(): void private function configureDefaultMessages(): void { - Validator::$messages[NForm::EQUAL] = t('ori.cmf.ui.forms.equal'); - Validator::$messages[NForm::NOT_EQUAL] = t('ori.cmf.ui.forms.notEqual'); - Validator::$messages[NForm::FILLED] = t('ori.cmf.ui.forms.filled'); - Validator::$messages[NForm::BLANK] = t('ori.cmf.ui.forms.blank'); - Validator::$messages[NForm::MIN_LENGTH] = t('ori.cmf.ui.forms.minLength'); - Validator::$messages[NForm::MAX_LENGTH] = t('ori.cmf.ui.forms.maxLength'); - Validator::$messages[NForm::LENGTH] = t('ori.cmf.ui.forms.length'); - Validator::$messages[NForm::EMAIL] = t('ori.cmf.ui.forms.email'); + Validator::$messages[NForm::Equal] = t('ori.cmf.ui.forms.equal'); + Validator::$messages[NForm::NotEqual] = t('ori.cmf.ui.forms.notEqual'); + Validator::$messages[NForm::Filled] = t('ori.cmf.ui.forms.filled'); + Validator::$messages[NForm::Blank] = t('ori.cmf.ui.forms.blank'); + Validator::$messages[NForm::MinLength] = t('ori.cmf.ui.forms.minLength'); + Validator::$messages[NForm::MaxLength] = t('ori.cmf.ui.forms.maxLength'); + Validator::$messages[NForm::Length] = t('ori.cmf.ui.forms.length'); + Validator::$messages[NForm::Email] = t('ori.cmf.ui.forms.email'); Validator::$messages[NForm::URL] = t('ori.cmf.ui.forms.url'); - Validator::$messages[NForm::INTEGER] = t('ori.cmf.ui.forms.integer'); - Validator::$messages[NForm::FLOAT] = t('ori.cmf.ui.forms.number'); - Validator::$messages[NForm::NUMERIC] = t('ori.cmf.ui.forms.number'); - Validator::$messages[NForm::MIN] = t('ori.cmf.ui.forms.min'); - Validator::$messages[NForm::MAX] = t('ori.cmf.ui.forms.max'); - Validator::$messages[NForm::RANGE] = t('ori.cmf.ui.forms.range'); - Validator::$messages[NForm::MAX_FILE_SIZE] = t('ori.cmf.ui.forms.maxFileSize'); - Validator::$messages[NForm::MAX_POST_SIZE] = t('ori.cmf.ui.forms.maxPostSize'); - Validator::$messages[NForm::MIME_TYPE] = t('ori.cmf.ui.forms.mimeType'); - Validator::$messages[NForm::IMAGE] = t('ori.cmf.ui.forms.image'); - Validator::$messages[SelectBox::VALID] = t('ori.cmf.ui.forms.select'); - Validator::$messages[UploadControl::VALID] = t('ori.cmf.ui.forms.upload'); + Validator::$messages[NForm::Integer] = t('ori.cmf.ui.forms.integer'); + Validator::$messages[NForm::Float] = t('ori.cmf.ui.forms.number'); + Validator::$messages[NForm::Numeric] = t('ori.cmf.ui.forms.number'); + Validator::$messages[NForm::Min] = t('ori.cmf.ui.forms.min'); + Validator::$messages[NForm::Max] = t('ori.cmf.ui.forms.max'); + Validator::$messages[NForm::Range] = t('ori.cmf.ui.forms.range'); + Validator::$messages[NForm::MaxFileSize] = t('ori.cmf.ui.forms.maxFileSize'); + Validator::$messages[NForm::MaxPostSize] = t('ori.cmf.ui.forms.maxPostSize'); + Validator::$messages[NForm::MimeType] = t('ori.cmf.ui.forms.mimeType'); + Validator::$messages[NForm::Image] = t('ori.cmf.ui.forms.image'); + Validator::$messages[SelectBox::Valid] = t('ori.cmf.ui.forms.select'); + Validator::$messages[UploadControl::Valid] = t('ori.cmf.ui.forms.upload'); } public function create(): Form diff --git a/src/UI/Presenter/BasePresenter.php b/src/UI/Presenter/BasePresenter.php index 2c14617..0f007cc 100644 --- a/src/UI/Presenter/BasePresenter.php +++ b/src/UI/Presenter/BasePresenter.php @@ -124,10 +124,10 @@ protected function linkToAction(ActionLink|HandleLink $link): string return $this->link($link->getDestination(), $link->getArguments()); } - protected function createTemplate(): BasePresenterTemplate + protected function createTemplate(string|null $class = null): BasePresenterTemplate { $templateFactory = $this->getTemplateFactory(); - $template = $templateFactory->createTemplate($this, $this->formatTemplateClass()); + $template = $templateFactory->createTemplate($this, $class ?? $this->formatTemplateClass()); assert($template instanceof BasePresenterTemplate); return $template; diff --git a/src/UI/Routing/ClassRoute.php b/src/UI/Routing/ClassRoute.php index b112b0f..92b82e1 100644 --- a/src/UI/Routing/ClassRoute.php +++ b/src/UI/Routing/ClassRoute.php @@ -13,9 +13,9 @@ final class ClassRoute extends Route private const UIMeta = [ 'action' => [ - self::PATTERN => '[a-z][a-z0-9-]*', - self::FILTER_IN => [OriginalRoute::class, 'path2action'], - self::FILTER_OUT => [OriginalRoute::class, 'action2path'], + self::Pattern => '[a-z][a-z0-9-]*', + self::FilterIn => [OriginalRoute::class, 'path2action'], + self::FilterOut => [OriginalRoute::class, 'action2path'], ], ]; diff --git a/src/UI/TemplateLocator/Locator/PresenterTemplateLocator.php b/src/UI/TemplateLocator/Locator/PresenterTemplateLocator.php index be171e1..f047b33 100644 --- a/src/UI/TemplateLocator/Locator/PresenterTemplateLocator.php +++ b/src/UI/TemplateLocator/Locator/PresenterTemplateLocator.php @@ -28,7 +28,7 @@ public function getLayoutTemplatePath(Presenter $presenter, string $layoutName): "@$layoutName", 'Presenter', self::BreakClasses, - Presenter::DEFAULT_ACTION, + Presenter::DefaultAction, ); } @@ -42,7 +42,7 @@ public function getActionTemplatePath(Presenter $presenter, string $viewName): s $viewName, '', self::BreakClasses, - Presenter::DEFAULT_ACTION, + Presenter::DefaultAction, ); }