diff --git a/src/Forms/Blueprint.php b/src/Forms/Blueprint.php index 2f11e940..67ace295 100644 --- a/src/Forms/Blueprint.php +++ b/src/Forms/Blueprint.php @@ -99,7 +99,7 @@ protected function receiveHttpData(): ?array public $inner; - public function getLabel($caption = null): Html|string|null + public function getLabel(string|\Stringable|null $caption = null): Html|string|null { return $this->inner->getLabel() ? '{label ' . $this->inner->lookupPath(Form::class) . '/}' diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 9de29111..824708fa 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -11,6 +11,7 @@ use Nette; use Nette\Utils\ArrayHash; +use Stringable; /** @@ -314,9 +315,13 @@ public function getForm(bool $throw = true): ?Form /** * Adds single-line text input control to the form. - * @param string|object|null $label */ - public function addText(string $name, $label = null, ?int $cols = null, ?int $maxLength = null): Controls\TextInput + public function addText( + string $name, + string|Stringable|null $label = null, + ?int $cols = null, + ?int $maxLength = null, + ): Controls\TextInput { return $this[$name] = (new Controls\TextInput($label, $maxLength)) ->setHtmlAttribute('size', $cols); @@ -325,11 +330,10 @@ public function addText(string $name, $label = null, ?int $cols = null, ?int $ma /** * Adds single-line text input control used for sensitive input such as passwords. - * @param string|object|null $label */ public function addPassword( string $name, - $label = null, + string|Stringable|null $label = null, ?int $cols = null, ?int $maxLength = null, ): Controls\TextInput @@ -342,9 +346,13 @@ public function addPassword( /** * Adds multi-line text input control to the form. - * @param string|object|null $label */ - public function addTextArea(string $name, $label = null, ?int $cols = null, ?int $rows = null): Controls\TextArea + public function addTextArea( + string $name, + string|Stringable|null $label = null, + ?int $cols = null, + ?int $rows = null, + ): Controls\TextArea { return $this[$name] = (new Controls\TextArea($label)) ->setHtmlAttribute('cols', $cols)->setHtmlAttribute('rows', $rows); @@ -353,9 +361,8 @@ public function addTextArea(string $name, $label = null, ?int $cols = null, ?int /** * Adds input for email. - * @param string|object|null $label */ - public function addEmail(string $name, $label = null): Controls\TextInput + public function addEmail(string $name, string|Stringable|null $label = null): Controls\TextInput { return $this[$name] = (new Controls\TextInput($label)) ->addRule(Form::Email); @@ -364,9 +371,8 @@ public function addEmail(string $name, $label = null): Controls\TextInput /** * Adds input for integer. - * @param string|object|null $label */ - public function addInteger(string $name, $label = null): Controls\TextInput + public function addInteger(string $name, string|Stringable|null $label = null): Controls\TextInput { return $this[$name] = (new Controls\TextInput($label)) ->setNullable() @@ -376,9 +382,8 @@ public function addInteger(string $name, $label = null): Controls\TextInput /** * Adds input for float. - * @param string|object|null $label */ - public function addFloat(string $name, $label = null): Controls\TextInput + public function addFloat(string $name, string|Stringable|null $label = null): Controls\TextInput { return $this[$name] = (new Controls\TextInput($label)) ->setNullable() @@ -390,9 +395,8 @@ public function addFloat(string $name, $label = null): Controls\TextInput /** * Adds input for date selection. - * @param string|object|null $label */ - public function addDate(string $name, $label = null): Controls\DateTimeControl + public function addDate(string $name, string|object|null $label = null): Controls\DateTimeControl { return $this[$name] = new Controls\DateTimeControl($label, Controls\DateTimeControl::TypeDate); } @@ -400,9 +404,12 @@ public function addDate(string $name, $label = null): Controls\DateTimeControl /** * Adds input for time selection. - * @param string|object|null $label */ - public function addTime(string $name, $label = null, bool $withSeconds = false): Controls\DateTimeControl + public function addTime( + string $name, + string|object|null $label = null, + bool $withSeconds = false, + ): Controls\DateTimeControl { return $this[$name] = new Controls\DateTimeControl($label, Controls\DateTimeControl::TypeTime, $withSeconds); } @@ -410,9 +417,12 @@ public function addTime(string $name, $label = null, bool $withSeconds = false): /** * Adds input for date and time selection. - * @param string|object|null $label */ - public function addDateTime(string $name, $label = null, bool $withSeconds = false): Controls\DateTimeControl + public function addDateTime( + string $name, + string|object|null $label = null, + bool $withSeconds = false, + ): Controls\DateTimeControl { return $this[$name] = new Controls\DateTimeControl($label, Controls\DateTimeControl::TypeDateTime, $withSeconds); } @@ -420,9 +430,8 @@ public function addDateTime(string $name, $label = null, bool $withSeconds = fal /** * Adds control that allows the user to upload files. - * @param string|object|null $label */ - public function addUpload(string $name, $label = null): Controls\UploadControl + public function addUpload(string $name, string|Stringable|null $label = null): Controls\UploadControl { return $this[$name] = new Controls\UploadControl($label, multiple: false); } @@ -430,9 +439,8 @@ public function addUpload(string $name, $label = null): Controls\UploadControl /** * Adds control that allows the user to upload multiple files. - * @param string|object|null $label */ - public function addMultiUpload(string $name, $label = null): Controls\UploadControl + public function addMultiUpload(string $name, string|Stringable|null $label = null): Controls\UploadControl { return $this[$name] = new Controls\UploadControl($label, multiple: true); } @@ -450,9 +458,8 @@ public function addHidden(string $name, $default = null): Controls\HiddenField /** * Adds check box control to the form. - * @param string|object|null $caption */ - public function addCheckbox(string $name, $caption = null): Controls\Checkbox + public function addCheckbox(string $name, string|Stringable|null $caption = null): Controls\Checkbox { return $this[$name] = new Controls\Checkbox($caption); } @@ -460,9 +467,12 @@ public function addCheckbox(string $name, $caption = null): Controls\Checkbox /** * Adds set of radio button controls to the form. - * @param string|object|null $label */ - public function addRadioList(string $name, $label = null, ?array $items = null): Controls\RadioList + public function addRadioList( + string $name, + string|Stringable|null $label = null, + ?array $items = null, + ): Controls\RadioList { return $this[$name] = new Controls\RadioList($label, $items); } @@ -470,9 +480,12 @@ public function addRadioList(string $name, $label = null, ?array $items = null): /** * Adds set of checkbox controls to the form. - * @param string|object|null $label */ - public function addCheckboxList(string $name, $label = null, ?array $items = null): Controls\CheckboxList + public function addCheckboxList( + string $name, + string|Stringable|null $label = null, + ?array $items = null, + ): Controls\CheckboxList { return $this[$name] = new Controls\CheckboxList($label, $items); } @@ -480,9 +493,13 @@ public function addCheckboxList(string $name, $label = null, ?array $items = nul /** * Adds select box control that allows single item selection. - * @param string|object|null $label */ - public function addSelect(string $name, $label = null, ?array $items = null, ?int $size = null): Controls\SelectBox + public function addSelect( + string $name, + string|Stringable|null $label = null, + ?array $items = null, + ?int $size = null, + ): Controls\SelectBox { return $this[$name] = (new Controls\SelectBox($label, $items)) ->setHtmlAttribute('size', $size > 1 ? $size : null); @@ -491,11 +508,10 @@ public function addSelect(string $name, $label = null, ?array $items = null, ?in /** * Adds select box control that allows multiple item selection. - * @param string|object|null $label */ public function addMultiSelect( string $name, - $label = null, + string|Stringable|null $label = null, ?array $items = null, ?int $size = null, ): Controls\MultiSelectBox @@ -507,9 +523,8 @@ public function addMultiSelect( /** * Adds color picker. - * @param string|object|null $label */ - public function addColor(string $name, $label = null): Controls\ColorPicker + public function addColor(string $name, string|Stringable|null $label = null): Controls\ColorPicker { return $this[$name] = new Controls\ColorPicker($label); } @@ -517,9 +532,8 @@ public function addColor(string $name, $label = null): Controls\ColorPicker /** * Adds button used to submit form. - * @param string|object|null $caption */ - public function addSubmit(string $name, $caption = null): Controls\SubmitButton + public function addSubmit(string $name, string|Stringable|null $caption = null): Controls\SubmitButton { return $this[$name] = new Controls\SubmitButton($caption); } @@ -527,9 +541,8 @@ public function addSubmit(string $name, $caption = null): Controls\SubmitButton /** * Adds push buttons with no default behavior. - * @param string|object|null $caption */ - public function addButton(string $name, $caption = null): Controls\Button + public function addButton(string $name, string|Stringable|null $caption = null): Controls\Button { return $this[$name] = new Controls\Button($caption); } diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index 7e8f0feb..2cd0117a 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -14,6 +14,7 @@ use Nette\Forms\Form; use Nette\Forms\Rules; use Nette\Utils\Html; +use Stringable; /** @@ -23,7 +24,7 @@ * @property-read string $htmlName * @property string|bool|null $htmlId * @property mixed $value - * @property string|object $caption + * @property string|Stringable $caption * @property bool $disabled * @property bool $omitted * @property-read Html $control @@ -49,7 +50,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con /** @var callable[][] extension methods */ private static array $extMethods = []; - private string|object|null $caption; + private string|Stringable|null $caption; private array $errors = []; private ?bool $omitted = null; private Rules $rules; @@ -59,10 +60,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements Con private array $options = []; - /** - * @param string|object $caption - */ - public function __construct($caption = null) + public function __construct(string|Stringable|null $caption = null) { $this->control = Html::el('input', ['type' => null, 'name' => null]); $this->label = Html::el('label'); @@ -79,17 +77,15 @@ public function __construct($caption = null) /** * Sets textual caption or label. - * @param object|string $caption */ - public function setCaption($caption): static + public function setCaption(string|Stringable $caption): static { $this->caption = $caption; return $this; } - /** @return object|string */ - public function getCaption() + public function getCaption(): string|Stringable|null { return $this->caption; } @@ -249,10 +245,9 @@ public function getControl() /** * Generates label's HTML element. - * @param string|object $caption * @return Html|string|null */ - public function getLabel($caption = null) + public function getLabel(string|Stringable|null $caption = null) { $label = clone $this->label; $label->for = $this->getHtmlId(); @@ -400,11 +395,13 @@ public function translate($value, ...$parameters): mixed /** * Adds a validation rule. - * @param string|object $errorMessage * @return static */ - public function addRule(callable|string $validator, $errorMessage = null, mixed $arg = null) - { + public function addRule( + callable|string $validator, + string|Stringable|null $errorMessage = null, + mixed $arg = null, + ) { $this->rules->addRule($validator, $errorMessage, $arg); return $this; } @@ -446,9 +443,8 @@ public function getRules(): Rules /** * Makes control mandatory. - * @param bool|string|object $value */ - public function setRequired($value = true): static + public function setRequired(string|Stringable|bool $value = true): static { $this->rules->setRequired($value); return $this; @@ -480,9 +476,8 @@ public function validate(): void /** * Adds error message to the list. - * @param string|object $message */ - public function addError($message, bool $translate = true): void + public function addError(string|Stringable $message, bool $translate = true): void { $this->errors[] = $translate ? $this->translate($message) : $message; } diff --git a/src/Forms/Controls/Button.php b/src/Forms/Controls/Button.php index 4e532b12..021bbcc7 100644 --- a/src/Forms/Controls/Button.php +++ b/src/Forms/Controls/Button.php @@ -10,6 +10,7 @@ namespace Nette\Forms\Controls; use Nette\Utils\Html; +use Stringable; /** @@ -17,10 +18,7 @@ */ class Button extends BaseControl { - /** - * @param string|object $caption - */ - public function __construct($caption = null) + public function __construct(string|Stringable|null $caption = null) { parent::__construct($caption); $this->control->type = 'button'; @@ -56,9 +54,8 @@ public function renderAsButton(bool $state = true): static /** * Generates control's HTML element. - * @param string|object $caption */ - public function getControl($caption = null): Html + public function getControl(string|Stringable|null $caption = null): Html { $this->setOption('rendered', true); $caption = $this->translate($caption ?? $this->getCaption()); diff --git a/src/Forms/Controls/Checkbox.php b/src/Forms/Controls/Checkbox.php index 8184d846..ff668659 100644 --- a/src/Forms/Controls/Checkbox.php +++ b/src/Forms/Controls/Checkbox.php @@ -11,6 +11,7 @@ use Nette; use Nette\Utils\Html; +use Stringable; /** @@ -21,10 +22,7 @@ class Checkbox extends BaseControl private Html $container; - /** - * @param string|object $label - */ - public function __construct($label = null) + public function __construct(string|Stringable|null $label = null) { parent::__construct($label); $this->control->type = 'checkbox'; diff --git a/src/Forms/Controls/CheckboxList.php b/src/Forms/Controls/CheckboxList.php index 71137a0d..a04207a2 100644 --- a/src/Forms/Controls/CheckboxList.php +++ b/src/Forms/Controls/CheckboxList.php @@ -11,6 +11,7 @@ use Nette; use Nette\Utils\Html; +use Stringable; /** @@ -27,10 +28,7 @@ class CheckboxList extends MultiChoiceControl protected Html $itemLabel; - /** - * @param string|object $label - */ - public function __construct($label = null, ?array $items = null) + public function __construct(string|Stringable|null $label = null, ?array $items = null) { parent::__construct($label, $items); $this->control->type = 'checkbox'; diff --git a/src/Forms/Controls/CsrfProtection.php b/src/Forms/Controls/CsrfProtection.php index f3f17781..4acc8428 100644 --- a/src/Forms/Controls/CsrfProtection.php +++ b/src/Forms/Controls/CsrfProtection.php @@ -11,6 +11,7 @@ use Nette; use Nette\Application\UI\Presenter; +use Stringable; /** @@ -24,10 +25,7 @@ class CsrfProtection extends HiddenField public ?Nette\Http\Session $session = null; - /** - * @param string|object $errorMessage - */ - public function __construct($errorMessage) + public function __construct(string|Stringable|null $errorMessage = null) { parent::__construct(); $this->setOmitted() diff --git a/src/Forms/Controls/DateTimeControl.php b/src/Forms/Controls/DateTimeControl.php index 55085a97..f6f053c1 100644 --- a/src/Forms/Controls/DateTimeControl.php +++ b/src/Forms/Controls/DateTimeControl.php @@ -11,6 +11,7 @@ use Nette; use Nette\Forms\Form; +use Stringable; /** @@ -32,7 +33,7 @@ class DateTimeControl extends BaseControl private string $format = self::FormatObject; - public function __construct($label = null, int $type = self::TypeDate, bool $withSeconds = false) + public function __construct(string|Stringable|null $label = null, int $type = self::Date, bool $withSeconds = false) { $this->type = $type; $this->withSeconds = $withSeconds; diff --git a/src/Forms/Controls/HiddenField.php b/src/Forms/Controls/HiddenField.php index c8049957..7f133f60 100644 --- a/src/Forms/Controls/HiddenField.php +++ b/src/Forms/Controls/HiddenField.php @@ -11,6 +11,7 @@ use Nette; use Nette\Utils\Html; +use Stringable; /** @@ -98,9 +99,8 @@ public function getLabel($caption = null): Html|string|null /** * Adds error message to the list. - * @param string|object $message */ - public function addError($message, bool $translate = true): void + public function addError(string|Stringable $message, bool $translate = true): void { $this->getForm()->addError($message, $translate); } diff --git a/src/Forms/Controls/RadioList.php b/src/Forms/Controls/RadioList.php index 227f5cd9..4a243e5f 100644 --- a/src/Forms/Controls/RadioList.php +++ b/src/Forms/Controls/RadioList.php @@ -11,6 +11,7 @@ use Nette; use Nette\Utils\Html; +use Stringable; /** @@ -28,10 +29,7 @@ class RadioList extends ChoiceControl protected Html $itemLabel; - /** - * @param string|object $label - */ - public function __construct($label = null, ?array $items = null) + public function __construct(string|Stringable|null $label = null, ?array $items = null) { parent::__construct($label, $items); $this->control->type = 'radio'; diff --git a/src/Forms/Controls/SelectBox.php b/src/Forms/Controls/SelectBox.php index e6be2f7f..8ab3f06d 100644 --- a/src/Forms/Controls/SelectBox.php +++ b/src/Forms/Controls/SelectBox.php @@ -10,6 +10,7 @@ namespace Nette\Forms\Controls; use Nette; +use Stringable; /** @@ -23,7 +24,7 @@ class SelectBox extends ChoiceControl /** of option / optgroup */ private array $options = []; - private string|object|false $prompt = false; + private string|Stringable|false $prompt = false; private array $optionAttributes = []; @@ -41,9 +42,8 @@ public function __construct($label = null, ?array $items = null) /** * Sets first prompt item in select box. - * @param string|object|false $prompt */ - public function setPrompt($prompt): static + public function setPrompt(string|Stringable|false $prompt): static { $this->prompt = $prompt; return $this; @@ -52,9 +52,8 @@ public function setPrompt($prompt): static /** * Returns first prompt item? - * @return string|object|false */ - public function getPrompt() + public function getPrompt(): string|Stringable|false { return $this->prompt; } diff --git a/src/Forms/Controls/SubmitButton.php b/src/Forms/Controls/SubmitButton.php index 1a423e1b..69d7eb98 100644 --- a/src/Forms/Controls/SubmitButton.php +++ b/src/Forms/Controls/SubmitButton.php @@ -10,6 +10,7 @@ namespace Nette\Forms\Controls; use Nette; +use Stringable; /** @@ -30,10 +31,7 @@ class SubmitButton extends Button implements Nette\Forms\SubmitterControl private ?array $validationScope = null; - /** - * @param string|object $caption - */ - public function __construct($caption = null) + public function __construct(string|Stringable|null $caption = null) { parent::__construct($caption); $this->control->type = 'submit'; diff --git a/src/Forms/Controls/TextArea.php b/src/Forms/Controls/TextArea.php index 160607a6..80dddb7f 100644 --- a/src/Forms/Controls/TextArea.php +++ b/src/Forms/Controls/TextArea.php @@ -10,6 +10,7 @@ namespace Nette\Forms\Controls; use Nette; +use Stringable; /** @@ -17,10 +18,7 @@ */ class TextArea extends TextBase { - /** - * @param string|object $label - */ - public function __construct($label = null) + public function __construct(string|Stringable|null $label = null) { parent::__construct($label); $this->control->setName('textarea'); diff --git a/src/Forms/Controls/TextBase.php b/src/Forms/Controls/TextBase.php index efa2449d..d8cbd15c 100644 --- a/src/Forms/Controls/TextBase.php +++ b/src/Forms/Controls/TextBase.php @@ -12,6 +12,7 @@ use Nette; use Nette\Forms\Form; use Nette\Utils\Strings; +use Stringable; /** @@ -119,8 +120,11 @@ protected function getRenderedValue(): ?string /** @return static */ - public function addRule(callable|string $validator, $errorMessage = null, mixed $arg = null) - { + public function addRule( + callable|string $validator, + string|Stringable|null $errorMessage = null, + mixed $arg = null, + ) { foreach ($this->getRules() as $rule) { if (!$rule->canExport() && !$rule->branch) { return parent::addRule($validator, $errorMessage, $arg); diff --git a/src/Forms/Controls/TextInput.php b/src/Forms/Controls/TextInput.php index 4bbeb092..95f5f666 100644 --- a/src/Forms/Controls/TextInput.php +++ b/src/Forms/Controls/TextInput.php @@ -11,6 +11,7 @@ use Nette; use Nette\Forms\Form; +use Stringable; /** @@ -18,10 +19,7 @@ */ class TextInput extends TextBase { - /** - * @param string|object $label - */ - public function __construct($label = null, ?int $maxLength = null) + public function __construct(string|Stringable|null $label = null, ?int $maxLength = null) { parent::__construct($label); $this->control->maxlength = $maxLength; @@ -64,8 +62,11 @@ public function getControl(): Nette\Utils\Html /** @return static */ - public function addRule(callable|string $validator, $errorMessage = null, mixed $arg = null) - { + public function addRule( + callable|string $validator, + string|Stringable|null $errorMessage = null, + mixed $arg = null, + ) { foreach ($this->getRules() as $rule) { if (!$rule->canExport() && !$rule->branch) { return parent::addRule($validator, $errorMessage, $arg); diff --git a/src/Forms/Controls/UploadControl.php b/src/Forms/Controls/UploadControl.php index cafb35b4..a862d9d3 100644 --- a/src/Forms/Controls/UploadControl.php +++ b/src/Forms/Controls/UploadControl.php @@ -14,6 +14,7 @@ use Nette\Forms\Form; use Nette\Http\FileUpload; use Nette\Utils\Arrays; +use Stringable; /** @@ -26,10 +27,7 @@ class UploadControl extends BaseControl public const VALID = self::Valid; - /** - * @param string|object $label - */ - public function __construct($label = null, bool $multiple = false) + public function __construct(string|Stringable|null $label = null, bool $multiple = false) { parent::__construct($label); $this->control->type = 'file'; @@ -98,8 +96,11 @@ public function isOk(): bool /** @return static */ - public function addRule(callable|string $validator, $errorMessage = null, mixed $arg = null) - { + public function addRule( + callable|string $validator, + string|Stringable|null $errorMessage = null, + mixed $arg = null, + ) { if ($validator === Form::Image) { $this->control->accept = implode(', ', Forms\Helpers::getSupportedImages()); diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 66ee8a04..dbe13251 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -12,6 +12,7 @@ use Nette; use Nette\Utils\Arrays; use Nette\Utils\Html; +use Stringable; /** @@ -177,9 +178,8 @@ public function getForm(bool $throw = true): static /** * Sets form's action. - * @param string|object $url */ - public function setAction($url): static + public function setAction(string|Stringable $url): static { $this->getElementPrototype()->action = $url; return $this; @@ -262,7 +262,7 @@ public function addProtection(?string $errorMessage = null): Controls\CsrfProtec /** * Adds fieldset group to the form. */ - public function addGroup(string|object|null $caption = null, bool $setAsCurrent = true): ControlGroup + public function addGroup(string|Stringable|null $caption = null, bool $setAsCurrent = true): ControlGroup { $group = new ControlGroup; $group->setOption('label', $caption); @@ -550,9 +550,8 @@ public function validateMaxPostSize(): void /** * Adds global error message. - * @param string|object $message */ - public function addError($message, bool $translate = true): void + public function addError(string|Stringable $message, bool $translate = true): void { if ($translate && $this->translator) { $message = $this->translator->translate($message); diff --git a/src/Forms/Rule.php b/src/Forms/Rule.php index bae34bea..27d57815 100644 --- a/src/Forms/Rule.php +++ b/src/Forms/Rule.php @@ -10,6 +10,7 @@ namespace Nette\Forms; use Nette; +use Stringable; /** @@ -21,7 +22,7 @@ class Rule public mixed $validator; public mixed $arg = null; public bool $isNegative = false; - public object|string|null $message; + public string|Stringable|null $message; public ?Rules $branch = null; diff --git a/src/Forms/Rules.php b/src/Forms/Rules.php index a1a84749..1db83c43 100644 --- a/src/Forms/Rules.php +++ b/src/Forms/Rules.php @@ -10,6 +10,7 @@ namespace Nette\Forms; use Nette; +use Stringable; /** @@ -40,9 +41,8 @@ public function __construct(Control $control) /** * Makes control mandatory. - * @param string|bool $value */ - public function setRequired($value = true): static + public function setRequired(string|Stringable|bool $value = true): static { if ($value) { $this->addRule(Form::Filled, $value === true ? null : $value); @@ -65,9 +65,12 @@ public function isRequired(): bool /** * Adds a validation rule for the current control. - * @param string|object $errorMessage */ - public function addRule(callable|string $validator, $errorMessage = null, mixed $arg = null): static + public function addRule( + callable|string $validator, + string|Stringable|null $errorMessage = null, + mixed $arg = null, + ): static { if ($validator === Form::Valid || $validator === ~Form::Valid) { throw new Nette\InvalidArgumentException('You cannot use Form::Valid in the addRule method.');