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

DocumentTypeDefinition.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\RichText\Normalizer;
8
9 use eZ\Publish\Core\FieldType\RichText\Normalizer;
10
20 class DocumentTypeDefinition extends Normalizer
21 {
27 private $documentElement;
28
34 private $namespace;
35
41 private $dtdPath;
42
48 private $expression;
49
50 public function __construct($documentElement, $namespace, $dtdPath)
51 {
52 $this->documentElement = $documentElement;
53 $this->namespace = $namespace;
54 $this->dtdPath = $dtdPath;
55 }
56
65 public function accept($input)
66 {
67 if (preg_match($this->getExpression(), $input, $matches)) {
68 return true;
69 }
70
71 return false;
72 }
73
81 public function normalize($input)
82 {
83 return preg_replace(
84 $this->getExpression(),
85 "\${1}\n" . file_get_contents($this->dtdPath) . '${3}',
86 $input
87 );
88 }
89
95 private function getExpression()
96 {
97 if ($this->expression === null) {
98 $this->expression =
99 '/(<\?xml.*\?>)?([ \t\n\r]*)(<' .
100 preg_quote($this->documentElement, '/') .
101 '.*xmlns="' .
102 preg_quote($this->namespace, '/') .
103 '".*>)/is';
104 }
105
106 return $this->expression;
107 }
108 }
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition
Character entity definition normalizer adds DTD containing character entity definition to string inpu...
Definition: DocumentTypeDefinition.php:21
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\__construct
__construct($documentElement, $namespace, $dtdPath)
Definition: DocumentTypeDefinition.php:50
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\$expression
$expression
Definition: DocumentTypeDefinition.php:48
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\getExpression
getExpression()
Computes and returns regular expression pattern for matching and replacement.
Definition: DocumentTypeDefinition.php:95
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\accept
accept($input)
Accept if $input looks like XML document, with configured document element and default namespace,...
Definition: DocumentTypeDefinition.php:65
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\$documentElement
$documentElement
Definition: DocumentTypeDefinition.php:27
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\$namespace
$namespace
Definition: DocumentTypeDefinition.php:34
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\normalize
normalize($input)
Normalizes given $input by adding DTD with character entity definition.
Definition: DocumentTypeDefinition.php:81
eZ\Publish\Core\FieldType\RichText\Normalizer\DocumentTypeDefinition\$dtdPath
$dtdPath
Definition: DocumentTypeDefinition.php:41
eZ\Publish\Core\FieldType\RichText\Normalizer
Abstract class for XML normalization of string input.
Definition: Normalizer.php:15
eZ\Publish\Core\FieldType\RichText\Normalizer
Definition: FieldType/RichText/Normalizer/Aggregate.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.