@@ -55,7 +55,6 @@ public function preProcessSource($templateSource)
55
55
{
56
56
$ templateSource = $ this ->replaceCdataSectionsByEmptyLines ($ templateSource );
57
57
$ templateSource = $ this ->registerNamespacesFromTemplateSource ($ templateSource );
58
- $ this ->throwExceptionsForUnhandledNamespaces ($ templateSource );
59
58
return $ templateSource ;
60
59
}
61
60
@@ -125,70 +124,35 @@ public function registerNamespacesFromTemplateSource($templateSource)
125
124
substr ($ templateSource , strrpos ($ templateSource , $ closingTag ) + strlen ($ closingTag ));
126
125
}
127
126
} else {
128
- if (!empty ($ namespaces )) {
129
- $ namespaceAttributesToRemove = [];
130
- foreach ($ namespaces as $ namespace ) {
131
- if (!$ viewHelperResolver ->isNamespaceIgnored ($ namespace [1 ])) {
132
- $ namespaceAttributesToRemove [] = preg_quote ($ namespace [1 ], '/ ' ) . '=" ' . preg_quote ($ namespace [2 ], '/ ' ) . '" ' ;
133
- }
134
- }
135
- if (count ($ namespaceAttributesToRemove )) {
136
- $ matchWithRemovedNamespaceAttributes = preg_replace ('/(?: \\s*+xmlns:(?: ' . implode ('| ' , $ namespaceAttributesToRemove ) . ') \\s*+)++/ ' , ' ' , $ matches [0 ]);
137
- $ templateSource = str_replace ($ matches [0 ], $ matchWithRemovedNamespaceAttributes , $ templateSource );
127
+ $ namespaceAttributesToRemove = [];
128
+ foreach ($ namespaces as $ namespace ) {
129
+ if (!$ viewHelperResolver ->isNamespaceIgnored ($ namespace [1 ])) {
130
+ $ namespaceAttributesToRemove [] = preg_quote ($ namespace [1 ], '/ ' ) . '=" ' . preg_quote ($ namespace [2 ], '/ ' ) . '" ' ;
138
131
}
139
132
}
133
+ if (count ($ namespaceAttributesToRemove )) {
134
+ $ matchWithRemovedNamespaceAttributes = preg_replace ('/(?: \\s*+xmlns:(?: ' . implode ('| ' , $ namespaceAttributesToRemove ) . ') \\s*+)++/ ' , ' ' , $ matches [0 ]);
135
+ $ templateSource = str_replace ($ matches [0 ], $ matchWithRemovedNamespaceAttributes , $ templateSource );
136
+ }
140
137
}
141
138
}
142
139
143
140
preg_match_all (static ::NAMESPACE_DECLARATION , $ templateSource , $ namespaces );
144
- foreach ($ namespaces ['identifier ' ] as $ key => $ identifier ) {
145
- $ namespace = $ namespaces ['phpNamespace ' ][$ key ];
146
- if (strlen ($ namespace ) === 0 ) {
147
- $ namespace = null ;
148
- }
149
- $ viewHelperResolver ->addNamespace ($ identifier , $ namespace );
150
- }
151
- foreach ($ namespaces [0 ] as $ removal ) {
152
- $ templateSource = str_replace ($ removal , '' , $ templateSource );
153
- }
154
-
155
- return $ templateSource ;
156
- }
157
-
158
- /**
159
- * Throw an UnknownNamespaceException for any unknown and not ignored
160
- * namespace inside the template string
161
- *
162
- * @param string $templateSource
163
- * @return void
164
- */
165
- public function throwExceptionsForUnhandledNamespaces ($ templateSource )
166
- {
167
- $ viewHelperResolver = $ this ->renderingContext ->getViewHelperResolver ();
168
- $ splitTemplate = preg_split (Patterns::$ SPLIT_PATTERN_TEMPLATE_DYNAMICTAGS , $ templateSource , -1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
169
- foreach ($ splitTemplate as $ templateElement ) {
170
- if (preg_match (Patterns::$ SCAN_PATTERN_TEMPLATE_VIEWHELPERTAG , $ templateElement , $ matchedVariables ) > 0 ) {
171
- if (!$ viewHelperResolver ->isNamespaceValidOrIgnored ($ matchedVariables ['NamespaceIdentifier ' ])) {
172
- throw new UnknownNamespaceException ('Unknown Namespace: ' . htmlspecialchars ($ matchedVariables [0 ]));
141
+ if (!empty ($ namespaces ['identifier ' ])) {
142
+ // There are no namespace declarations using curly-brace syntax.
143
+ foreach ($ namespaces ['identifier ' ] as $ key => $ identifier ) {
144
+ $ namespace = $ namespaces ['phpNamespace ' ][$ key ];
145
+ if (strlen ($ namespace ) === 0 ) {
146
+ $ namespace = null ;
173
147
}
174
- continue ;
175
- } elseif (preg_match (Patterns::$ SCAN_PATTERN_TEMPLATE_CLOSINGVIEWHELPERTAG , $ templateElement , $ matchedVariables ) > 0 ) {
176
- continue ;
148
+ $ viewHelperResolver ->addNamespace ($ identifier , $ namespace );
177
149
}
178
-
179
- $ sections = preg_split (Patterns::$ SPLIT_PATTERN_SHORTHANDSYNTAX , $ templateElement , -1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
180
- foreach ($ sections as $ section ) {
181
- if (preg_match (Patterns::$ SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS , $ section , $ matchedVariables ) > 0 ) {
182
- preg_match_all (Patterns::$ SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER , $ section , $ shorthandViewHelpers , PREG_SET_ORDER );
183
- if (is_array ($ shorthandViewHelpers ) === true ) {
184
- foreach ($ shorthandViewHelpers as $ shorthandViewHelper ) {
185
- if (!$ viewHelperResolver ->isNamespaceValidOrIgnored ($ shorthandViewHelper ['NamespaceIdentifier ' ])) {
186
- throw new UnknownNamespaceException ('Unknown Namespace: ' . $ shorthandViewHelper ['NamespaceIdentifier ' ]);
187
- }
188
- }
189
- }
190
- }
150
+ foreach ($ namespaces [0 ] as $ removal ) {
151
+ $ templateSource = str_replace ($ removal , '' , $ templateSource );
191
152
}
153
+
192
154
}
155
+
156
+ return $ templateSource ;
193
157
}
194
158
}
0 commit comments