Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ValidatorDispatcher.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\RichText;
8
9 use eZ\Publish\Core\Base\Exceptions\NotFoundException;
10 use DOMDocument;
11
17 class ValidatorDispatcher
18 {
24 protected $mapping = [];
25
29 public function __construct($validatorMap)
30 {
31 foreach ($validatorMap as $namespace => $validator) {
32 $this->addValidator($namespace, $validator);
33 }
34 }
35
42 public function addValidator($namespace, Validator $validator = null)
43 {
44 $this->mapping[$namespace] = $validator;
45 }
46
56 public function dispatch(DOMDocument $document)
57 {
58 $documentNamespace = $document->documentElement->lookupNamespaceURI(null);
59 // checking for null as ezxml has no default namespace...
60 if ($documentNamespace === null) {
61 $documentNamespace = $document->documentElement->lookupNamespaceURI('xhtml');
62 }
63
64 foreach ($this->mapping as $namespace => $validator) {
65 if ($documentNamespace === $namespace) {
66 if ($validator === null) {
67 return [];
68 }
69
70 return $validator->validate($document);
71 }
72 }
73
74 throw new NotFoundException('Validator', $documentNamespace);
75 }
76 }
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\Core\Base\Exceptions\NotFoundException
Not Found Exception implementation.
Definition: Core/Base/Exceptions/NotFoundException.php:21
eZ\Publish\Core\FieldType\RichText\ValidatorDispatcher
Dispatcher for various validators depending on the XML document namespace.
Definition: ValidatorDispatcher.php:18
eZ\Publish\Core\FieldType\RichText\ValidatorDispatcher\addValidator
addValidator($namespace, Validator $validator=null)
Adds validator mapping.
Definition: ValidatorDispatcher.php:42
eZ\Publish\Core\FieldType\RichText\ValidatorDispatcher\$mapping
$mapping
Definition: ValidatorDispatcher.php:24
eZ\Publish\Core\FieldType\RichText\ValidatorDispatcher\__construct
__construct($validatorMap)
Definition: ValidatorDispatcher.php:29
eZ\Publish\Core\FieldType\RichText\ValidatorDispatcher\dispatch
dispatch(DOMDocument $document)
Dispatches DOMDocument to the namespace mapped validator.
Definition: ValidatorDispatcher.php:56
eZ\Publish\Core\FieldType\RichText\Validator
Validates XML document using ISO Schematron (as XSLT stylesheet), XSD and RELAX NG schemas.
Definition: RichText/Validator.php:21
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.