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

ConverterDispatcher.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 ConverterDispatcher
18 {
24 protected $mapping = [];
25
29 public function __construct($converterMap)
30 {
31 foreach ($converterMap as $namespace => $converter) {
32 $this->addConverter($namespace, $converter);
33 }
34 }
35
42 public function addConverter($namespace, Converter $converter = null)
43 {
44 $this->mapping[$namespace] = $converter;
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 => $converter) {
65 if ($documentNamespace === $namespace) {
66 if ($converter === null) {
67 return $document;
68 }
69
70 return $converter->convert($document);
71 }
72 }
73
74 throw new NotFoundException('Converter', $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\ConverterDispatcher
Dispatcher for various converters depending on the XML document namespace.
Definition: ConverterDispatcher.php:18
eZ\Publish\Core\FieldType\RichText\ConverterDispatcher\$mapping
$mapping
Definition: ConverterDispatcher.php:24
eZ\Publish\Core\FieldType\RichText\ConverterDispatcher\addConverter
addConverter($namespace, Converter $converter=null)
Adds converter mapping.
Definition: ConverterDispatcher.php:42
eZ\Publish\Core\FieldType\RichText\ConverterDispatcher\__construct
__construct($converterMap)
Definition: ConverterDispatcher.php:29
eZ\Publish\Core\FieldType\RichText\ConverterDispatcher\dispatch
dispatch(DOMDocument $document)
Dispatches DOMDocument to the namespace mapped converter.
Definition: ConverterDispatcher.php:56
eZ\Publish\Core\FieldType\RichText\Converter
Interface for rich text conversion.
Definition: FieldType/RichText/Converter.php:17
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.