From f0187dfa7fd45a4e8ae0eb2e251dae8795b6e6fa Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 21 Oct 2024 10:59:11 +0100 Subject: [PATCH] `NotEmpty` Validator Input Filter Affordances 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 --- src/NotEmpty.php | 18 ++++++++++++++++++ test/NotEmptyTest.php | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/src/NotEmpty.php b/src/NotEmpty.php index 066fe0b2..3cc301bc 100644 --- a/src/NotEmpty.php +++ b/src/NotEmpty.php @@ -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 + */ + public function getMessageTemplates(): array + { + return $this->messageTemplates; + } } diff --git a/test/NotEmptyTest.php b/test/NotEmptyTest.php index 799decac..c8c3268a 100644 --- a/test/NotEmptyTest.php +++ b/test/NotEmptyTest.php @@ -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); + } }