Skip to content

Commit

Permalink
NotEmpty Validator Input Filter Affordances
Browse files Browse the repository at this point in the history
InputFilter needs access to the internal message templates of the `NotEmpty` validator in order to present error messages when a required field is empty. This patch re-introduces `getMessageTemplates` only on the NotEmpty validator and marks the method as internal.

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Oct 21, 2024
1 parent 0971d89 commit f0187df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/NotEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,22 @@ public function isValid(mixed $value): bool

return true;
}

/**
* Return the configured message templates
*
* This method is an affordance to laminas-inputfilter.
* It needs to introspect configured message templates in order to provide a default error message for empty inputs.
*
* In future versions of laminas-validator, this method will likely be deprecated and removed. Please avoid.
*
* @internal
*
* @psalm-internal \Laminas
* @return array<string, string>
*/
public function getMessageTemplates(): array
{
return $this->messageTemplates;
}
}
9 changes: 9 additions & 0 deletions test/NotEmptyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,13 @@ public static function arrayConfigNotationWithoutKeyProvider(): array
[null, true],
];
}

public function testRetrievalOfMessageTemplates(): void
{
/** @psalm-suppress InternalMethod */
$templates = (new NotEmpty())->getMessageTemplates();
self::assertNotSame([], $templates);
self::assertArrayHasKey(NotEmpty::IS_EMPTY, $templates);
self::assertArrayHasKey(NotEmpty::INVALID, $templates);
}
}

0 comments on commit f0187df

Please sign in to comment.