From a1129d1d867fd28f418c06a288d233f15867734c Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 24 Sep 2024 17:40:35 +1200 Subject: [PATCH] ENH Use symfony/validation logic --- src/PersistedQuery/HTTPProvider.php | 5 ++++- tests/Schema/AbstractTypeRegistryTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PersistedQuery/HTTPProvider.php b/src/PersistedQuery/HTTPProvider.php index 6d35911f..9669bbb1 100644 --- a/src/PersistedQuery/HTTPProvider.php +++ b/src/PersistedQuery/HTTPProvider.php @@ -7,6 +7,9 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Core\Validation\ConstraintValidator; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\Url; /** * Class HTTPProvider @@ -108,7 +111,7 @@ public function getByID(string $queryID, string $schemaKey = 'default'): ?string public function setSchemaMapping(array $mapping): HTTPProvider { foreach ($mapping as $schemaKey => $url) { - if (!filter_var($url, FILTER_VALIDATE_URL)) { + if (!ConstraintValidator::validate($url, [new Url(), new NotBlank()])->isValid()) { throw new InvalidArgumentException( 'setSchemaMapping accepts an array of schema keys to URLs' ); diff --git a/tests/Schema/AbstractTypeRegistryTest.php b/tests/Schema/AbstractTypeRegistryTest.php index 39f8930a..556100f2 100644 --- a/tests/Schema/AbstractTypeRegistryTest.php +++ b/tests/Schema/AbstractTypeRegistryTest.php @@ -139,7 +139,7 @@ public static function provideRebuildOnMissing(): array private function getInstance() { - $registry = new Class extends AbstractTypeRegistry + $registry = new class extends AbstractTypeRegistry { protected static function getSourceDirectory(): string {