From 9568ecf4605170fa6526533bc33ec50d464dc4da Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Thu, 29 Feb 2024 16:20:41 -0300 Subject: [PATCH 01/25] Move `attributes` to `php-forge/html-attributes` package. --- CHANGELOG.md | 1 + composer.json | 5 +- docs/form-control/Label.md | 3 + src/Attribute/CanBeAutofocus.php | 28 - src/Attribute/CanBeHidden.php | 27 - src/Attribute/Custom/HasContent.php | 40 -- src/Attribute/Enum/DataAttributes.php | 26 - src/Attribute/HasClass.php | 31 -- src/Attribute/HasData.php | 41 -- src/Attribute/HasId.php | 44 -- src/Attribute/Input/HasForm.php | 30 -- src/Attribute/Tag/HasFor.php | 32 -- src/Base/AbstractBlockElement.php | 8 +- src/Base/AbstractElement.php | 5 +- src/Base/AbstractSvg.php | 26 +- src/FormControl/Base/AbstractForm.php | 2 - src/FormControl/Base/AbstractSelect.php | 13 +- src/FormControl/Button.php | 60 ++- src/FormControl/Input/Base/AbstractButton.php | 61 +-- .../Input/Base/AbstractChoiceList.php | 168 ------ src/FormControl/Input/Base/AbstractHidden.php | 22 +- src/FormControl/Input/Base/AbstractInput.php | 24 +- .../Input/Base/AbstractInputChoice.php | 19 +- src/FormControl/Input/Checkbox.php | 9 + src/FormControl/Input/CheckboxList.php | 52 -- src/FormControl/Input/DatetimeLocal.php | 12 + src/FormControl/Input/File.php | 1 + src/FormControl/Input/Radio.php | 9 + src/FormControl/Input/RadioList.php | 52 -- src/FormControl/Input/Reset.php | 4 +- src/FormControl/Input/Submit.php | 4 +- src/FormControl/Label.php | 11 +- src/FormControl/TextArea.php | 12 +- src/Group/Base/AbstractLi.php | 7 +- src/Group/Base/AbstractList.php | 1 - src/Metadata/Meta.php | 2 +- tests/Attribute/CanBeAutofocusTest.php | 39 -- tests/Attribute/CanBeHiddenTest.php | 39 -- tests/Attribute/Custom/HasContentTest.php | 51 -- tests/Attribute/HasClassTest.php | 50 -- tests/Attribute/HasDataTest.php | 74 --- tests/Attribute/HasIdTest.php | 22 - tests/Attribute/Input/HasFormTest.php | 22 - tests/Attribute/Tag/HasForTest.php | 22 - .../Input/Checkbox/AttributeTest.php | 8 +- .../Input/Checkbox/CustomMethodTest.php | 6 +- .../Input/CheckboxList/AttributeTest.php | 505 ------------------ .../Input/CheckboxList/CustomMethodTest.php | 328 ------------ .../Input/CheckboxList/ExceptionTest.php | 24 - .../Input/CheckboxList/ImmutabilityTest.php | 21 - .../Input/CheckboxList/LabelTest.php | 203 ------- .../Input/CheckboxList/ValidateTest.php | 40 -- .../FormControl/Input/Color/AttributeTest.php | 8 +- .../Input/Color/CustomMethodTest.php | 6 +- .../FormControl/Input/Date/AttributeTest.php | 8 +- .../Input/Date/CustomMethodTest.php | 6 +- .../Input/Datetime/AttributeTest.php | 8 +- .../Input/Datetime/CustomMethodTest.php | 6 +- .../Input/DatetimeLocal/AttributeTest.php | 8 +- .../Input/DatetimeLocal/CustomMethodTest.php | 6 +- .../FormControl/Input/Email/AttributeTest.php | 8 +- .../Input/Email/CustomMethodTest.php | 6 +- .../FormControl/Input/File/AttributeTest.php | 8 +- .../Input/File/CustomMethodTest.php | 12 +- .../FormControl/Input/Image/AttributeTest.php | 8 +- .../Input/Image/CustomMethodTest.php | 6 +- .../FormControl/Input/Month/AttributeTest.php | 8 +- .../Input/Month/CustomMethodTest.php | 6 +- .../Input/Number/AttributeTest.php | 8 +- .../Input/Number/CustomMethodTest.php | 6 +- .../Input/Password/AttributeTest.php | 8 +- .../Input/Password/CustomMethodTest.php | 6 +- .../FormControl/Input/Radio/AttributeTest.php | 8 +- .../Input/Radio/CustomMethodTest.php | 6 +- .../Input/RadioList/AttributeTest.php | 430 --------------- .../Input/RadioList/CustomMethodTest.php | 290 ---------- .../Input/RadioList/ExceptionTest.php | 24 - .../Input/RadioList/ImmutabilityTest.php | 21 - .../FormControl/Input/RadioList/LabelTest.php | 158 ------ .../Input/RadioList/ValidateTest.php | 37 -- .../FormControl/Input/Range/AttributeTest.php | 8 +- .../Input/Range/CustomMethodTest.php | 6 +- .../Input/Search/AttributeTest.php | 8 +- .../Input/Search/CustomMethodTest.php | 6 +- .../FormControl/Input/Text/AttributeTest.php | 8 +- .../Input/Text/CustomMethodTest.php | 4 +- .../FormControl/Input/Time/AttributeTest.php | 8 +- .../Input/Time/CustomMethodTest.php | 4 +- tests/FormControl/Input/Url/AttributeTest.php | 8 +- .../Input/Url/CustomMethodTest.php | 4 +- .../FormControl/Input/Week/AttributeTest.php | 8 +- .../Input/Week/CustomMethodTest.php | 6 +- tests/FormControl/Label/AttributeTest.php | 36 +- tests/FormControl/Label/CustomMethodTest.php | 65 ++- tests/FormControl/Select/AttributeTest.php | 32 ++ tests/FormControl/Select/CustomMethodTest.php | 6 +- tests/FormControl/TextArea/AttributeTest.php | 20 + .../FormControl/TextArea/CustomMethodTest.php | 6 +- 98 files changed, 431 insertions(+), 3278 deletions(-) delete mode 100644 src/Attribute/CanBeAutofocus.php delete mode 100644 src/Attribute/CanBeHidden.php delete mode 100644 src/Attribute/Custom/HasContent.php delete mode 100644 src/Attribute/Enum/DataAttributes.php delete mode 100644 src/Attribute/HasClass.php delete mode 100644 src/Attribute/HasData.php delete mode 100644 src/Attribute/HasId.php delete mode 100644 src/Attribute/Input/HasForm.php delete mode 100644 src/Attribute/Tag/HasFor.php delete mode 100644 src/FormControl/Input/Base/AbstractChoiceList.php delete mode 100644 src/FormControl/Input/CheckboxList.php delete mode 100644 src/FormControl/Input/RadioList.php delete mode 100644 tests/Attribute/CanBeAutofocusTest.php delete mode 100644 tests/Attribute/CanBeHiddenTest.php delete mode 100644 tests/Attribute/Custom/HasContentTest.php delete mode 100644 tests/Attribute/HasClassTest.php delete mode 100644 tests/Attribute/HasDataTest.php delete mode 100644 tests/Attribute/HasIdTest.php delete mode 100644 tests/Attribute/Input/HasFormTest.php delete mode 100644 tests/Attribute/Tag/HasForTest.php delete mode 100644 tests/FormControl/Input/CheckboxList/AttributeTest.php delete mode 100644 tests/FormControl/Input/CheckboxList/CustomMethodTest.php delete mode 100644 tests/FormControl/Input/CheckboxList/ExceptionTest.php delete mode 100644 tests/FormControl/Input/CheckboxList/ImmutabilityTest.php delete mode 100644 tests/FormControl/Input/CheckboxList/LabelTest.php delete mode 100644 tests/FormControl/Input/CheckboxList/ValidateTest.php delete mode 100644 tests/FormControl/Input/RadioList/AttributeTest.php delete mode 100644 tests/FormControl/Input/RadioList/CustomMethodTest.php delete mode 100644 tests/FormControl/Input/RadioList/ExceptionTest.php delete mode 100644 tests/FormControl/Input/RadioList/ImmutabilityTest.php delete mode 100644 tests/FormControl/Input/RadioList/LabelTest.php delete mode 100644 tests/FormControl/Input/RadioList/ValidateTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 51dd203a..83fb5f11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Enh #338: Move `Helper` classes to `php-forge/html-helper` package (@terabytesoftw) - Enh #339: Move interface `ContentInterface::class` and `LabelInterface::class` to `php-forge/html-interop` package (@terabytesoftw) +- Enh #340: Move `attributes` classes to `php-forge/html-attributes` package (@terabytesoftw) ## 0.2.0 February 27, 2024 diff --git a/composer.json b/composer.json index 2ab31577..9e4bdc37 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,9 @@ "ext-mbstring": "*", "enshrined/svg-sanitize": "^0.17.0", "php-forge/awesome-widget": "^0.1.2", - "php-forge/html-helper": "^0.1", - "php-forge/html-interop": "^0.1", + "php-forge/html-attribute": "dev-main", + "php-forge/html-helper": "^0.2", + "php-forge/html-interop": "^0.2", "voku/anti-xss": "^4.1" }, "require-dev": { diff --git a/docs/form-control/Label.md b/docs/form-control/Label.md index e01ec784..81722827 100644 --- a/docs/form-control/Label.md +++ b/docs/form-control/Label.md @@ -33,6 +33,9 @@ If you want to include content within the `label` tag, use the `content` method. $label->content('MyContent'); ``` +> if content is empty, the `label` tag will not be rendered. + + ## Rendering Generate the `HTML` output using the `render` method. diff --git a/src/Attribute/CanBeAutofocus.php b/src/Attribute/CanBeAutofocus.php deleted file mode 100644 index fcaaea5a..00000000 --- a/src/Attribute/CanBeAutofocus.php +++ /dev/null @@ -1,28 +0,0 @@ -attributes['autofocus'] = true; - - return $new; - } -} diff --git a/src/Attribute/CanBeHidden.php b/src/Attribute/CanBeHidden.php deleted file mode 100644 index 5117d173..00000000 --- a/src/Attribute/CanBeHidden.php +++ /dev/null @@ -1,27 +0,0 @@ -attributes['hidden'] = true; - - return $new; - } -} diff --git a/src/Attribute/Custom/HasContent.php b/src/Attribute/Custom/HasContent.php deleted file mode 100644 index 678f49c0..00000000 --- a/src/Attribute/Custom/HasContent.php +++ /dev/null @@ -1,40 +0,0 @@ -content = Sanitize::html(...$values); - - return $new; - } - - /** - * Get the `HTML` content value. - * - * @return string The `HTML` content value. - */ - public function getContent(): string - { - return $this->content; - } -} diff --git a/src/Attribute/Enum/DataAttributes.php b/src/Attribute/Enum/DataAttributes.php deleted file mode 100644 index e6a3731e..00000000 --- a/src/Attribute/Enum/DataAttributes.php +++ /dev/null @@ -1,26 +0,0 @@ -attributes, $value, $override); - - return $new; - } -} diff --git a/src/Attribute/HasData.php b/src/Attribute/HasData.php deleted file mode 100644 index 229efd96..00000000 --- a/src/Attribute/HasData.php +++ /dev/null @@ -1,41 +0,0 @@ - $value) { - if (!is_string($key) || (!is_string($value) && !$value instanceof Closure)) { - throw new InvalidArgumentException( - 'The data attribute key must be a string and the value must be a string or a Closure.', - ); - } - - - $new->attributes["data-$key"] = $value; - } - - return $new; - } -} diff --git a/src/Attribute/HasId.php b/src/Attribute/HasId.php deleted file mode 100644 index a805bf8c..00000000 --- a/src/Attribute/HasId.php +++ /dev/null @@ -1,44 +0,0 @@ -id = $value; - - return $new; - } - - /** - * Generate a unique ID for the widget. - * - * @param string $value The value to use for the ID. - * - * @return string|null A unique ID for the widget. - */ - protected function generateId(string $value = 'id_'): string|null - { - return $this->id === '' ? uniqid($value) : $this->id; - } -} diff --git a/src/Attribute/Input/HasForm.php b/src/Attribute/Input/HasForm.php deleted file mode 100644 index 28ed9494..00000000 --- a/src/Attribute/Input/HasForm.php +++ /dev/null @@ -1,30 +0,0 @@ -attributes['form'] = $value; - - return $new; - } -} diff --git a/src/Attribute/Tag/HasFor.php b/src/Attribute/Tag/HasFor.php deleted file mode 100644 index 687f9a81..00000000 --- a/src/Attribute/Tag/HasFor.php +++ /dev/null @@ -1,32 +0,0 @@ -attributes['for'] = $value; - - return $new; - } -} diff --git a/src/Base/AbstractBlockElement.php b/src/Base/AbstractBlockElement.php index 2a4666a9..09e405e5 100644 --- a/src/Base/AbstractBlockElement.php +++ b/src/Base/AbstractBlockElement.php @@ -44,10 +44,8 @@ abstract class AbstractBlockElement extends Block public function begin(): string { parent::begin(); - $attributes = $this->attributes; - $attributes['id'] = $this->id; - return HtmlBuilder::begin($this->tagName, $attributes); + return HtmlBuilder::begin($this->tagName, $this->attributes); } /** @@ -58,10 +56,8 @@ public function begin(): string protected function run(): string { if ($this->isBeginExecuted() === false) { - $attributes = $this->attributes; - $attributes['id'] = $this->id; - return HtmlBuilder::create($this->tagName, $this->content, $attributes); + return HtmlBuilder::create($this->tagName, $this->content, $this->attributes); } return HtmlBuilder::end($this->tagName); diff --git a/src/Base/AbstractElement.php b/src/Base/AbstractElement.php index a3f4883b..27ee36b9 100644 --- a/src/Base/AbstractElement.php +++ b/src/Base/AbstractElement.php @@ -61,12 +61,9 @@ protected function loadDefaultDefinitions(): array */ protected function buildElement(string $tagName, string $content = '', array $tokenValues = []): string { - $attributes = $this->attributes; - $attributes['id'] ??= $this->id; - $tokenTemplateValues = [ '{prefix}' => $this->renderPrefixTag(), - '{tag}' => HtmlBuilder::create($tagName, $content, $attributes), + '{tag}' => HtmlBuilder::create($tagName, $content, $this->attributes), '{suffix}' => $this->renderSuffixTag(), ]; $tokenTemplateValues += $tokenValues; diff --git a/src/Base/AbstractSvg.php b/src/Base/AbstractSvg.php index dfde37d0..e3dd69fd 100644 --- a/src/Base/AbstractSvg.php +++ b/src/Base/AbstractSvg.php @@ -8,19 +8,19 @@ use DOMElement; use enshrined\svgSanitize\Sanitizer; use InvalidArgumentException; -use PHPForge\Html\{ - Attribute\Custom\HasAttributes, - Attribute\Custom\HasContent, - Attribute\HasClass, - Attribute\HasId, - Attribute\HasLang, - Attribute\HasTitle, - Attribute\Input\HasHeight, - Attribute\Input\HasName, - Attribute\Input\HasWidth, - Tag +use PHPForge\{ + Html\Attribute\Custom\HasAttributes, + Html\Attribute\Custom\HasContent, + Html\Attribute\HasClass, + Html\Attribute\HasId, + Html\Attribute\HasLang, + Html\Attribute\HasTitle, + Html\Attribute\Input\HasHeight, + Html\Attribute\Input\HasName, + Html\Attribute\Input\HasWidth, + Html\Tag, + Widget\Element }; -use PHPForge\Widget\Element; use RuntimeException; use function file_get_contents; @@ -136,7 +136,6 @@ protected function run(): string default => Tag::widget() ->attributes($this->attributes) ->content(PHP_EOL, $this->content, PHP_EOL) - ->id($this->id) ->tagName('svg') ->render(), }; @@ -181,7 +180,6 @@ private function renderSvg(): string { /** @psalm-var array $attributes */ $attributes = $this->attributes; - $attributes['id'] = $this->id; $svg = new DOMDocument(); diff --git a/src/FormControl/Base/AbstractForm.php b/src/FormControl/Base/AbstractForm.php index 25c1a85a..4f56c692 100644 --- a/src/FormControl/Base/AbstractForm.php +++ b/src/FormControl/Base/AbstractForm.php @@ -68,7 +68,6 @@ public function begin(): string $hiddenInputs = $this->renderHiddenInput(); $attributes = $this->attributes; - $attributes['id'] = $this->id; $html = HtmlBuilder::begin('form', $attributes); @@ -90,7 +89,6 @@ protected function run(): string $hiddenInputs = $this->renderHiddenInput(); $attributes = $this->attributes; - $attributes['id'] = $this->id; $html = ''; if ($hiddenInputs !== '') { diff --git a/src/FormControl/Base/AbstractSelect.php b/src/FormControl/Base/AbstractSelect.php index 1a927df8..a4a7571b 100644 --- a/src/FormControl/Base/AbstractSelect.php +++ b/src/FormControl/Base/AbstractSelect.php @@ -12,7 +12,6 @@ Html\Attribute\Custom\HasLabelCollection, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, - Html\Attribute\Field\HasGenerateField, Html\Attribute\HasClass, Html\Attribute\HasId, Html\Attribute\HasStyle, @@ -28,12 +27,13 @@ Html\Attribute\Tag\HasItemsAttributes, Html\Attribute\Tag\HasPrompt, Html\FormControl\Label, + Html\Helper\Utils, Html\Interop\InputInterface, Html\Interop\RenderInterface, Html\Interop\RequiredInterface, Html\Interop\ValueInterface, Html\Tag, - Widget\Element, + Widget\Element }; use Stringable; @@ -61,7 +61,6 @@ abstract class AbstractSelect extends Element implements use HasAriaLabel; use HasAttributes; use HasClass; - use HasGenerateField; use HasGroup; use HasId; use HasItems; @@ -78,6 +77,13 @@ abstract class AbstractSelect extends Element implements protected array $attributes = []; + public function fieldAttributes(string $formModel, string $property, bool $arrayable = false): static + { + return $this + ->id(Utils::generateInputId($formModel, $property)) + ->name(Utils::generateInputName($formModel, $property, $arrayable)); + } + protected function run(): string { $attributes = $this->attributes; @@ -115,7 +121,6 @@ protected function run(): string $selectTag = Tag::widget() ->attributes($attributes) ->content($items) - ->id($this->id) ->prefix($this->prefix) ->prefixContainer($this->prefixContainer) ->prefixContainerAttributes($this->prefixContainerAttributes) diff --git a/src/FormControl/Button.php b/src/FormControl/Button.php index 36ce6c97..26fda956 100644 --- a/src/FormControl/Button.php +++ b/src/FormControl/Button.php @@ -4,32 +4,33 @@ namespace PHPForge\Html\FormControl; -use PHPForge\Html\{ - Attribute\Aria\HasAriaControls, - Attribute\Aria\HasAriaDescribedBy, - Attribute\Aria\HasAriaDisabled, - Attribute\Aria\HasAriaExpanded, - Attribute\Aria\HasAriaLabel, - Attribute\Aria\HasRole, - Attribute\Custom\HasAttributes, - Attribute\Custom\HasContainerCollection, - Attribute\Custom\HasContent, - Attribute\Custom\HasPrefixCollection, - Attribute\Custom\HasSuffixCollection, - Attribute\Custom\HasTagName, - Attribute\Custom\HasTemplate, - Attribute\Custom\HasValidateInList, - Attribute\HasClass, - Attribute\HasData, - Attribute\HasId, - Attribute\HasLang, - Attribute\HasStyle, - Attribute\HasTabindex, - Attribute\HasTitle, - Attribute\Input\HasName, - Tag +use PHPForge\{ + Html\Attribute\Aria\HasAriaControls, + Html\Attribute\Aria\HasAriaDescribedBy, + Html\Attribute\Aria\HasAriaDisabled, + Html\Attribute\Aria\HasAriaExpanded, + Html\Attribute\Aria\HasAriaLabel, + Html\Attribute\Aria\HasRole, + Html\Attribute\Custom\HasAttributes, + Html\Attribute\Custom\HasContainerCollection, + Html\Attribute\Custom\HasContent, + Html\Attribute\Custom\HasPrefixCollection, + Html\Attribute\Custom\HasSuffixCollection, + Html\Attribute\Custom\HasTagName, + Html\Attribute\Custom\HasTemplate, + Html\Attribute\Custom\HasValidateInList, + Html\Attribute\HasClass, + Html\Attribute\HasData, + Html\Attribute\HasId, + Html\Attribute\HasLang, + Html\Attribute\HasStyle, + Html\Attribute\HasTabindex, + Html\Attribute\HasTitle, + Html\Attribute\Input\HasName, + Html\Helper\Utils, + Html\Tag, + Widget\Element }; -use PHPForge\Widget\Element; /** * The ` + HTML, + Button::widget()->formaction('value')->id('button-658716145f1d9')->render() + ); + } + + public function testFormenctype(): void + { + Assert::equalsWithoutLE( + << + HTML, + Button::widget()->formenctype('text/plain')->id('button-658716145f1d9')->render() + ); + } + + public function testFormmethod(): void + { + Assert::equalsWithoutLE( + << + HTML, + Button::widget()->formmethod('GET')->id('button-658716145f1d9')->render() + ); + } + + public function testFormnovalidate(): void + { + Assert::equalsWithoutLE( + << + HTML, + Button::widget()->formnovalidate()->id('button-658716145f1d9')->render() + ); + } + + public function testFormtarget(): void + { + Assert::equalsWithoutLE( + << + HTML, + Button::widget()->formtarget('_blank')->id('button-658716145f1d9')->render() + ); + } + public function testGenerateAriaDescribedBy(): void { Assert::equalsWithoutLE( diff --git a/tests/FormControl/Input/Button/AttributeTest.php b/tests/FormControl/Input/Button/AttributeTest.php index 20de3240..54a41e9b 100644 --- a/tests/FormControl/Input/Button/AttributeTest.php +++ b/tests/FormControl/Input/Button/AttributeTest.php @@ -108,6 +108,66 @@ public function testForm(): void ); } + public function testFormaction(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Button::widget()->formaction('value')->id('button-6582f2d099e8b')->render() + ); + } + + public function testFormenctype(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Button::widget()->formenctype('text/plain')->id('button-6582f2d099e8b')->render() + ); + } + + public function testFormmethod(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Button::widget()->formmethod('GET')->id('button-6582f2d099e8b')->render() + ); + } + + public function testFormnovalidate(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Button::widget()->formnovalidate()->id('button-6582f2d099e8b')->render() + ); + } + + public function testFormtarget(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Button::widget()->formtarget('_blank')->id('button-6582f2d099e8b')->render() + ); + } + public function testGenerateAriaDescribeBy(): void { Assert::equalsWithoutLE( diff --git a/tests/FormControl/Input/Reset/AttributeTest.php b/tests/FormControl/Input/Reset/AttributeTest.php index d1345268..8ac94bae 100644 --- a/tests/FormControl/Input/Reset/AttributeTest.php +++ b/tests/FormControl/Input/Reset/AttributeTest.php @@ -112,6 +112,66 @@ public function testForm(): void ); } + public function testFormaction(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Reset::widget()->formaction('value')->id('reset-6582f2d099e8b')->render() + ); + } + + public function testFormenctype(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Reset::widget()->formenctype('text/plain')->id('reset-6582f2d099e8b')->render() + ); + } + + public function testFormmethod(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Reset::widget()->formmethod('GET')->id('reset-6582f2d099e8b')->render() + ); + } + + public function testFormnovalidate(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Reset::widget()->formnovalidate()->id('reset-6582f2d099e8b')->render() + ); + } + + public function testFormtarget(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Reset::widget()->formtarget('_blank')->id('reset-6582f2d099e8b')->render() + ); + } + public function testGenerateAriaDescribeBy(): void { Assert::equalsWithoutLE( diff --git a/tests/FormControl/Input/Submit/AttributeTest.php b/tests/FormControl/Input/Submit/AttributeTest.php index 880bc3af..dd2eb130 100644 --- a/tests/FormControl/Input/Submit/AttributeTest.php +++ b/tests/FormControl/Input/Submit/AttributeTest.php @@ -112,6 +112,66 @@ public function testForm(): void ); } + public function testFormaction(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Submit::widget()->formaction('value')->id('submit-6582f2d099e8b')->render() + ); + } + + public function testFormenctype(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Submit::widget()->formenctype('text/plain')->id('submit-6582f2d099e8b')->render() + ); + } + + public function testFormmethod(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Submit::widget()->formmethod('GET')->id('submit-6582f2d099e8b')->render() + ); + } + + public function testFormnovalidate(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Submit::widget()->formnovalidate()->id('submit-6582f2d099e8b')->render() + ); + } + + public function testFormtarget(): void + { + Assert::equalsWithoutLE( + << + + + HTML, + Submit::widget()->formtarget('_blank')->id('submit-6582f2d099e8b')->render() + ); + } + public function testGenerateAriaDescribeBy(): void { Assert::equalsWithoutLE( From c172a4363b092b77e5b6946994c3f3d5602d843a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 3 Mar 2024 04:42:41 -0300 Subject: [PATCH 19/25] Update exception messages in form control input widgets. --- src/Attribute/Component/HasListCollection.php | 6 +-- .../Component/HasToggleCollection.php | 6 +-- src/Attribute/Custom/HasValidateIterable.php | 32 ---------------- src/Attribute/Custom/HasValidateNumeric.php | 32 ---------------- src/Attribute/Custom/HasValidateScalar.php | 32 ---------------- src/Attribute/Custom/HasValidateString.php | 32 ---------------- src/Attribute/Tag/HasCrossorigin.php | 7 +--- src/Attribute/Tag/HasEnctype.php | 6 +-- src/Attribute/Tag/HasLoading.php | 7 +--- src/Attribute/Tag/HasReferrerpolicy.php | 6 +-- src/Attribute/Tag/HasRel.php | 6 +-- src/Attribute/Tag/HasTarget.php | 6 +-- src/Attribute/Tag/HasWrap.php | 6 +-- src/FormControl/Button.php | 5 +-- src/FormControl/Input/Base/AbstractButton.php | 7 ++-- src/FormControl/Input/Base/AbstractHidden.php | 5 +-- .../Input/Base/AbstractInputChoice.php | 5 +-- src/FormControl/Input/Color.php | 5 +-- src/FormControl/Input/Date.php | 23 ++++++------ src/FormControl/Input/Datetime.php | 23 ++++++------ src/FormControl/Input/DatetimeLocal.php | 25 ++++++------- src/FormControl/Input/Email.php | 5 +-- src/FormControl/Input/Month.php | 25 ++++++------- src/FormControl/Input/Number.php | 29 +++++++-------- src/FormControl/Input/Password.php | 5 +-- src/FormControl/Input/Range.php | 5 +-- src/FormControl/Input/Search.php | 5 +-- src/FormControl/Input/Text.php | 37 +++++++++---------- src/FormControl/Input/Time.php | 25 ++++++------- src/FormControl/Input/Url.php | 5 +-- src/FormControl/Input/Week.php | 25 ++++++------- src/Semantic/H.php | 9 +---- .../Custom/HasValidateIterableTest.php | 29 --------------- .../Custom/HasValidateNumericTest.php | 29 --------------- .../Custom/HasValidateScalarTest.php | 29 --------------- .../Custom/HasValidateStringTest.php | 29 --------------- .../Input/Button/ExceptionTest.php | 2 +- .../Input/Checkbox/ExceptionTest.php | 2 +- .../FormControl/Input/Color/ExceptionTest.php | 2 +- .../FormControl/Input/Date/ExceptionTest.php | 2 +- .../Input/Datetime/ExceptionTest.php | 2 +- .../Input/DatetimeLocal/ExceptionTest.php | 2 +- .../FormControl/Input/Email/ExceptionTest.php | 2 +- .../Input/Hidden/ExceptionTest.php | 2 +- .../FormControl/Input/Month/ExceptionTest.php | 2 +- .../Input/Number/ExceptionTest.php | 2 +- .../Input/Password/ExceptionTest.php | 2 +- .../FormControl/Input/Radio/ExceptionTest.php | 2 +- .../FormControl/Input/Range/ExceptionTest.php | 2 +- .../FormControl/Input/Reset/ExceptionTest.php | 2 +- .../Input/Search/ExceptionTest.php | 2 +- .../Input/Submit/ExceptionTest.php | 2 +- .../FormControl/Input/Text/ExceptionTest.php | 2 +- .../FormControl/Input/Time/ExceptionTest.php | 2 +- tests/FormControl/Input/Url/ExceptionTest.php | 2 +- .../FormControl/Input/Week/ExceptionTest.php | 2 +- 56 files changed, 163 insertions(+), 450 deletions(-) delete mode 100644 src/Attribute/Custom/HasValidateIterable.php delete mode 100644 src/Attribute/Custom/HasValidateNumeric.php delete mode 100644 src/Attribute/Custom/HasValidateScalar.php delete mode 100644 src/Attribute/Custom/HasValidateString.php delete mode 100644 tests/Attribute/Custom/HasValidateIterableTest.php delete mode 100644 tests/Attribute/Custom/HasValidateNumericTest.php delete mode 100644 tests/Attribute/Custom/HasValidateScalarTest.php delete mode 100644 tests/Attribute/Custom/HasValidateStringTest.php diff --git a/src/Attribute/Component/HasListCollection.php b/src/Attribute/Component/HasListCollection.php index 757a7fd8..97ae1d5c 100644 --- a/src/Attribute/Component/HasListCollection.php +++ b/src/Attribute/Component/HasListCollection.php @@ -5,15 +5,13 @@ namespace PHPForge\Html\Attribute\Component; use InvalidArgumentException; -use PHPForge\Html\{Attribute\Custom\HasValidateInList, Helper\CssClass}; +use PHPForge\Html\Helper\{CssClass, Validator}; /** * Is used by widgets that implement list collection. */ trait HasListCollection { - use HasValidateInList; - protected array $listAttributes = []; protected bool $listContainer = false; protected array $listContainerAttributes = []; @@ -110,7 +108,7 @@ public function listContainerClass(string $value, bool $override = false): stati public function listType(string|false $value): static { if ($value !== false) { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the list type method. Allowed values are: "%s".', 'ol', diff --git a/src/Attribute/Component/HasToggleCollection.php b/src/Attribute/Component/HasToggleCollection.php index b19ef37f..46e279a1 100644 --- a/src/Attribute/Component/HasToggleCollection.php +++ b/src/Attribute/Component/HasToggleCollection.php @@ -5,7 +5,7 @@ namespace PHPForge\Html\Attribute\Component; use InvalidArgumentException; -use PHPForge\Html\{Attribute\Custom\HasValidateInList, Helper\Sanitize, Interop\RenderInterface, Tag}; +use PHPForge\Html\{Helper\Sanitize, Helper\Validator, Interop\RenderInterface, Tag}; use function array_merge; @@ -14,8 +14,6 @@ */ trait HasToggleCollection { - use HasValidateInList; - protected bool $isToggle = true; protected array $toggleAttributes = []; protected string $toggleClass = ''; @@ -98,7 +96,7 @@ public function toggleContent(string|RenderInterface ...$values): static */ public function toggleDataAttribute(string $name, string $value): static { - $this->validateInList( + Validator::inList( $name, 'Invalid value "%s" for the data attribute. Allowed values are: "%s".', 'bs-toggle', diff --git a/src/Attribute/Custom/HasValidateIterable.php b/src/Attribute/Custom/HasValidateIterable.php deleted file mode 100644 index 9a9650fd..00000000 --- a/src/Attribute/Custom/HasValidateIterable.php +++ /dev/null @@ -1,32 +0,0 @@ -validateInList( + Validator::inList( $value, 'Invalid value "%s" for the crossorigin attribute. Allowed values are: "%s".', 'anonymous', diff --git a/src/Attribute/Tag/HasEnctype.php b/src/Attribute/Tag/HasEnctype.php index c4ce8f02..a1997a1d 100644 --- a/src/Attribute/Tag/HasEnctype.php +++ b/src/Attribute/Tag/HasEnctype.php @@ -5,15 +5,13 @@ namespace PHPForge\Html\Attribute\Tag; use InvalidArgumentException; -use PHPForge\Html\Attribute\Custom\HasValidateInList; +use PHPForge\Html\Helper\Validator; /** * Is used by widgets that implement the enctype method. */ trait HasEnctype { - use HasValidateInList; - /** * Set the enctype content attribute specifies the content type of the form submission. * @@ -28,7 +26,7 @@ trait HasEnctype */ public function enctype(string $value): static { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the enctype attribute. Allowed values are: "%s".', 'multipart/form-data', diff --git a/src/Attribute/Tag/HasLoading.php b/src/Attribute/Tag/HasLoading.php index d2fda74c..817bf494 100644 --- a/src/Attribute/Tag/HasLoading.php +++ b/src/Attribute/Tag/HasLoading.php @@ -5,16 +5,13 @@ namespace PHPForge\Html\Attribute\Tag; use InvalidArgumentException; - -use PHPForge\Html\Attribute\Custom\HasValidateInList; +use PHPForge\Html\Helper\Validator; /** * Is used by widgets that implement the loading method. */ trait HasLoading { - use HasValidateInList; - /** * Specifying when the browser should load the image. * @@ -26,7 +23,7 @@ trait HasLoading */ public function loading(string $value): static { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the loading attribute. Allowed values are: "%s".', 'eager', diff --git a/src/Attribute/Tag/HasReferrerpolicy.php b/src/Attribute/Tag/HasReferrerpolicy.php index 778a95e0..b5493a00 100644 --- a/src/Attribute/Tag/HasReferrerpolicy.php +++ b/src/Attribute/Tag/HasReferrerpolicy.php @@ -5,15 +5,13 @@ namespace PHPForge\Html\Attribute\Tag; use InvalidArgumentException; -use PHPForge\Html\Attribute\Custom\HasValidateInList; +use PHPForge\Html\Helper\Validator; /** * Is used by widgets that implement the referrerpolicy method. */ trait HasReferrerpolicy { - use HasValidateInList; - /** * Returns a new instance specifying a string indicating which referrer to use when fetching the resource. * @@ -29,7 +27,7 @@ trait HasReferrerpolicy */ public function referrerpolicy(string $value): static { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the referrerpolicy attribute. Allowed values are: "%s".', 'no-referrer', diff --git a/src/Attribute/Tag/HasRel.php b/src/Attribute/Tag/HasRel.php index bdd9fe8e..ef26376e 100644 --- a/src/Attribute/Tag/HasRel.php +++ b/src/Attribute/Tag/HasRel.php @@ -5,15 +5,13 @@ namespace PHPForge\Html\Attribute\Tag; use InvalidArgumentException; -use PHPForge\Html\Attribute\Custom\HasValidateInList; +use PHPForge\Html\Helper\Validator; /** * Is used by widgets that implement the rel method. */ trait HasRel { - use HasValidateInList; - /** * Set the rel attribute specifies the relationship between the current document and the linked document. * @@ -29,7 +27,7 @@ trait HasRel */ public function rel(string $value): static { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the rel attribute. Allowed values are: "%s".', 'alternate', diff --git a/src/Attribute/Tag/HasTarget.php b/src/Attribute/Tag/HasTarget.php index b1620e19..dd7cf09b 100644 --- a/src/Attribute/Tag/HasTarget.php +++ b/src/Attribute/Tag/HasTarget.php @@ -5,15 +5,13 @@ namespace PHPForge\Html\Attribute\Tag; use InvalidArgumentException; -use PHPForge\Html\Attribute\Custom\HasValidateInList; +use PHPForge\Html\Helper\Validator; /** * Is used by widgets that implement the target method. */ trait HasTarget { - use HasValidateInList; - /** * Set the target attributes, if specified, must have values that are valid browsing context names or keywords. * @@ -28,7 +26,7 @@ trait HasTarget */ public function target(string $value): static { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the target attribute. Allowed values are: "%s".', '_blank', diff --git a/src/Attribute/Tag/HasWrap.php b/src/Attribute/Tag/HasWrap.php index fe9d3aa6..cb1cb3c1 100644 --- a/src/Attribute/Tag/HasWrap.php +++ b/src/Attribute/Tag/HasWrap.php @@ -5,15 +5,13 @@ namespace PHPForge\Html\Attribute\Tag; use InvalidArgumentException; -use PHPForge\Html\Attribute\Custom\HasValidateInList; +use PHPForge\Html\Helper\Validator; /** * Is used by widgets that implement the wrap method. */ trait HasWrap { - use HasValidateInList; - /** * Set the wrap attribute is an enumerated attribute with two keywords and states: the soft keyword, which maps to * the Soft state, and the hard keyword which maps to the Hard state. @@ -32,7 +30,7 @@ trait HasWrap */ public function wrap(string $value = 'hard'): static { - $this->validateInList( + Validator::inList( $value, 'Invalid value "%s" for the wrap attribute. Allowed values are: "%s".', 'hard', diff --git a/src/FormControl/Button.php b/src/FormControl/Button.php index 42c09db3..7d706fbc 100644 --- a/src/FormControl/Button.php +++ b/src/FormControl/Button.php @@ -18,7 +18,6 @@ Html\Attribute\Custom\HasSuffixCollection, Html\Attribute\Custom\HasTagName, Html\Attribute\Custom\HasTemplate, - Html\Attribute\Custom\HasValidateInList, Html\Attribute\FormControl\HasFormaction, Html\Attribute\FormControl\HasFormenctype, Html\Attribute\FormControl\HasFormmethod, @@ -33,6 +32,7 @@ Html\Attribute\HasTabindex, Html\Attribute\HasTitle, Html\Helper\Utils, + Html\Helper\Validator, Html\Tag, Widget\Element }; @@ -72,7 +72,6 @@ final class Button extends Element use HasTagName; use HasTemplate; use HasTitle; - use HasValidateInList; protected array $attributes = []; protected string $type = 'button'; @@ -98,7 +97,7 @@ protected function run(): string { $attributes = $this->attributes; - $this->validateInList( + Validator::inList( $this->tagName, 'Invalid value "%s" for the tagname method. Allowed values are: "%s".', 'a', diff --git a/src/FormControl/Input/Base/AbstractButton.php b/src/FormControl/Input/Base/AbstractButton.php index cc9760e5..927a72bb 100644 --- a/src/FormControl/Input/Base/AbstractButton.php +++ b/src/FormControl/Input/Base/AbstractButton.php @@ -14,7 +14,6 @@ Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, Html\Attribute\Custom\HasTemplate, - Html\Attribute\Custom\HasValidateString, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, Html\Attribute\FormControl\HasForm, @@ -37,11 +36,12 @@ Html\Attribute\HasTabindex, Html\Attribute\HasTitle, Html\Attribute\Input\HasValue, + Html\FormControl\Label, Html\Helper\Utils, + Html\Helper\Validator, Html\Tag, Widget\Element }; -use PHPForge\Html\FormControl\Label; abstract class AbstractButton extends Element { @@ -75,7 +75,6 @@ abstract class AbstractButton extends Element use HasTabindex; use HasTemplate; use HasTitle; - use HasValidateString; use HasValue; protected array $attributes = []; @@ -95,7 +94,7 @@ protected function loadDefaultDefinitions(): array protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); $id = $this->getId(); diff --git a/src/FormControl/Input/Base/AbstractHidden.php b/src/FormControl/Input/Base/AbstractHidden.php index a6d0e789..bbe18fa6 100644 --- a/src/FormControl/Input/Base/AbstractHidden.php +++ b/src/FormControl/Input/Base/AbstractHidden.php @@ -7,13 +7,13 @@ use PHPForge\{ Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasTemplate, - Html\Attribute\Custom\HasValidateString, Html\Attribute\FormControl\HasName, Html\Attribute\HasClass, Html\Attribute\HasId, Html\Attribute\HasStyle, Html\Attribute\Input\HasValue, Html\Helper\Utils, + Html\Helper\Validator, Html\Interop\ValueInterface, Html\Tag, Widget\Element @@ -27,7 +27,6 @@ abstract class AbstractHidden extends Element implements ValueInterface use HasName; use HasStyle; use HasTemplate; - use HasValidateString; use HasValue; protected array $attributes = []; @@ -44,7 +43,7 @@ protected function loadDefaultDefinitions(): array protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return Tag::widget()->attributes($this->attributes)->tagName('input')->type('hidden')->render(); } diff --git a/src/FormControl/Input/Base/AbstractInputChoice.php b/src/FormControl/Input/Base/AbstractInputChoice.php index e367ddb5..93d53f3c 100644 --- a/src/FormControl/Input/Base/AbstractInputChoice.php +++ b/src/FormControl/Input/Base/AbstractInputChoice.php @@ -18,7 +18,6 @@ Html\Attribute\Custom\HasSuffixCollection, Html\Attribute\Custom\HasTemplate, Html\Attribute\Custom\HasUncheckedCollection, - Html\Attribute\Custom\HasValidateScalar, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, Html\Attribute\FormControl\CanBeRequired, @@ -41,6 +40,7 @@ Html\Attribute\Input\HasValue, Html\FormControl\Label, Html\Helper\Utils, + Html\Helper\Validator, Html\Interop\AriaDescribedByInterface, Html\Interop\CheckedInterface, Html\Interop\InputInterface, @@ -94,7 +94,6 @@ abstract class AbstractInputChoice extends Element implements use HasTemplate; use HasTitle; use HasUncheckedCollection; - use HasValidateScalar; use HasValue; protected array $attributes = []; @@ -123,7 +122,7 @@ protected function buildChoiceTag(string $type): string { $value = $this->getValue(); - $this->validateScalar($value, $this->checked); + Validator::isScalar($value, $this->checked); $attributes = $this->attributes; diff --git a/src/FormControl/Input/Color.php b/src/FormControl/Input/Color.php index 42ec79bc..3cda4354 100644 --- a/src/FormControl/Input/Color.php +++ b/src/FormControl/Input/Color.php @@ -5,11 +5,11 @@ namespace PHPForge\Html\FormControl\Input; use PHPForge\Html\{ - Attribute\Custom\HasValidateString, Attribute\FormControl\CanBeRequired, Attribute\FormControl\HasAutocomplete, Attribute\FormControl\HasDirname, Attribute\Input\HasValue, + Helper\Validator, Interop\RequiredInterface, Interop\ValueInterface }; @@ -25,14 +25,13 @@ final class Color extends Base\AbstractInput implements RequiredInterface, Value use CanBeRequired; use HasAutocomplete; use HasDirname; - use HasValidateString; use HasValue; protected string $type = 'color'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Date.php b/src/FormControl/Input/Date.php index b381c038..d0d73278 100644 --- a/src/FormControl/Input/Date.php +++ b/src/FormControl/Input/Date.php @@ -4,16 +4,16 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + Helper\Validator, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -28,14 +28,13 @@ final class Date extends Base\AbstractInput implements RangeLengthInterface, Req use HasMax; use HasMin; use HasStep; - use HasValidateString; use HasValue; protected string $type = 'date'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Datetime.php b/src/FormControl/Input/Datetime.php index f9cc3a9a..90bb5df4 100644 --- a/src/FormControl/Input/Datetime.php +++ b/src/FormControl/Input/Datetime.php @@ -4,16 +4,16 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + Helper\Validator, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -28,14 +28,13 @@ final class Datetime extends Base\AbstractInput implements RangeLengthInterface, use HasMax; use HasMin; use HasStep; - use HasValidateString; use HasValue; protected string $type = 'datetime'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/DatetimeLocal.php b/src/FormControl/Input/DatetimeLocal.php index 98911f42..218324b6 100644 --- a/src/FormControl/Input/DatetimeLocal.php +++ b/src/FormControl/Input/DatetimeLocal.php @@ -4,17 +4,17 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\Helper\Utils, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + Helper\Utils, + Helper\Validator, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -29,7 +29,6 @@ final class DatetimeLocal extends Base\AbstractInput implements RangeLengthInter use HasMax; use HasMin; use HasStep; - use HasValidateString; use HasValue; protected string $type = 'datetime-local'; @@ -47,7 +46,7 @@ protected function loadDefaultDefinitions(): array protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Email.php b/src/FormControl/Input/Email.php index 50186d84..87fc2894 100644 --- a/src/FormControl/Input/Email.php +++ b/src/FormControl/Input/Email.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\FormControl\Input; use PHPForge\Html\{ - Attribute\Custom\HasValidateString, Attribute\FormControl\CanBeMultiple, Attribute\FormControl\CanBeRequired, Attribute\FormControl\HasAutocomplete, @@ -17,6 +16,7 @@ Attribute\Input\HasSize, Attribute\Input\HasValue, FormControl\Input\Base\AbstractInput, + Helper\Validator, Interop\LengthInterface, Interop\PatternInterface, Interop\PlaceholderInterface, @@ -46,14 +46,13 @@ final class Email extends AbstractInput implements use HasPattern; use HasPlaceholder; use HasSize; - use HasValidateString; use HasValue; protected string $type = 'email'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Month.php b/src/FormControl/Input/Month.php index 00760ef4..d507c2c2 100644 --- a/src/FormControl/Input/Month.php +++ b/src/FormControl/Input/Month.php @@ -4,17 +4,17 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\FormControl\Input\Base\AbstractInput, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + FormControl\Input\Base\AbstractInput, + Helper\Validator, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -29,14 +29,13 @@ final class Month extends AbstractInput implements RangeLengthInterface, Require use HasMax; use HasMin; use HasStep; - use HasValidateString; use HasValue; protected string $type = 'month'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Number.php b/src/FormControl/Input/Number.php index c7c041da..ae694c9e 100644 --- a/src/FormControl/Input/Number.php +++ b/src/FormControl/Input/Number.php @@ -4,19 +4,19 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateNumeric, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasPlaceholder, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\FormControl\Input\Base\AbstractInput, - Html\Interop\PlaceholderInterface, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasPlaceholder, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + FormControl\Input\Base\AbstractInput, + Helper\Validator, + Interop\PlaceholderInterface, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -36,14 +36,13 @@ final class Number extends AbstractInput implements use HasMin; use HasPlaceholder; use HasStep; - use HasValidateNumeric; use HasValue; protected string $type = 'number'; protected function run(): string { - $this->validateNumeric($this->getValue()); + Validator::isNumeric($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Password.php b/src/FormControl/Input/Password.php index 4dad080f..caf4a7e8 100644 --- a/src/FormControl/Input/Password.php +++ b/src/FormControl/Input/Password.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\FormControl\Input; use PHPForge\Html\{ - Attribute\Custom\HasValidateString, Attribute\FormControl\CanBeRequired, Attribute\FormControl\HasAutocomplete, Attribute\FormControl\HasDirname, @@ -16,6 +15,7 @@ Attribute\Input\HasSize, Attribute\Input\HasValue, FormControl\Input\Base\AbstractInput, + Helper\Validator, Interop\LengthInterface, Interop\PatternInterface, Interop\PlaceholderInterface, @@ -44,14 +44,13 @@ final class Password extends AbstractInput implements use HasPattern; use HasPlaceholder; use HasSize; - use HasValidateString; use HasValue; protected string $type = 'password'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Range.php b/src/FormControl/Input/Range.php index 094a0389..80bb696a 100644 --- a/src/FormControl/Input/Range.php +++ b/src/FormControl/Input/Range.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\FormControl\Input; use PHPForge\Html\{ - Attribute\Custom\HasValidateNumeric, Attribute\FormControl\HasAutocomplete, Attribute\FormControl\HasDirname, Attribute\Input\HasMax, @@ -13,6 +12,7 @@ Attribute\Input\HasStep, Attribute\Input\HasValue, FormControl\Input\Base\AbstractInput, + Helper\Validator, Interop\RangeLengthInterface, Interop\ValueInterface }; @@ -30,14 +30,13 @@ final class Range extends AbstractInput implements RangeLengthInterface, ValueIn use HasMax; use HasMin; use HasStep; - use HasValidateNumeric; use HasValue; protected string $type = 'range'; protected function run(): string { - $this->validateNumeric($this->getValue()); + Validator::isNumeric($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Search.php b/src/FormControl/Input/Search.php index 6d574086..30dc65e2 100644 --- a/src/FormControl/Input/Search.php +++ b/src/FormControl/Input/Search.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\FormControl\Input; use PHPForge\Html\{ - Attribute\Custom\HasValidateString, Attribute\FormControl\CanBeRequired, Attribute\FormControl\HasAutocomplete, Attribute\FormControl\HasDirname, @@ -22,6 +21,7 @@ Interop\RequiredInterface, Interop\ValueInterface }; +use PHPForge\Html\Helper\Validator; /** * The input element with a type attribute whose value is "search" represents a one-line plain-text edit control for @@ -44,14 +44,13 @@ final class Search extends AbstractInput implements use HasPattern; use HasPlaceholder; use HasSize; - use HasValidateString; use HasValue; protected string $type = 'search'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Text.php b/src/FormControl/Input/Text.php index f717dddd..845a9b3a 100644 --- a/src/FormControl/Input/Text.php +++ b/src/FormControl/Input/Text.php @@ -4,23 +4,23 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\FormControl\HasAutocomplete, - Html\Attribute\FormControl\HasDirname, - Html\Attribute\Input\HasMaxLength, - Html\Attribute\Input\HasMinLength, - Html\Attribute\Input\HasPattern, - Html\Attribute\Input\HasPlaceholder, - Html\Attribute\Input\HasSize, - Html\Attribute\Input\HasValue, - Html\FormControl\Input\Base\AbstractInput, - Html\Interop\LengthInterface, - Html\Interop\PatternInterface, - Html\Interop\PlaceholderInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\FormControl\HasAutocomplete, + Attribute\FormControl\HasDirname, + Attribute\Input\HasMaxLength, + Attribute\Input\HasMinLength, + Attribute\Input\HasPattern, + Attribute\Input\HasPlaceholder, + Attribute\Input\HasSize, + Attribute\Input\HasValue, + FormControl\Input\Base\AbstractInput, + Helper\Validator, + Interop\LengthInterface, + Interop\PatternInterface, + Interop\PlaceholderInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -44,12 +44,11 @@ final class Text extends AbstractInput implements use HasPattern; use HasPlaceholder; use HasSize; - use HasValidateString; use HasValue; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Time.php b/src/FormControl/Input/Time.php index 16e647df..e4ffa6ba 100644 --- a/src/FormControl/Input/Time.php +++ b/src/FormControl/Input/Time.php @@ -4,17 +4,17 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\FormControl\Input\Base\AbstractInput, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + FormControl\Input\Base\AbstractInput, + Helper\Validator, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -29,14 +29,13 @@ final class Time extends AbstractInput implements RangeLengthInterface, Required use HasMax; use HasMin; use HasStep; - use HasValidateString; use HasValue; protected string $type = 'time'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Url.php b/src/FormControl/Input/Url.php index 4e6aa718..a4175e89 100644 --- a/src/FormControl/Input/Url.php +++ b/src/FormControl/Input/Url.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\FormControl\Input; use PHPForge\Html\{ - Attribute\Custom\HasValidateString, Attribute\FormControl\CanBeRequired, Attribute\FormControl\HasAutocomplete, Attribute\FormControl\HasDirname, @@ -22,6 +21,7 @@ Interop\RequiredInterface, Interop\ValueInterface }; +use PHPForge\Html\Helper\Validator; /** * The input element with a type attribute whose value is "url" represents a control for editing an absolute URL given @@ -44,14 +44,13 @@ final class Url extends AbstractInput implements use HasPattern; use HasPlaceholder; use HasSize; - use HasValidateString; use HasValue; protected string $type = 'url'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/FormControl/Input/Week.php b/src/FormControl/Input/Week.php index c97bd3cc..1f5d00b4 100644 --- a/src/FormControl/Input/Week.php +++ b/src/FormControl/Input/Week.php @@ -4,17 +4,17 @@ namespace PHPForge\Html\FormControl\Input; -use PHPForge\{ - Html\Attribute\Custom\HasValidateString, - Html\Attribute\FormControl\CanBeRequired, - Html\Attribute\Input\HasMax, - Html\Attribute\Input\HasMin, - Html\Attribute\Input\HasStep, - Html\Attribute\Input\HasValue, - Html\FormControl\Input\Base\AbstractInput, - Html\Interop\RangeLengthInterface, - Html\Interop\RequiredInterface, - Html\Interop\ValueInterface +use PHPForge\Html\{ + Attribute\FormControl\CanBeRequired, + Attribute\Input\HasMax, + Attribute\Input\HasMin, + Attribute\Input\HasStep, + Attribute\Input\HasValue, + FormControl\Input\Base\AbstractInput, + Helper\Validator, + Interop\RangeLengthInterface, + Interop\RequiredInterface, + Interop\ValueInterface }; /** @@ -29,14 +29,13 @@ final class Week extends AbstractInput implements RangeLengthInterface, Required use HasMax; use HasMin; use HasStep; - use HasValidateString; use HasValue; protected string $type = 'week'; protected function run(): string { - $this->validateString($this->getValue()); + Validator::isString($this->getValue()); return $this->renderInputTag($this->attributes); } diff --git a/src/Semantic/H.php b/src/Semantic/H.php index 4b9ec522..69cb5423 100644 --- a/src/Semantic/H.php +++ b/src/Semantic/H.php @@ -4,11 +4,7 @@ namespace PHPForge\Html\Semantic; -use PHPForge\Html\{ - Attribute\Custom\HasTagName, - Attribute\Custom\HasValidateInList, - Base\AbstractBlockElement -}; +use PHPForge\Html\{Attribute\Custom\HasTagName, Base\AbstractBlockElement, Helper\Validator}; /** * The `

` to `

` HTML elements represent six levels of section headings. @@ -19,7 +15,6 @@ final class H extends AbstractBlockElement { use HasTagName; - use HasValidateInList; /** * This method is used to configure the widget with the provided default definitions. @@ -33,7 +28,7 @@ protected function loadDefaultDefinitions(): array protected function run(): string { - $this->validateInList( + Validator::inList( $this->tagName, 'Invalid value "%s" for the tagname method. Allowed values are: "%s".', 'h1', diff --git a/tests/Attribute/Custom/HasValidateIterableTest.php b/tests/Attribute/Custom/HasValidateIterableTest.php deleted file mode 100644 index 6e122fe3..00000000 --- a/tests/Attribute/Custom/HasValidateIterableTest.php +++ /dev/null @@ -1,29 +0,0 @@ -validateIterable('string'); - } - }; - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('class widget must be an iterable or null value.'); - - $instance->run(); - } -} diff --git a/tests/Attribute/Custom/HasValidateNumericTest.php b/tests/Attribute/Custom/HasValidateNumericTest.php deleted file mode 100644 index 78f8b2b7..00000000 --- a/tests/Attribute/Custom/HasValidateNumericTest.php +++ /dev/null @@ -1,29 +0,0 @@ -validateNumeric([]); - } - }; - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('class widget must be a numeric or null value.'); - - $instance->run(); - } -} diff --git a/tests/Attribute/Custom/HasValidateScalarTest.php b/tests/Attribute/Custom/HasValidateScalarTest.php deleted file mode 100644 index 0f1a417e..00000000 --- a/tests/Attribute/Custom/HasValidateScalarTest.php +++ /dev/null @@ -1,29 +0,0 @@ -validateScalar([]); - } - }; - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('class widget must be a scalar value.'); - - $instance->run(); - } -} diff --git a/tests/Attribute/Custom/HasValidateStringTest.php b/tests/Attribute/Custom/HasValidateStringTest.php deleted file mode 100644 index 9676150a..00000000 --- a/tests/Attribute/Custom/HasValidateStringTest.php +++ /dev/null @@ -1,29 +0,0 @@ -validateString([]); - } - }; - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('class widget must be a string or null value.'); - - $instance->run(); - } -} diff --git a/tests/FormControl/Input/Button/ExceptionTest.php b/tests/FormControl/Input/Button/ExceptionTest.php index c3c2f279..9af7f6cf 100644 --- a/tests/FormControl/Input/Button/ExceptionTest.php +++ b/tests/FormControl/Input/Button/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Button::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Button::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Checkbox/ExceptionTest.php b/tests/FormControl/Input/Checkbox/ExceptionTest.php index caac6ce6..3743212c 100644 --- a/tests/FormControl/Input/Checkbox/ExceptionTest.php +++ b/tests/FormControl/Input/Checkbox/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Checkbox::class widget must be a scalar value.'); + $this->expectExceptionMessage('The value must be a scalar or null value. The value is: array.'); Checkbox::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Color/ExceptionTest.php b/tests/FormControl/Input/Color/ExceptionTest.php index ee5e1b04..1a5c0245 100644 --- a/tests/FormControl/Input/Color/ExceptionTest.php +++ b/tests/FormControl/Input/Color/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Color::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Color::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Date/ExceptionTest.php b/tests/FormControl/Input/Date/ExceptionTest.php index 35c99b51..24e918bc 100644 --- a/tests/FormControl/Input/Date/ExceptionTest.php +++ b/tests/FormControl/Input/Date/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Date::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Date::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Datetime/ExceptionTest.php b/tests/FormControl/Input/Datetime/ExceptionTest.php index 2df1e59f..3f84bf9f 100644 --- a/tests/FormControl/Input/Datetime/ExceptionTest.php +++ b/tests/FormControl/Input/Datetime/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Datetime::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Datetime::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/DatetimeLocal/ExceptionTest.php b/tests/FormControl/Input/DatetimeLocal/ExceptionTest.php index 207dd3c8..221da6f6 100644 --- a/tests/FormControl/Input/DatetimeLocal/ExceptionTest.php +++ b/tests/FormControl/Input/DatetimeLocal/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('DatetimeLocal::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); DatetimeLocal::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Email/ExceptionTest.php b/tests/FormControl/Input/Email/ExceptionTest.php index b6c25e8b..b4f61b22 100644 --- a/tests/FormControl/Input/Email/ExceptionTest.php +++ b/tests/FormControl/Input/Email/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Email::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: integer.'); Email::widget()->value(1)->render(); } diff --git a/tests/FormControl/Input/Hidden/ExceptionTest.php b/tests/FormControl/Input/Hidden/ExceptionTest.php index 7444c7ef..2919fcc4 100644 --- a/tests/FormControl/Input/Hidden/ExceptionTest.php +++ b/tests/FormControl/Input/Hidden/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Hidden::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Hidden::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Month/ExceptionTest.php b/tests/FormControl/Input/Month/ExceptionTest.php index e5fc970e..db1f8421 100644 --- a/tests/FormControl/Input/Month/ExceptionTest.php +++ b/tests/FormControl/Input/Month/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Month::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Month::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Number/ExceptionTest.php b/tests/FormControl/Input/Number/ExceptionTest.php index 8776a18f..96f81468 100644 --- a/tests/FormControl/Input/Number/ExceptionTest.php +++ b/tests/FormControl/Input/Number/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Number::class widget must be a numeric or null value.'); + $this->expectExceptionMessage('The value must be a numeric or null value. The value is: array.'); Number::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Password/ExceptionTest.php b/tests/FormControl/Input/Password/ExceptionTest.php index c4f602a3..eb62b725 100644 --- a/tests/FormControl/Input/Password/ExceptionTest.php +++ b/tests/FormControl/Input/Password/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Password::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Password::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Radio/ExceptionTest.php b/tests/FormControl/Input/Radio/ExceptionTest.php index b15024da..6b6e24cb 100644 --- a/tests/FormControl/Input/Radio/ExceptionTest.php +++ b/tests/FormControl/Input/Radio/ExceptionTest.php @@ -17,7 +17,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Radio::class widget must be a scalar value.'); + $this->expectExceptionMessage('The value must be a scalar or null value. The value is: array.'); Radio::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Range/ExceptionTest.php b/tests/FormControl/Input/Range/ExceptionTest.php index 4113be54..857507e0 100644 --- a/tests/FormControl/Input/Range/ExceptionTest.php +++ b/tests/FormControl/Input/Range/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Range::class widget must be a numeric or null value.'); + $this->expectExceptionMessage('The value must be a numeric or null value. The value is: array.'); Range::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Reset/ExceptionTest.php b/tests/FormControl/Input/Reset/ExceptionTest.php index eaa9d119..08445f6a 100644 --- a/tests/FormControl/Input/Reset/ExceptionTest.php +++ b/tests/FormControl/Input/Reset/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Reset::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Reset::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Search/ExceptionTest.php b/tests/FormControl/Input/Search/ExceptionTest.php index 5769ed85..94d575b7 100644 --- a/tests/FormControl/Input/Search/ExceptionTest.php +++ b/tests/FormControl/Input/Search/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Search::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Search::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Submit/ExceptionTest.php b/tests/FormControl/Input/Submit/ExceptionTest.php index b64161b8..c94d0db1 100644 --- a/tests/FormControl/Input/Submit/ExceptionTest.php +++ b/tests/FormControl/Input/Submit/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Submit::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Submit::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Text/ExceptionTest.php b/tests/FormControl/Input/Text/ExceptionTest.php index 5ebf837f..b4de7598 100644 --- a/tests/FormControl/Input/Text/ExceptionTest.php +++ b/tests/FormControl/Input/Text/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Text::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Text::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Time/ExceptionTest.php b/tests/FormControl/Input/Time/ExceptionTest.php index 0e69a5ed..4899d277 100644 --- a/tests/FormControl/Input/Time/ExceptionTest.php +++ b/tests/FormControl/Input/Time/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Time::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Time::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Url/ExceptionTest.php b/tests/FormControl/Input/Url/ExceptionTest.php index 2f87381a..3a5f43cb 100644 --- a/tests/FormControl/Input/Url/ExceptionTest.php +++ b/tests/FormControl/Input/Url/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Url::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Url::widget()->value([])->render(); } diff --git a/tests/FormControl/Input/Week/ExceptionTest.php b/tests/FormControl/Input/Week/ExceptionTest.php index 1d80197e..0dc84ee3 100644 --- a/tests/FormControl/Input/Week/ExceptionTest.php +++ b/tests/FormControl/Input/Week/ExceptionTest.php @@ -16,7 +16,7 @@ final class ExceptionTest extends TestCase public function testValue(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Week::class widget must be a string or null value.'); + $this->expectExceptionMessage('The value must be a string or null value. The value is: array.'); Week::widget()->value([])->render(); } From 56d362d22e0effb7911178c729d2812f05833d2b Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sun, 3 Mar 2024 11:14:38 -0300 Subject: [PATCH 20/25] Better structure. --- src/Attribute/Custom/HasPrefixCollection.php | 17 ------ src/Attribute/Custom/HasSuffixCollection.php | 17 ------ src/Attribute/Custom/HasTemplate.php | 52 ---------------- src/Attribute/Input/HasHeight.php | 31 ---------- src/Base/AbstractBlockElement.php | 14 ++--- src/Base/AbstractElement.php | 40 +++++++++---- src/Base/AbstractSvg.php | 12 ++-- src/FormControl/Base/AbstractForm.php | 12 ++-- src/FormControl/Base/AbstractSelect.php | 10 ++-- src/FormControl/Button.php | 18 +++--- src/FormControl/Input/Base/AbstractButton.php | 20 +++---- src/FormControl/Input/Base/AbstractHidden.php | 8 +-- src/FormControl/Input/Base/AbstractInput.php | 20 +++---- .../Input/Base/AbstractInputChoice.php | 47 ++++++++++----- src/FormControl/Input/Image.php | 2 +- src/FormControl/Input/Tel.php | 60 +++++++++++++++++++ src/FormControl/Label.php | 2 +- src/FormControl/TextArea.php | 6 +- src/Group/Base/AbstractLi.php | 12 ++-- src/Group/Base/AbstractList.php | 12 ++-- src/Metadata/Meta.php | 8 +-- src/Multimedia/Img.php | 2 +- src/Tag.php | 4 +- src/Textual/A.php | 8 +-- src/Textual/I.php | 2 +- src/Textual/Span.php | 2 +- .../Custom/HasPrefixCollectionTest.php | 44 -------------- .../Custom/HasSuffixCollectionTest.php | 46 -------------- tests/Attribute/Custom/HasTemplateTest.php | 20 ------- tests/Attribute/Input/HasHeightTest.php | 22 ------- 30 files changed, 210 insertions(+), 360 deletions(-) delete mode 100644 src/Attribute/Custom/HasTemplate.php delete mode 100644 src/Attribute/Input/HasHeight.php create mode 100644 src/FormControl/Input/Tel.php delete mode 100644 tests/Attribute/Custom/HasTemplateTest.php delete mode 100644 tests/Attribute/Input/HasHeightTest.php diff --git a/src/Attribute/Custom/HasPrefixCollection.php b/src/Attribute/Custom/HasPrefixCollection.php index 7210aa13..d72ad705 100644 --- a/src/Attribute/Custom/HasPrefixCollection.php +++ b/src/Attribute/Custom/HasPrefixCollection.php @@ -98,21 +98,4 @@ public function prefixContainerTag(string $value): static return $new; } - - /** - * Render the prefix container. - * - * @return string The prefix container. - */ - private function renderPrefixTag(): string - { - return match ($this->prefixContainer) { - true => Tag::widget() - ->attributes($this->prefixContainerAttributes) - ->content($this->prefix) - ->tagName($this->prefixContainerTag) - ->render(), - false => $this->prefix, - }; - } } diff --git a/src/Attribute/Custom/HasSuffixCollection.php b/src/Attribute/Custom/HasSuffixCollection.php index c9905112..16ef7fd3 100644 --- a/src/Attribute/Custom/HasSuffixCollection.php +++ b/src/Attribute/Custom/HasSuffixCollection.php @@ -98,21 +98,4 @@ public function suffixContainerTag(string $value): static return $new; } - - /** - * Render the suffix container. - * - * @return string The suffix container. - */ - private function renderSuffixTag(): string - { - return match ($this->suffixContainer) { - true => Tag::widget() - ->attributes($this->suffixContainerAttributes) - ->content($this->suffix) - ->tagName($this->suffixContainerTag) - ->render(), - default => $this->suffix, - }; - } } diff --git a/src/Attribute/Custom/HasTemplate.php b/src/Attribute/Custom/HasTemplate.php deleted file mode 100644 index 2498f8cc..00000000 --- a/src/Attribute/Custom/HasTemplate.php +++ /dev/null @@ -1,52 +0,0 @@ -template = $value; - - return $new; - } - - private function renderTemplate(string $template, array $tokenValues): string - { - $result = ''; - $tokens = explode('\n', $template); - - foreach ($tokens as $key => $token) { - $tokenValue = strtr($token, $tokenValues); - - if ($tokenValue !== '') { - $result .= $tokenValue; - } - - if ($result !== '' && $key < count($tokens) - 1) { - $result = strtr($tokens[$key + 1], $tokenValues) !== '' ? $result . PHP_EOL : $result; - } - } - - return $result; - } -} diff --git a/src/Attribute/Input/HasHeight.php b/src/Attribute/Input/HasHeight.php deleted file mode 100644 index f6b1beaf..00000000 --- a/src/Attribute/Input/HasHeight.php +++ /dev/null @@ -1,31 +0,0 @@ -attributes['height'] = $value; - - return $new; - } -} diff --git a/src/Base/AbstractBlockElement.php b/src/Base/AbstractBlockElement.php index c0c47ba3..80c6aed9 100644 --- a/src/Base/AbstractBlockElement.php +++ b/src/Base/AbstractBlockElement.php @@ -6,13 +6,13 @@ use PHPForge\Html\{ Attribute\Custom\HasAttributes, - Attribute\Custom\HasContent, - Attribute\HasClass, - Attribute\HasData, - Attribute\HasId, - Attribute\HasLang, - Attribute\HasStyle, - Attribute\HasTitle, + Attribute\Global\HasClass, + Attribute\Global\HasData, + Attribute\Global\HasId, + Attribute\Global\HasLang, + Attribute\Global\HasStyle, + Attribute\Global\HasTitle, + Attribute\HasContent, HtmlBuilder }; use PHPForge\Widget\Block; diff --git a/src/Base/AbstractElement.php b/src/Base/AbstractElement.php index 54c923c7..be2029cd 100644 --- a/src/Base/AbstractElement.php +++ b/src/Base/AbstractElement.php @@ -8,15 +8,17 @@ Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, - Html\Attribute\Custom\HasTemplate, - Html\Attribute\HasClass, - Html\Attribute\HasData, - Html\Attribute\HasId, - Html\Attribute\HasLang, - Html\Attribute\HasStyle, - Html\Attribute\HasTitle, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasData, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasLang, + Html\Attribute\Global\HasStyle, + Html\Attribute\Global\HasTitle, + Html\Attribute\HasTemplate, + Html\Helper\Template, Html\HtmlBuilder, Html\Interop\RenderInterface, + Html\Tag, Widget\Element }; @@ -60,12 +62,30 @@ protected function loadDefaultDefinitions(): array protected function buildElement(string $tagName, string $content = '', array $tokenValues = []): string { $tokenTemplateValues = [ - '{prefix}' => $this->renderPrefixTag(), + '{prefix}' => $this->renderTag( + $this->prefixContainerAttributes, + $this->prefixContainer, + $this->prefix, + $this->prefixContainerTag + ), '{tag}' => HtmlBuilder::create($tagName, $content, $this->attributes), - '{suffix}' => $this->renderSuffixTag(), + '{suffix}' => $this->renderTag( + $this->suffixContainerAttributes, + $this->suffixContainer, + $this->suffix, + $this->suffixContainerTag + ), ]; $tokenTemplateValues += $tokenValues; - return $this->renderTemplate($this->template, $tokenTemplateValues); + return Template::render($this->template, $tokenTemplateValues); + } + + private function renderTag(array $attributes, bool $container, string $content, string $tag): string + { + return match ($container) { + true => Tag::widget()->attributes($attributes)->content($content)->tagName($tag)->render(), + false => $content, + }; } } diff --git a/src/Base/AbstractSvg.php b/src/Base/AbstractSvg.php index 913952c2..082aec8b 100644 --- a/src/Base/AbstractSvg.php +++ b/src/Base/AbstractSvg.php @@ -10,12 +10,12 @@ use InvalidArgumentException; use PHPForge\{ Html\Attribute\Custom\HasAttributes, - Html\Attribute\Custom\HasContent, - Html\Attribute\HasClass, - Html\Attribute\HasId, - Html\Attribute\HasLang, - Html\Attribute\HasTitle, - Html\Attribute\Input\HasHeight, + Html\Attribute\FormControl\HasHeight, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasLang, + Html\Attribute\Global\HasTitle, + Html\Attribute\HasContent, Html\Attribute\Input\HasWidth, Html\Tag, Widget\Element diff --git a/src/FormControl/Base/AbstractForm.php b/src/FormControl/Base/AbstractForm.php index 44829e7a..a97a84e9 100644 --- a/src/FormControl/Base/AbstractForm.php +++ b/src/FormControl/Base/AbstractForm.php @@ -6,16 +6,16 @@ use PHPForge\Html\{ Attribute\Custom\HasAttributes, - Attribute\Custom\HasContent, Attribute\Custom\HasCsrf, Attribute\FormControl\HasAccept, Attribute\FormControl\HasAutocomplete, Attribute\FormControl\HasName, - Attribute\HasClass, - Attribute\HasId, - Attribute\HasLang, - Attribute\HasStyle, - Attribute\HasTitle, + Attribute\Global\HasClass, + Attribute\Global\HasId, + Attribute\Global\HasLang, + Attribute\Global\HasStyle, + Attribute\Global\HasTitle, + Attribute\HasContent, Attribute\Tag\CanBeNoValidate, Attribute\Tag\HasAction, Attribute\Tag\HasEnctype, diff --git a/src/FormControl/Base/AbstractSelect.php b/src/FormControl/Base/AbstractSelect.php index 9b854013..9d663842 100644 --- a/src/FormControl/Base/AbstractSelect.php +++ b/src/FormControl/Base/AbstractSelect.php @@ -7,7 +7,6 @@ use InvalidArgumentException; use PHPForge\{ Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\CanBeAutofocus, Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, @@ -22,10 +21,11 @@ Html\Attribute\FormControl\Label\HasLabelAttributes, Html\Attribute\FormControl\Label\HasLabelClass, Html\Attribute\FormControl\Label\HasLabelFor, - Html\Attribute\HasClass, - Html\Attribute\HasId, - Html\Attribute\HasStyle, - Html\Attribute\HasTabindex, + Html\Attribute\Global\CanBeAutofocus, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasStyle, + Html\Attribute\Global\HasTabindex, Html\Attribute\Input\HasSize, Html\Attribute\Input\HasValue, Html\Attribute\Tag\HasGroup, diff --git a/src/FormControl/Button.php b/src/FormControl/Button.php index 7d706fbc..a0bdfdab 100644 --- a/src/FormControl/Button.php +++ b/src/FormControl/Button.php @@ -13,24 +13,24 @@ Html\Attribute\Aria\HasRole, Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasContainerCollection, - Html\Attribute\Custom\HasContent, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, Html\Attribute\Custom\HasTagName, - Html\Attribute\Custom\HasTemplate, Html\Attribute\FormControl\HasFormaction, Html\Attribute\FormControl\HasFormenctype, Html\Attribute\FormControl\HasFormmethod, Html\Attribute\FormControl\HasFormnovalidate, Html\Attribute\FormControl\HasFormtarget, Html\Attribute\FormControl\HasName, - Html\Attribute\HasClass, - Html\Attribute\HasData, - Html\Attribute\HasId, - Html\Attribute\HasLang, - Html\Attribute\HasStyle, - Html\Attribute\HasTabindex, - Html\Attribute\HasTitle, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasData, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasLang, + Html\Attribute\Global\HasStyle, + Html\Attribute\Global\HasTabindex, + Html\Attribute\Global\HasTitle, + Html\Attribute\HasContent, + Html\Attribute\HasTemplate, Html\Helper\Utils, Html\Helper\Validator, Html\Tag, diff --git a/src/FormControl/Input/Base/AbstractButton.php b/src/FormControl/Input/Base/AbstractButton.php index 927a72bb..cac0b086 100644 --- a/src/FormControl/Input/Base/AbstractButton.php +++ b/src/FormControl/Input/Base/AbstractButton.php @@ -7,13 +7,10 @@ use PHPForge\{ Html\Attribute\Aria\HasAriaDescribedBy, Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\CanBeAutofocus, - Html\Attribute\CanBeHidden, Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasContainerCollection, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, - Html\Attribute\Custom\HasTemplate, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, Html\Attribute\FormControl\HasForm, @@ -28,13 +25,16 @@ Html\Attribute\FormControl\Label\HasLabelAttributes, Html\Attribute\FormControl\Label\HasLabelClass, Html\Attribute\FormControl\Label\HasLabelFor, - Html\Attribute\HasClass, - Html\Attribute\HasData, - Html\Attribute\HasId, - Html\Attribute\HasLang, - Html\Attribute\HasStyle, - Html\Attribute\HasTabindex, - Html\Attribute\HasTitle, + Html\Attribute\Global\CanBeAutofocus, + Html\Attribute\Global\CanBeHidden, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasData, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasLang, + Html\Attribute\Global\HasStyle, + Html\Attribute\Global\HasTabindex, + Html\Attribute\Global\HasTitle, + Html\Attribute\HasTemplate, Html\Attribute\Input\HasValue, Html\FormControl\Label, Html\Helper\Utils, diff --git a/src/FormControl/Input/Base/AbstractHidden.php b/src/FormControl/Input/Base/AbstractHidden.php index bbe18fa6..f8170b9d 100644 --- a/src/FormControl/Input/Base/AbstractHidden.php +++ b/src/FormControl/Input/Base/AbstractHidden.php @@ -6,11 +6,11 @@ use PHPForge\{ Html\Attribute\Custom\HasAttributes, - Html\Attribute\Custom\HasTemplate, Html\Attribute\FormControl\HasName, - Html\Attribute\HasClass, - Html\Attribute\HasId, - Html\Attribute\HasStyle, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasStyle, + Html\Attribute\HasTemplate, Html\Attribute\Input\HasValue, Html\Helper\Utils, Html\Helper\Validator, diff --git a/src/FormControl/Input/Base/AbstractInput.php b/src/FormControl/Input/Base/AbstractInput.php index d74ed222..71a4e242 100644 --- a/src/FormControl/Input/Base/AbstractInput.php +++ b/src/FormControl/Input/Base/AbstractInput.php @@ -7,24 +7,24 @@ use PHPForge\{ Html\Attribute\Aria\HasAriaDescribedBy, Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\CanBeAutofocus, - Html\Attribute\CanBeHidden, Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSuffixCollection, - Html\Attribute\Custom\HasTemplate, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, Html\Attribute\FormControl\HasFieldAttributes, Html\Attribute\FormControl\HasForm, Html\Attribute\FormControl\HasName, - Html\Attribute\HasClass, - Html\Attribute\HasData, - Html\Attribute\HasId, - Html\Attribute\HasLang, - Html\Attribute\HasStyle, - Html\Attribute\HasTabindex, - Html\Attribute\HasTitle, + Html\Attribute\Global\CanBeAutofocus, + Html\Attribute\Global\CanBeHidden, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasData, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasLang, + Html\Attribute\Global\HasStyle, + Html\Attribute\Global\HasTabindex, + Html\Attribute\Global\HasTitle, + Html\Attribute\HasTemplate, Html\Helper\Utils, Html\Interop\AriaDescribedByInterface, Html\Interop\InputInterface, diff --git a/src/FormControl/Input/Base/AbstractInputChoice.php b/src/FormControl/Input/Base/AbstractInputChoice.php index 93d53f3c..1c70588b 100644 --- a/src/FormControl/Input/Base/AbstractInputChoice.php +++ b/src/FormControl/Input/Base/AbstractInputChoice.php @@ -7,16 +7,12 @@ use PHPForge\{ Html\Attribute\Aria\HasAriaDescribedBy, Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\CanBeAutofocus, - Html\Attribute\CanBeHidden, Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasContainerCollection, - Html\Attribute\Custom\HasContent, Html\Attribute\Custom\HasEnclosedByLabel, Html\Attribute\Custom\HasPrefixCollection, Html\Attribute\Custom\HasSeparator, Html\Attribute\Custom\HasSuffixCollection, - Html\Attribute\Custom\HasTemplate, Html\Attribute\Custom\HasUncheckedCollection, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, @@ -30,15 +26,20 @@ Html\Attribute\FormControl\Label\HasLabelAttributes, Html\Attribute\FormControl\Label\HasLabelClass, Html\Attribute\FormControl\Label\HasLabelFor, - Html\Attribute\HasClass, - Html\Attribute\HasData, - Html\Attribute\HasId, - Html\Attribute\HasLang, - Html\Attribute\HasStyle, - Html\Attribute\HasTabindex, - Html\Attribute\HasTitle, + Html\Attribute\Global\CanBeAutofocus, + Html\Attribute\Global\CanBeHidden, + Html\Attribute\Global\HasClass, + Html\Attribute\Global\HasData, + Html\Attribute\Global\HasId, + Html\Attribute\Global\HasLang, + Html\Attribute\Global\HasStyle, + Html\Attribute\Global\HasTabindex, + Html\Attribute\Global\HasTitle, + Html\Attribute\HasContent, + Html\Attribute\HasTemplate, Html\Attribute\Input\HasValue, Html\FormControl\Label, + Html\Helper\Template, Html\Helper\Utils, Html\Helper\Validator, Html\Interop\AriaDescribedByInterface, @@ -167,14 +168,24 @@ protected function buildChoiceTag(string $type): string private function prepareTemplate(string $tag, string $labelTag): string { $tokenValues = [ - '{prefix}' => $this->renderPrefixTag(), + '{prefix}' => $this->renderTag( + $this->prefixContainerAttributes, + $this->prefixContainer, + $this->prefix, + $this->prefixContainerTag + ), '{unchecktag}' => $this->renderUncheckTag($this->getName()), '{tag}' => $tag, '{label}' => $labelTag, - '{suffix}' => $this->renderSuffixTag(), + '{suffix}' => $this->renderTag( + $this->suffixContainerAttributes, + $this->suffixContainer, + $this->suffix, + $this->suffixContainerTag + ), ]; - return $this->renderTemplate($this->template, $tokenValues); + return Template::render($this->template, $tokenValues); } private function renderLabel(string ...$content): string @@ -185,4 +196,12 @@ private function renderLabel(string ...$content): string ->for($this->labelFor ?? $this->getId()) ->render(); } + + private function renderTag(array $attributes, bool $container, string $content, string $tag): string + { + return match ($container) { + true => Tag::widget()->attributes($attributes)->content($content)->tagName($tag)->render(), + false => $content, + }; + } } diff --git a/src/FormControl/Input/Image.php b/src/FormControl/Input/Image.php index 618e7326..806c0afc 100644 --- a/src/FormControl/Input/Image.php +++ b/src/FormControl/Input/Image.php @@ -11,7 +11,7 @@ Attribute\FormControl\HasFormmethod, Attribute\FormControl\HasFormnovalidate, Attribute\FormControl\HasFormtarget, - Attribute\Input\HasHeight, + Attribute\FormControl\HasHeight, Attribute\Input\HasSrc, Attribute\Input\HasValue, Attribute\Input\HasWidth, diff --git a/src/FormControl/Input/Tel.php b/src/FormControl/Input/Tel.php new file mode 100644 index 00000000..29d88871 --- /dev/null +++ b/src/FormControl/Input/Tel.php @@ -0,0 +1,60 @@ +getValue()); + + return $this->renderInputTag($this->attributes); + } +} diff --git a/src/FormControl/Label.php b/src/FormControl/Label.php index a6fffbf8..36c23d59 100644 --- a/src/FormControl/Label.php +++ b/src/FormControl/Label.php @@ -4,7 +4,7 @@ namespace PHPForge\Html\FormControl; -use PHPForge\Html\{Attribute\Custom\HasContent, Attribute\FormControl\HasForm, Base\AbstractElement}; +use PHPForge\Html\{Attribute\HasContent, Attribute\FormControl\HasForm, Base\AbstractElement}; /** * The ` -
+
value
HTML, - Label::widget()->content('value')->suffixContainer(true)->suffix('value')->render() + Label::widget() + ->content('value') + ->suffix('value') + ->suffixAttributes(['class' => 'value']) + ->suffixTag('div') + ->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( << HTML, - Label::widget() - ->content('value') - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerAttributes(['class' => 'value']) - ->render() + Label::widget()->content('value')->suffix('value')->suffixClass('value')->suffixTag('div')->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( <<value -
- value -
+ value HTML, - Label::widget() - ->content('value') - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerClass('value') - ->render() + Label::widget()->content('value')->suffix('value')->suffixTag('span')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTagWithFalseValue(): void { Assert::equalsWithoutLE( <<value - value + value HTML, - Label::widget() - ->content('value') - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerTag('span') - ->render() + Label::widget()->content('value')->suffix('value')->suffixTag(false)->render() ); } diff --git a/tests/FormControl/Select/CustomMethodTest.php b/tests/FormControl/Select/CustomMethodTest.php index 5f61ac14..f86a52b9 100644 --- a/tests/FormControl/Select/CustomMethodTest.php +++ b/tests/FormControl/Select/CustomMethodTest.php @@ -137,7 +137,9 @@ public function testPrefix(): void { Assert::equalsWithoutLE( << + value +
HTML, - Select::widget()->items($this->cities)->prefix('prefix')->render() + Select::widget()->items($this->cities)->prefix('value')->render() ); } - public function testPrefixContainer(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << - prefix +
+ value
HTML, - Select::widget()->items($this->cities)->prefixContainer(true)->prefix('prefix')->render() + Select::widget()->items($this->cities)->prefix('value')->prefixAttributes(['class' => 'value'])->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << - prefix + value HTML, - Select::widget() - ->items($this->cities) - ->prefixContainer(true) - ->prefix('prefix') - ->prefixContainerClass('value') - ->render() + Select::widget()->items($this->cities)->prefix('value')->prefixClass('value')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( <<prefix + value HTML, - Select::widget() - ->items($this->cities) - ->prefixContainer(true) - ->prefix('prefix') - ->prefixContainerTag('span') - ->render() + Select::widget()->items($this->cities)->prefix('value')->prefixTag('span')->render() ); } - public function testSuffix(): void + public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( << @@ -226,13 +219,12 @@ public function testSuffix(): void - value HTML, - Select::widget()->items($this->cities)->suffix('value')->render() + Select::widget()->items($this->cities)->prefix('value')->prefixTag(false)->render() ); } - public function testSuffixContainer(): void + public function testSuffix(): void { Assert::equalsWithoutLE( << HTML, - Select::widget()->items($this->cities)->suffixContainer(true)->suffix('value')->render() + Select::widget()->items($this->cities)->suffix('value')->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixAttributes(): void { Assert::equalsWithoutLE( << HTML, - Select::widget() - ->items([1 => 'Moscu']) - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerAttributes(['class' => 'value']) - ->render() + Select::widget()->items([1 => 'Moscu'])->suffix('value')->suffixAttributes(['class' => 'value'])->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( << HTML, - Select::widget() - ->items([1 => 'Moscu']) - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerClass('value') - ->render() + Select::widget()->items([1 => 'Moscu'])->suffix('value')->suffixClass('value')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( << value HTML, - Select::widget() - ->items([1 => 'Moscu']) - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerTag('span') - ->render() + Select::widget()->items([1 => 'Moscu'])->suffix('value')->suffixTag('span')->render() + ); + } + + public function testSuffixTagWithFalseValue(): void + { + Assert::equalsWithoutLE( + << + + + + value + HTML, + Select::widget()->items([1 => 'Moscu'])->suffix('value')->suffixTag(false)->render() ); } } diff --git a/tests/FormControl/TextArea/CustomMethodTest.php b/tests/FormControl/TextArea/CustomMethodTest.php index 1edc9e55..dba65dd2 100644 --- a/tests/FormControl/TextArea/CustomMethodTest.php +++ b/tests/FormControl/TextArea/CustomMethodTest.php @@ -26,75 +26,68 @@ public function testPrefix(): void { Assert::equalsWithoutLE( << HTML, - TextArea::widget()->id('textarea-659fc6087e75b')->prefix('prefix')->render() + TextArea::widget()->id('textarea-659fc6087e75b')->prefix('value')->render() ); } - public function testPrefixContainer(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << - prefix +
+ value
HTML, - TextArea::widget()->id('textarea-659fc6087e75b')->prefixContainer(true)->prefix('prefix')->render() + TextArea::widget() + ->id('textarea-659fc6087e75b') + ->prefix('value') + ->prefixAttributes(['class' => 'value']) + ->prefixTag('div') + ->render() ); } - public function testPrefixContainerAttributes(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << - prefix + value HTML, TextArea::widget() ->id('textarea-659fc6087e75b') - ->prefixContainer(true) - ->prefix('prefix') - ->prefixContainerAttributes(['class' => 'value']) + ->prefix('value') + ->prefixClass('value') + ->prefixTag('div') ->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( << - prefix - + value HTML, - TextArea::widget() - ->id('textarea-659fc6087e75b') - ->prefixContainer(true) - ->prefix('prefix') - ->prefixContainerClass('value') - ->render() + TextArea::widget()->id('textarea-659fc6087e75b')->prefix('value')->prefixTag('span')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( <<prefix + value HTML, - TextArea::widget() - ->id('textarea-659fc6087e75b') - ->prefixContainer(true) - ->prefix('prefix') - ->prefixContainerTag('span') - ->render() + TextArea::widget()->id('textarea-659fc6087e75b')->prefix('value')->prefixTag(false)->render() ); } @@ -113,74 +106,67 @@ public function testSuffix(): void Assert::equalsWithoutLE( << - suffix + value HTML, - TextArea::widget()->id('textarea-659fc6087e75b')->suffix('suffix')->render() + TextArea::widget()->id('textarea-659fc6087e75b')->suffix('value')->render() ); } - public function testSuffixContainer(): void + public function testSuffixAttributes(): void { Assert::equalsWithoutLE( << -
- suffix +
+ value
HTML, - TextArea::widget()->id('textarea-659fc6087e75b')->suffixContainer(true)->suffix('suffix')->render() + TextArea::widget() + ->id('textarea-659fc6087e75b') + ->suffix('value') + ->suffixAttributes(['class' => 'value']) + ->suffixTag('div') + ->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( <<
- suffix + value
HTML, TextArea::widget() ->id('textarea-659fc6087e75b') - ->suffixContainer(true) - ->suffix('suffix') - ->suffixContainerAttributes(['class' => 'value']) + ->suffix('value') + ->suffixClass('value') + ->suffixTag('div') ->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( << -
- suffix -
+ value HTML, - TextArea::widget() - ->id('textarea-659fc6087e75b') - ->suffixContainer(true) - ->suffix('suffix') - ->suffixContainerClass('value') - ->render() + TextArea::widget()->id('textarea-659fc6087e75b')->suffix('value')->suffixTag('span')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTagWithFalseValue(): void { Assert::equalsWithoutLE( << - suffix + value HTML, - TextArea::widget() - ->id('textarea-659fc6087e75b') - ->suffixContainer(true) - ->suffix('suffix') - ->suffixContainerTag('span') - ->render() + TextArea::widget()->id('textarea-659fc6087e75b')->suffix('value')->suffixTag(false)->render() ); } diff --git a/tests/Mutlimedia/Img/CustomMethodTest.php b/tests/Mutlimedia/Img/CustomMethodTest.php index 3fe7f981..de61a18e 100644 --- a/tests/Mutlimedia/Img/CustomMethodTest.php +++ b/tests/Mutlimedia/Img/CustomMethodTest.php @@ -23,20 +23,20 @@ public function testPrefix(): void ); } - public function testPrefixContainer(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << +
value
HTML, - Img::widget()->prefixContainer(true)->prefix('value')->render() + Img::widget()->prefix('value')->prefixAttributes(['class' => 'value'])->prefixTag('div')->render() ); } - public function testPrefixContainerAttributes(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << HTML, - Img::widget() - ->prefixContainer(true) - ->prefix('value') - ->prefixContainerAttributes(['class' => 'value']) - ->render() + Img::widget()->prefix('value')->prefixClass('value')->prefixTag('div')->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( << - value -
+ value HTML, - Img::widget()->prefixContainer(true)->prefix('value')->prefixContainerClass('value')->render() + Img::widget()->prefix('value')->prefixTag('span')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( <<value + value HTML, - Img::widget()->prefixContainer(true)->prefix('value')->prefixContainerTag('span')->render() + Img::widget()->prefix('value')->prefixTag(false)->render() ); } @@ -98,20 +92,20 @@ public function testSuffix(): void ); } - public function testSuffixContainer(): void + public function testSuffixAttributes(): void { Assert::equalsWithoutLE( << -
+
value
HTML, - Img::widget()->suffixContainer(true)->suffix('value')->render() + Img::widget()->suffix('value')->suffixAttributes(['class' => 'value'])->suffixTag('div')->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( << HTML, - Img::widget() - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerAttributes(['class' => 'value']) - ->render() + Img::widget()->suffix('value')->suffixClass('value')->suffixTag('div')->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( << -
- value -
+ value HTML, - Img::widget()->suffixContainer(true)->suffix('value')->suffixContainerClass('value')->render() + Img::widget()->suffix('value')->suffixTag('span')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTagWithFalseValue(): void { Assert::equalsWithoutLE( << - value + value HTML, - Img::widget()->suffixContainer(true)->suffix('value')->suffixContainerTag('span')->render() + Img::widget()->suffix('value')->suffixTag(false)->render() ); } diff --git a/tests/Tag/CustomMethodTest.php b/tests/Tag/CustomMethodTest.php index 8cba7952..187543c2 100644 --- a/tests/Tag/CustomMethodTest.php +++ b/tests/Tag/CustomMethodTest.php @@ -16,165 +16,141 @@ public function testPrefix(): void { Assert::equalsWithoutLE( << HTML, - Tag::widget()->prefix('prefix')->tagName('span')->render() + Tag::widget()->prefix('value')->tagName('span')->render() ); } - public function testPrefixContainer(): void - { - Assert::equalsWithoutLE( - << - prefix -
- - HTML, - Tag::widget()->prefix('prefix')->prefixContainer(true)->tagName('span')->render() - ); - } - - public function testPrefixContainerAttributes(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << - prefix + value HTML, Tag::widget() - ->prefix('prefix') - ->prefixContainer(true) - ->prefixContainerAttributes(['class' => 'value']) + ->prefix('value') + ->prefixAttributes(['class' => 'value']) + ->prefixTag('div') ->tagName('span') ->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << - prefix + value HTML, - Tag::widget() - ->prefix('prefix') - ->prefixContainer(true) - ->prefixContainerClass('value') - ->tagName('span') - ->render() + Tag::widget()->prefix('value')->prefixClass('value')->prefixTag('div')->tagName('span')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( << - prefix + value

HTML, - Tag::widget() - ->prefix('prefix') - ->prefixContainer(true) - ->prefixContainerTag('p') - ->tagName('span') - ->render() + Tag::widget()->prefix('value')->prefixTag('p')->tagName('span')->render() ); } - public function testRender(): void + public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( << HTML, - Tag::widget()->tagName('span')->render() + Tag::widget()->prefix('value')->prefixTag(false)->tagName('span')->render() ); } - public function testSuffix(): void + public function testRender(): void { Assert::equalsWithoutLE( << - suffix HTML, - Tag::widget()->suffix('suffix')->tagName('span')->render() + Tag::widget()->tagName('span')->render() ); } - public function testSuffixContainer(): void + public function testSuffix(): void { Assert::equalsWithoutLE( << -
- suffix -
+ value HTML, - Tag::widget()->suffix('suffix')->suffixContainer(true)->tagName('span')->render() + Tag::widget()->suffix('value')->tagName('span')->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixAttributes(): void { Assert::equalsWithoutLE( <<
- suffix + value
HTML, Tag::widget() - ->suffix('suffix') - ->suffixContainer(true) - ->suffixContainerAttributes(['class' => 'value']) + ->suffix('value') + ->suffixAttributes(['class' => 'value']) + ->suffixTag('div') ->tagName('span') ->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( <<
- suffix + value
HTML, - Tag::widget() - ->suffix('suffix') - ->suffixContainer(true) - ->suffixContainerClass('value') - ->tagName('span') - ->render() + Tag::widget()->suffix('value')->suffixClass('value')->suffixTag('div')->tagName('span')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( <<

- suffix + value

HTML, - Tag::widget() - ->suffix('suffix') - ->suffixContainer(true) - ->suffixContainerTag('p') - ->tagName('span') - ->render() + Tag::widget()->suffix('value')->suffixTag('p')->tagName('span')->render() + ); + } + + public function testSuffixTagWithFalseValue(): void + { + Assert::equalsWithoutLE( + << + value + HTML, + Tag::widget()->suffix('value')->suffixTag(false)->tagName('span')->render() ); } diff --git a/tests/Textual/A/CustomMethodTest.php b/tests/Textual/A/CustomMethodTest.php index 4c415790..fc08670a 100644 --- a/tests/Textual/A/CustomMethodTest.php +++ b/tests/Textual/A/CustomMethodTest.php @@ -23,20 +23,20 @@ public function testPrefix(): void ); } - public function testPrefixContainer(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << +
value
HTML, - A::widget()->prefixContainer(true)->prefix('value')->render() + A::widget()->prefix('value')->prefixAttributes(['class' => 'value'])->prefixTag('div')->render() ); } - public function testPrefixContainerAttributes(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << HTML, - A::widget() - ->prefixContainer(true) - ->prefix('value') - ->prefixContainerAttributes(['class' => 'value']) - ->render() + A::widget()->prefix('value')->prefixClass('value')->prefixTag('div')->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( << - value - + value HTML, - A::widget()->prefixContainer(true)->prefix('value')->prefixContainerClass('value')->render() + A::widget()->prefix('value')->prefixTag('span')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( <<value + value HTML, - A::widget()->prefixContainer(true)->prefix('value')->prefixContainerTag('span')->render() + A::widget()->prefix('value')->prefixTag(false)->render() ); } @@ -98,20 +92,20 @@ public function testSuffix(): void ); } - public function testSuffixContainer(): void + public function testSuffixAttributes(): void { Assert::equalsWithoutLE( << -
+
value
HTML, - A::widget()->suffixContainer(true)->suffix('value')->render() + A::widget()->suffix('value')->suffixAttributes(['class' => 'value'])->suffixTag('div')->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( << HTML, - A::widget() - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerAttributes(['class' => 'value']) - ->render() + A::widget()->suffix('value')->suffixClass('value')->suffixTag('div')->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( << -
- value -
+ value HTML, - A::widget()->suffixContainer(true)->suffix('value')->suffixContainerClass('value')->render() + A::widget()->suffix('value')->suffixTag('span')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTagWithFalseValue(): void { Assert::equalsWithoutLE( << - value + value HTML, - A::widget()->suffixContainer(true)->suffix('value')->suffixContainerTag('span')->render() + A::widget()->suffix('value')->suffixTag(false)->render() ); } diff --git a/tests/Textual/I/CustomMethodTest.php b/tests/Textual/I/CustomMethodTest.php index 70e88377..7e6bb6a5 100644 --- a/tests/Textual/I/CustomMethodTest.php +++ b/tests/Textual/I/CustomMethodTest.php @@ -23,20 +23,20 @@ public function testPrefix(): void ); } - public function testPrefixContainer(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << +
value
HTML, - I::widget()->prefixContainer(true)->prefix('value')->render() + I::widget()->prefix('value')->prefixAttributes(['class' => 'value'])->prefixTag('div')->render() ); } - public function testPrefixContainerAttributes(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << HTML, - I::widget() - ->prefixContainer(true) - ->prefix('value') - ->prefixContainerAttributes(['class' => 'value']) - ->render() + I::widget()->prefix('value')->prefixClass('value')->prefixTag('div')->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( << - value -
+ value HTML, - I::widget()->prefixContainer(true)->prefix('value')->prefixContainerClass('value')->render() + I::widget()->prefix('value')->prefixTag('span')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( <<value + value HTML, - I::widget()->prefixContainer(true)->prefix('value')->prefixContainerTag('span')->render() + I::widget()->prefix('value')->prefixTag(false)->render() ); } @@ -98,20 +92,20 @@ public function testSuffix(): void ); } - public function testSuffixContainer(): void + public function testSuffixAttributes(): void { Assert::equalsWithoutLE( <<
-
+
value
HTML, - I::widget()->suffixContainer(true)->suffix('value')->render() + I::widget()->suffix('value')->suffixAttributes(['class' => 'value'])->suffixTag('div')->render() ); } - public function testSuffixContainerAttributes(): void + public function testSuffixClass(): void { Assert::equalsWithoutLE( << HTML, - I::widget() - ->suffixContainer(true) - ->suffix('value') - ->suffixContainerAttributes(['class' => 'value']) - ->render() + I::widget()->suffix('value')->suffixClass('value')->suffixTag('div')->render() ); } - public function testSuffixContainerClass(): void + public function testSuffixTag(): void { Assert::equalsWithoutLE( << -
- value -
+ value HTML, - I::widget()->suffixContainer(true)->suffix('value')->suffixContainerClass('value')->render() + I::widget()->suffix('value')->suffixTag('span')->render() ); } - public function testSuffixContainerTag(): void + public function testSuffixTagWithFalseValue(): void { Assert::equalsWithoutLE( << - value + value HTML, - I::widget()->suffixContainer(true)->suffix('value')->suffixContainerTag('span')->render() + I::widget()->suffix('value')->suffixTag(false)->render() ); } diff --git a/tests/Textual/Span/CustomMethodTest.php b/tests/Textual/Span/CustomMethodTest.php index 6af6d36b..deb230e7 100644 --- a/tests/Textual/Span/CustomMethodTest.php +++ b/tests/Textual/Span/CustomMethodTest.php @@ -12,20 +12,18 @@ */ final class CustomMethodTest extends TestCase { - public function testPrefixContainer(): void + public function testPrefix(): void { Assert::equalsWithoutLE( << value -
HTML, - Span::widget()->prefix('value')->prefixContainer(true)->render() + Span::widget()->prefix('value')->render() ); } - public function testPrefixContainerAttributes(): void + public function testPrefixAttributes(): void { Assert::equalsWithoutLE( << HTML, - Span::widget() - ->prefix('value') - ->prefixContainer(true) - ->prefixContainerAttributes(['class' => 'value']) - ->render() + Span::widget()->prefix('value')->prefixAttributes(['class' => 'value'])->prefixTag('div')->render() ); } - public function testPrefixContainerClass(): void + public function testPrefixClass(): void { Assert::equalsWithoutLE( << HTML, - Span::widget()->prefix('value')->prefixContainer(true)->prefixContainerClass('value')->render() + Span::widget()->prefix('value')->prefixClass('value')->prefixTag('div')->render() ); } - public function testPrefixContainerTag(): void + public function testPrefixTag(): void { Assert::equalsWithoutLE( << HTML, - Span::widget()->prefix('value')->prefixContainer(true)->prefixContainerTag('div')->render() + Span::widget()->prefix('value')->prefixTag('div')->render() + ); + } + + public function testPrefixTagWithFalseValue(): void + { + Assert::equalsWithoutLE( + << + HTML, + Span::widget()->prefix('value')->prefixTag(false)->render() ); } @@ -78,6 +83,67 @@ public function testRender(): void ); } + public function testSuffix(): void + { + Assert::equalsWithoutLE( + << + value + HTML, + Span::widget()->suffix('value')->render() + ); + } + + public function testSuffixAttributes(): void + { + Assert::equalsWithoutLE( + << +
+ value +
+ HTML, + Span::widget()->suffix('value')->suffixAttributes(['class' => 'value'])->suffixTag('div')->render() + ); + } + + public function testSuffixClass(): void + { + Assert::equalsWithoutLE( + << +
+ value +
+ HTML, + Span::widget()->suffix('value')->suffixClass('value')->suffixTag('div')->render() + ); + } + + public function testSuffixTag(): void + { + Assert::equalsWithoutLE( + << +
+ value +
+ HTML, + Span::widget()->suffix('value')->suffixTag('div')->render() + ); + } + + public function testSuffixTagWithFalseValue(): void + { + Assert::equalsWithoutLE( + << + value + HTML, + Span::widget()->suffix('value')->suffixTag(false)->render() + ); + } + public function testTemplate(): void { Assert::equalsWithoutLE( From 347d5810ff0733db889c1371697145dda81b7ac2 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Mar 2024 11:33:52 +0000 Subject: [PATCH 22/25] Apply fixes from StyleCI --- tests/FormControl/Input/Button/CustomMethodTest.php | 1 - tests/FormControl/Input/Email/CustomMethodTest.php | 1 - tests/FormControl/Input/Radio/CustomMethodTest.php | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/FormControl/Input/Button/CustomMethodTest.php b/tests/FormControl/Input/Button/CustomMethodTest.php index d95eb0a2..6cf1a86c 100644 --- a/tests/FormControl/Input/Button/CustomMethodTest.php +++ b/tests/FormControl/Input/Button/CustomMethodTest.php @@ -119,7 +119,6 @@ public function testPrefixClass(): void ); } - public function testPrefixTag(): void { Assert::equalsWithoutLE( diff --git a/tests/FormControl/Input/Email/CustomMethodTest.php b/tests/FormControl/Input/Email/CustomMethodTest.php index aaa51668..a0f9527f 100644 --- a/tests/FormControl/Input/Email/CustomMethodTest.php +++ b/tests/FormControl/Input/Email/CustomMethodTest.php @@ -159,7 +159,6 @@ public function testSuffixTag(): void ); } - public function testSuffixTagWithFalseValue(): void { Assert::equalsWithoutLE( diff --git a/tests/FormControl/Input/Radio/CustomMethodTest.php b/tests/FormControl/Input/Radio/CustomMethodTest.php index 223daa7e..01a643cd 100644 --- a/tests/FormControl/Input/Radio/CustomMethodTest.php +++ b/tests/FormControl/Input/Radio/CustomMethodTest.php @@ -147,7 +147,6 @@ public function testPrefixTag(): void ); } - public function testPrefixTagWithFalseValue(): void { Assert::equalsWithoutLE( From b3d562b0cfc9bc06f9026eefbc58e9c0d1c24949 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 4 Mar 2024 08:36:59 -0300 Subject: [PATCH 23/25] Fix ecs tests. --- tests/FormControl/Input/DatetimeLocal/CustomMethodTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FormControl/Input/DatetimeLocal/CustomMethodTest.php b/tests/FormControl/Input/DatetimeLocal/CustomMethodTest.php index fe943db1..f6f5020b 100644 --- a/tests/FormControl/Input/DatetimeLocal/CustomMethodTest.php +++ b/tests/FormControl/Input/DatetimeLocal/CustomMethodTest.php @@ -126,7 +126,7 @@ public function testSuffixAttributes(): void DatetimeLocal::widget() ->id('datetime-local-6582f2d099e8b') ->suffix('value') - ->suffixAttributes(['class' => 'value',]) + ->suffixAttributes(['class' => 'value']) ->suffixTag('div') ->render() ); From 44129f9e8ecbb7d5e925dab97a78512a5805e457 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 4 Mar 2024 09:05:43 -0300 Subject: [PATCH 24/25] Refactor attribute imports in PHPForge classes. --- src/Attribute/Custom/HasAttributes.php | 31 ------------------- src/Base/AbstractBlockElement.php | 5 ++- src/Base/AbstractElement.php | 4 +-- src/Base/AbstractSvg.php | 3 +- src/FormControl/Base/AbstractForm.php | 4 +-- src/FormControl/Base/AbstractSelect.php | 4 +-- src/FormControl/Button.php | 3 +- src/FormControl/Input/Base/AbstractButton.php | 3 +- src/FormControl/Input/Base/AbstractHidden.php | 4 +-- src/FormControl/Input/Base/AbstractInput.php | 3 +- .../Input/Base/AbstractInputChoice.php | 3 +- src/Group/Base/AbstractLi.php | 3 +- src/Group/Base/AbstractList.php | 3 +- src/Metadata/Meta.php | 4 +-- 14 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 src/Attribute/Custom/HasAttributes.php diff --git a/src/Attribute/Custom/HasAttributes.php b/src/Attribute/Custom/HasAttributes.php deleted file mode 100644 index c30d223c..00000000 --- a/src/Attribute/Custom/HasAttributes.php +++ /dev/null @@ -1,31 +0,0 @@ -attributes = array_merge($this->attributes, $values); - - return $new; - } -} diff --git a/src/Base/AbstractBlockElement.php b/src/Base/AbstractBlockElement.php index 80c6aed9..78aebf35 100644 --- a/src/Base/AbstractBlockElement.php +++ b/src/Base/AbstractBlockElement.php @@ -5,13 +5,13 @@ namespace PHPForge\Html\Base; use PHPForge\Html\{ - Attribute\Custom\HasAttributes, Attribute\Global\HasClass, Attribute\Global\HasData, Attribute\Global\HasId, Attribute\Global\HasLang, Attribute\Global\HasStyle, Attribute\Global\HasTitle, + Attribute\HasAttributes, Attribute\HasContent, HtmlBuilder }; @@ -30,8 +30,7 @@ abstract class AbstractBlockElement extends Block use HasLang; use HasStyle; use HasTitle; - - protected array $attributes = []; + protected string $tagName = ''; /** diff --git a/src/Base/AbstractElement.php b/src/Base/AbstractElement.php index 4fb26b49..d7e6a87b 100644 --- a/src/Base/AbstractElement.php +++ b/src/Base/AbstractElement.php @@ -5,13 +5,13 @@ namespace PHPForge\Html\Base; use PHPForge\{ - Html\Attribute\Custom\HasAttributes, Html\Attribute\Global\HasClass, Html\Attribute\Global\HasData, Html\Attribute\Global\HasId, Html\Attribute\Global\HasLang, Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\HasPrefixCollection, Html\Attribute\HasSuffixCollection, Html\Attribute\HasTemplate, @@ -39,8 +39,6 @@ abstract class AbstractElement extends Element implements RenderInterface use HasTemplate; use HasTitle; - protected array $attributes = []; - /** * This method is used to configure the widget with the provided default definitions. */ diff --git a/src/Base/AbstractSvg.php b/src/Base/AbstractSvg.php index 082aec8b..af2a4100 100644 --- a/src/Base/AbstractSvg.php +++ b/src/Base/AbstractSvg.php @@ -9,12 +9,12 @@ use enshrined\svgSanitize\Sanitizer; use InvalidArgumentException; use PHPForge\{ - Html\Attribute\Custom\HasAttributes, Html\Attribute\FormControl\HasHeight, Html\Attribute\Global\HasClass, Html\Attribute\Global\HasId, Html\Attribute\Global\HasLang, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\HasContent, Html\Attribute\Input\HasWidth, Html\Tag, @@ -38,7 +38,6 @@ abstract class AbstractSvg extends Element use HasTitle; use HasWidth; - protected array $attributes = []; private string $filePath = ''; /** diff --git a/src/FormControl/Base/AbstractForm.php b/src/FormControl/Base/AbstractForm.php index a97a84e9..ec81fd46 100644 --- a/src/FormControl/Base/AbstractForm.php +++ b/src/FormControl/Base/AbstractForm.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\FormControl\Base; use PHPForge\Html\{ - Attribute\Custom\HasAttributes, Attribute\Custom\HasCsrf, Attribute\FormControl\HasAccept, Attribute\FormControl\HasAutocomplete, @@ -15,6 +14,7 @@ Attribute\Global\HasLang, Attribute\Global\HasStyle, Attribute\Global\HasTitle, + Attribute\HasAttributes, Attribute\HasContent, Attribute\Tag\CanBeNoValidate, Attribute\Tag\HasAction, @@ -54,8 +54,6 @@ abstract class AbstractForm extends Block use HasStyle; use HasTitle; - protected array $attributes = []; - /** * Begin rendering the block element. * diff --git a/src/FormControl/Base/AbstractSelect.php b/src/FormControl/Base/AbstractSelect.php index c10c2edf..16285410 100644 --- a/src/FormControl/Base/AbstractSelect.php +++ b/src/FormControl/Base/AbstractSelect.php @@ -7,7 +7,6 @@ use InvalidArgumentException; use PHPForge\{ Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\Custom\HasAttributes, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeMultiple, Html\Attribute\FormControl\CanBeRequired, @@ -20,6 +19,7 @@ Html\Attribute\Global\HasId, Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, + Html\Attribute\HasAttributes, Html\Attribute\HasPrefixCollection, Html\Attribute\HasSuffixCollection, Html\Attribute\Input\HasSize, @@ -77,8 +77,6 @@ abstract class AbstractSelect extends Element implements use HasTabindex; use HasValue; - protected array $attributes = []; - protected function run(): string { /** @psalm-var array|scalar|object|null $value */ diff --git a/src/FormControl/Button.php b/src/FormControl/Button.php index a2ce7adb..3d42e8f8 100644 --- a/src/FormControl/Button.php +++ b/src/FormControl/Button.php @@ -11,7 +11,6 @@ Html\Attribute\Aria\HasAriaExpanded, Html\Attribute\Aria\HasAriaLabel, Html\Attribute\Aria\HasRole, - Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasContainerCollection, Html\Attribute\Custom\HasTagName, Html\Attribute\FormControl\HasFormaction, @@ -27,6 +26,7 @@ Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\HasContent, Html\Attribute\HasPrefixCollection, Html\Attribute\HasSuffixCollection, @@ -73,7 +73,6 @@ final class Button extends Element use HasTemplate; use HasTitle; - protected array $attributes = []; protected string $type = 'button'; /** diff --git a/src/FormControl/Input/Base/AbstractButton.php b/src/FormControl/Input/Base/AbstractButton.php index a7d33098..5e11e752 100644 --- a/src/FormControl/Input/Base/AbstractButton.php +++ b/src/FormControl/Input/Base/AbstractButton.php @@ -7,7 +7,6 @@ use PHPForge\{ Html\Attribute\Aria\HasAriaDescribedBy, Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasContainerCollection, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, @@ -28,6 +27,7 @@ Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\HasPrefixCollection, Html\Attribute\HasSuffixCollection, Html\Attribute\HasTemplate, @@ -69,7 +69,6 @@ abstract class AbstractButton extends Element use HasTitle; use HasValue; - protected array $attributes = []; protected string $type = 'button'; /** diff --git a/src/FormControl/Input/Base/AbstractHidden.php b/src/FormControl/Input/Base/AbstractHidden.php index f8170b9d..9f6d9cd4 100644 --- a/src/FormControl/Input/Base/AbstractHidden.php +++ b/src/FormControl/Input/Base/AbstractHidden.php @@ -5,11 +5,11 @@ namespace PHPForge\Html\FormControl\Input\Base; use PHPForge\{ - Html\Attribute\Custom\HasAttributes, Html\Attribute\FormControl\HasName, Html\Attribute\Global\HasClass, Html\Attribute\Global\HasId, Html\Attribute\Global\HasStyle, + Html\Attribute\HasAttributes, Html\Attribute\HasTemplate, Html\Attribute\Input\HasValue, Html\Helper\Utils, @@ -29,8 +29,6 @@ abstract class AbstractHidden extends Element implements ValueInterface use HasTemplate; use HasValue; - protected array $attributes = []; - /** * This method is used to configure the widget with the provided default definitions. */ diff --git a/src/FormControl/Input/Base/AbstractInput.php b/src/FormControl/Input/Base/AbstractInput.php index aae6726e..133e7c99 100644 --- a/src/FormControl/Input/Base/AbstractInput.php +++ b/src/FormControl/Input/Base/AbstractInput.php @@ -7,7 +7,6 @@ use PHPForge\{ Html\Attribute\Aria\HasAriaDescribedBy, Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\Custom\HasAttributes, Html\Attribute\FormControl\CanBeDisabled, Html\Attribute\FormControl\CanBeReadonly, Html\Attribute\FormControl\HasFieldAttributes, @@ -22,6 +21,7 @@ Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\HasPrefixCollection, Html\Attribute\HasSuffixCollection, Html\Attribute\HasTemplate, @@ -59,7 +59,6 @@ abstract class AbstractInput extends Element implements AriaDescribedByInterface use HasTemplate; use HasTitle; - protected array $attributes = []; protected string $type = 'text'; /** diff --git a/src/FormControl/Input/Base/AbstractInputChoice.php b/src/FormControl/Input/Base/AbstractInputChoice.php index b4d44ac5..3ce78dda 100644 --- a/src/FormControl/Input/Base/AbstractInputChoice.php +++ b/src/FormControl/Input/Base/AbstractInputChoice.php @@ -7,7 +7,6 @@ use PHPForge\{ Html\Attribute\Aria\HasAriaDescribedBy, Html\Attribute\Aria\HasAriaLabel, - Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasContainerCollection, Html\Attribute\Custom\HasEnclosedByLabel, Html\Attribute\Custom\HasSeparator, @@ -29,6 +28,7 @@ Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\HasContent, Html\Attribute\HasPrefixCollection, Html\Attribute\HasSuffixCollection, @@ -89,7 +89,6 @@ abstract class AbstractInputChoice extends Element implements use HasUncheckedCollection; use HasValue; - protected array $attributes = []; protected string $tagName = ''; /** diff --git a/src/Group/Base/AbstractLi.php b/src/Group/Base/AbstractLi.php index ade69457..db2e25e0 100644 --- a/src/Group/Base/AbstractLi.php +++ b/src/Group/Base/AbstractLi.php @@ -5,13 +5,13 @@ namespace PHPForge\Html\Group\Base; use PHPForge\{ - Html\Attribute\Custom\HasAttributes, Html\Attribute\Global\HasClass, Html\Attribute\Global\HasId, Html\Attribute\Global\HasLang, Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Attribute\Input\HasValue, Html\Interop\RenderInterface, Html\Tag, @@ -34,7 +34,6 @@ abstract class AbstractLi extends Element implements RenderInterface use HasTitle; use HasValue; - protected array $attributes = []; protected string $content = ''; /** diff --git a/src/Group/Base/AbstractList.php b/src/Group/Base/AbstractList.php index fdf853ae..aa1ea6af 100644 --- a/src/Group/Base/AbstractList.php +++ b/src/Group/Base/AbstractList.php @@ -5,7 +5,6 @@ namespace PHPForge\Html\Group\Base; use PHPForge\{ - Html\Attribute\Custom\HasAttributes, Html\Attribute\Custom\HasTagName, Html\Attribute\Global\HasClass, Html\Attribute\Global\HasId, @@ -13,6 +12,7 @@ Html\Attribute\Global\HasStyle, Html\Attribute\Global\HasTabindex, Html\Attribute\Global\HasTitle, + Html\Attribute\HasAttributes, Html\Interop\RenderInterface, Html\Tag, Widget\Element @@ -34,7 +34,6 @@ abstract class AbstractList extends Element implements RenderInterface use HasTagName; use HasTitle; - protected array $attributes = []; protected string $content = ''; /** diff --git a/src/Metadata/Meta.php b/src/Metadata/Meta.php index d2e5b100..9029da20 100644 --- a/src/Metadata/Meta.php +++ b/src/Metadata/Meta.php @@ -5,13 +5,13 @@ namespace PHPForge\Html\Metadata; use PHPForge\Html\{ - Attribute\Custom\HasAttributes, Attribute\Custom\HasContentAttribute, Attribute\FormControl\HasName, Attribute\Global\HasClass, Attribute\Global\HasId, Attribute\Global\HasLang, Attribute\Global\HasStyle, + Attribute\HasAttributes, Attribute\Tag\HasCharset, Attribute\Tag\HasHttpEquiv, Tag @@ -36,8 +36,6 @@ final class Meta extends Element use HasName; use HasStyle; - private array $attributes = []; - /** * Generate the HTML representation of the element. * From 0fcef0e8b940cdeca322ab7b68a719c4d3a79bcd Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Mar 2024 12:06:08 +0000 Subject: [PATCH 25/25] Apply fixes from StyleCI --- src/Base/AbstractBlockElement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Base/AbstractBlockElement.php b/src/Base/AbstractBlockElement.php index 78aebf35..cb1e210b 100644 --- a/src/Base/AbstractBlockElement.php +++ b/src/Base/AbstractBlockElement.php @@ -30,7 +30,7 @@ abstract class AbstractBlockElement extends Block use HasLang; use HasStyle; use HasTitle; - + protected string $tagName = ''; /**