Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatetypeoperator.php
Go to the documentation of this file.
1 <?php
34 class eZTemplateTypeOperator
35 {
53 public function __construct(
54 $isArrayName = "is_array",
55 $isBooleanName = "is_boolean",
56 $isIntegerName = "is_integer",
57 $isFloatName = "is_float",
58 $isNumericName = "is_numeric",
59 $isStringName = "is_string",
60 $isObjectName = "is_object",
61 $isClassName = "is_class",
62 $isNullName = "is_null",
63 $isSetName = "is_set",
64 $isUnsetName = "is_unset",
65 $getTypeName = "get_type",
66 $getClassName = "get_class" )
67 {
68 $this->Operators = array( $isArrayName,
69 $isBooleanName,
70 $isIntegerName,
71 $isFloatName,
72 $isNumericName,
73 $isStringName,
74 $isObjectName,
75 $isClassName,
76 $isNullName,
77 $isSetName,
78 $isUnsetName,
79 $getTypeName,
80 $getClassName );
81 $this->IsArrayName = $isArrayName;
82 $this->IsBooleanName = $isBooleanName;
83 $this->IsIntegerName = $isIntegerName;
84 $this->IsFloatName = $isFloatName;
85 $this->IsNumericName = $isNumericName;
86 $this->IsStringName = $isStringName;
87 $this->IsObjectName = $isObjectName;
88 $this->IsClassName = $isClassName;
89 $this->IsNullName = $isNullName;
90 $this->IsSetName = $isSetName;
91 $this->IsUnsetName = $isUnsetName;
92 $this->GetTypeName = $getTypeName;
93 $this->GetClassName = $getClassName;
94 $this->PHPNameMap = array( $isArrayName => 'is_array',
95 $isBooleanName => 'is_bool',
96 $isIntegerName => 'is_integer',
97 $isFloatName => 'is_float',
98 $isNumericName => 'is_numeric',
99 $isStringName => 'is_string',
100 $isObjectName => 'is_object',
101 $isNullName => 'is_null' );
102 }
103
107 function operatorList()
108 {
109 return $this->Operators;
110 }
111
112 function operatorTemplateHints()
113 {
114 return array( $this->IsArrayName => array( 'input' => true,
115 'output' => true,
116 'parameters' => true,
117 'element-transformation' => true,
118 'transform-parameters' => true,
119 'input-as-parameter' => true,
120 'element-transformation-func' => 'isTransform'),
121 $this->IsBooleanName => array( 'input' => true,
122 'output' => true,
123 'parameters' => true,
124 'element-transformation' => true,
125 'transform-parameters' => true,
126 'input-as-parameter' => true,
127 'element-transformation-func' => 'isTransform' ),
128 $this->IsIntegerName => array( 'input' => true,
129 'output' => true,
130 'parameters' => true,
131 'element-transformation' => true,
132 'transform-parameters' => true,
133 'input-as-parameter' => true,
134 'element-transformation-func' => 'isTransform' ),
135 $this->IsFloatName => array( 'input' => true,
136 'output' => true,
137 'parameters' => true,
138 'element-transformation' => true,
139 'transform-parameters' => true,
140 'input-as-parameter' => true,
141 'element-transformation-func' => 'isTransform' ),
142 $this->IsNumericName => array( 'input' => true,
143 'output' => true,
144 'parameters' => true,
145 'element-transformation' => true,
146 'transform-parameters' => true,
147 'input-as-parameter' => true,
148 'element-transformation-func' => 'isTransform' ),
149 $this->IsStringName => array( 'input' => true,
150 'output' => true,
151 'parameters' => true,
152 'element-transformation' => true,
153 'transform-parameters' => true,
154 'input-as-parameter' => true,
155 'element-transformation-func' => 'isTransform' ),
156 $this->IsObjectName => array( 'input' => true,
157 'output' => true,
158 'parameters' => true,
159 'element-transformation' => true,
160 'transform-parameters' => true,
161 'input-as-parameter' => true,
162 'element-transformation-func' => 'isTransform' ),
163 $this->IsClassName => array( 'input' => true,
164 'output' => true,
165 'parameters' => true,
166 'element-transformation' => true,
167 'transform-parameters' => true,
168 'input-as-parameter' => true,
169 'element-transformation-func' => 'isTransform' ),
170 $this->IsNullName => array( 'input' => true,
171 'output' => true,
172 'parameters' => true,
173 'element-transformation' => true,
174 'transform-parameters' => true,
175 'input-as-parameter' => true,
176 'element-transformation-func' => 'isTransform' ),
177 $this->IsSetName => array( 'input' => true,
178 'output' => true,
179 'parameters' => true,
180 'element-transformation' => true,
181 'transform-parameters' => true,
182 'input-as-parameter' => true,
183 'element-transformation-func' => 'isTransform' ),
184 $this->IsUnsetName => array( 'input' => true,
185 'output' => true,
186 'parameters' => true,
187 'element-transformation' => true,
188 'transform-parameters' => true,
189 'input-as-parameter' => true,
190 'element-transformation-func' => 'isTransform' ),
191 $this->GetTypeName => array( 'input' => true,
192 'output' => true,
193 'parameters' => true,
194 'element-transformation' => true,
195 'transform-parameters' => true,
196 'input-as-parameter' => true,
197 'element-transformation-func' => 'isTransform' ),
198 $this->GetClassName => array( 'input' => true,
199 'output' => true,
200 'parameters' => true,
201 'element-transformation' => true,
202 'transform-parameters' => true,
203 'input-as-parameter' => true,
204 'element-transformation-func' => 'isTransform' ) );
205 }
206
207 function isTransform( $operatorName, &$node, $tpl, &$resourceData,
208 $element, $lastElement, $elementList, $elementTree, &$parameters )
209 {
210 $values = array();
211 $values[] = $parameters[0];
212 $code = '%output% = ';
213
214 switch( $operatorName )
215 {
216 case $this->IsArrayName:
217 {
218 $code .= 'is_array( %1% );';
219 } break;
220
221 case $this->IsBooleanName:
222 {
223 $code .= '( %1% === true || %1% === false );';
224 } break;
225
226 case $this->IsIntegerName:
227 {
228 $code .= 'is_int( %1% );';
229 } break;
230
231 case $this->IsFloatName:
232 {
233 $code .= 'is_float( %1% );';
234 } break;
235
236 case $this->IsNumericName:
237 {
238 $code .= 'is_numeric( %1% );';
239 } break;
240
241 case $this->IsStringName:
242 {
243 $code .= 'is_string( %1% );';
244 } break;
245
246 case $this->IsObjectName:
247 {
248 $code .= 'is_object( %1% );';
249 } break;
250
251 case $this->IsClassName:
252 {
253 $code .= '( is_object( %1% ) ? strtolower( get_class( %1% ) ) == strtolower( %2% ) : false );';
254 $values[] = $parameters[1];
255 } break;
256
257 case $this->IsNullName:
258 {
259 $code .= '(%1% === null);';
260 } break;
261
262 case $this->IsSetName:
263 {
264 $code .= 'isset( %1% );';
265 } break;
266
267 case $this->IsUnsetName:
268 {
269 $code .= '!isset( %1% );';
270 } break;
271
272 case $this->GetTypeName:
273 {
274 return false;
275 } break;
276
277 case $this->GetClassName:
278 {
279 $code .= '( is_object( %1% ) ? strtolower( get_class( %1% ) ) : "" );';
280 } break;
281 }
282
283 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
284 }
285
289 function namedParameterPerOperator()
290 {
291 return true;
292 }
293
297 function namedParameterList()
298 {
299 return array();
300 }
301
305 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters, $placement )
306 {
307 if ( isset( $this->PHPNameMap[$operatorName] ) )
308 {
309 $typeFunction = $this->PHPNameMap[$operatorName];
310 $this->checkType( $typeFunction, $tpl, $value, $operatorParameters, $rootNamespace, $currentNamespace, $placement );
311 return;
312 }
313 switch ( $operatorName )
314 {
315 case $this->IsClassName:
316 {
317 if ( count( $operatorParameters ) == 1 )
318 {
319 $className = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
320 $value = strtolower( get_class( $value ) ) == strtolower( $className );
321 }
322 else
323 {
324 $className = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
325 $value = strtolower( get_class( $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement ) ) ) == strtolower( $className );
326 }
327 } break;
328 case $this->IsSetName:
329 {
330 if ( count( $operatorParameters ) > 0 )
331 {
332 if ( count( $operatorParameters ) > 1 )
333 {
334 $tpl->extraParameters( $operatorName, count( $operatorParameters ), 1 );
335 }
336
337 $operand = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement, true );
338 $value = $operand !== null;
339
340
341 }
342 else
343 $tpl->missingParameter( $operatorName, 'input' );
344
345 } break;
346 case $this->IsUnsetName:
347 {
348 if ( count( $operatorParameters ) > 0 )
349 {
350 if ( count( $operatorParameters ) > 1 )
351 $tpl->extraParameters( $operatorName,
352 count( $operatorParameters ),
353 1 );
354 $operand = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement, true );
355 $value = $operand === null;
356 }
357 else
358 $tpl->missingParameter( $operatorName, 'input' );
359 } break;
360 case $this->GetTypeName:
361 {
362 if ( count( $operatorParameters ) > 0 )
363 {
364 if ( count( $operatorParameters ) > 1 )
365 $tpl->extraParameters( $operatorName,
366 count( $operatorParameters ),
367 1 );
368 $operand = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
369 }
370 else
371 $operand =& $value;
372 if ( $operand === null )
373 $value = 'null';
374 else if ( is_bool( $operand ) )
375 $value = 'boolean[' . ( $operand ? 'true' : 'false' ) . ']';
376 else if ( is_object( $operand ) )
377 $value = 'object[' . get_class( $operand ) . ']';
378 else if ( is_array( $operand ) )
379 $value = 'array[' . count( $operand ) . ']';
380 else if ( is_string( $operand ) )
381 $value = 'string[' . strlen( $operand ) . ']';
382 else
383 $value = gettype( $operand );
384 } break;
385 case $this->GetClassName:
386 {
387 if ( count( $operatorParameters ) > 0 )
388 {
389 if ( count( $operatorParameters ) > 1 )
390 $tpl->extraParameters( $operatorName,
391 count( $operatorParameters ),
392 1 );
393 $operand = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
394 $value = strtolower( get_class( $operand ) );
395 }
396 else
397 {
398 $value = strtolower( get_class( $value ) );
399 }
400 } break;
401 }
402 }
403
404 function checkType( $typeFunction, $tpl, &$value, $operatorParameters, $rootNamespace, $currentNamespace, $placement )
405 {
406 if ( count( $operatorParameters ) > 0 )
407 {
408 $value = true;
409 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
410 {
411 $operand = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
412 if ( !$typeFunction( $operand) )
413 $value = false;
414 }
415 }
416 else
417 {
418 $value = $typeFunction( $value );
419 }
420 }
421
423 public $Operators;
425 public $IsArrayName;
426 public $IsBooleanName;
427 public $IsIntegerName;
428 public $IsFloatName;
429 public $IsNumericName;
430 public $IsStringName;
431 public $IsObjectName;
432 public $IsClassName;
433 public $IsNullName;
434 public $IsSetName;
435 public $IsUnsetName;
436 public $GetTypeName;
437 public $GetClassName;
438 public $PHPNameMap;
439 }
440
441 ?>
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateTypeOperator
Operators for checking variable type.
Definition: eztemplatetypeoperator.php:35
eZTemplateTypeOperator\$IsSetName
$IsSetName
Definition: eztemplatetypeoperator.php:434
eZTemplateTypeOperator\$IsClassName
$IsClassName
Definition: eztemplatetypeoperator.php:432
eZTemplateTypeOperator\$IsStringName
$IsStringName
Definition: eztemplatetypeoperator.php:430
eZTemplateTypeOperator\__construct
__construct($isArrayName="is_array", $isBooleanName="is_boolean", $isIntegerName="is_integer", $isFloatName="is_float", $isNumericName="is_numeric", $isStringName="is_string", $isObjectName="is_object", $isClassName="is_class", $isNullName="is_null", $isSetName="is_set", $isUnsetName="is_unset", $getTypeName="get_type", $getClassName="get_class")
Definition: eztemplatetypeoperator.php:53
eZTemplateTypeOperator\isTransform
isTransform( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatetypeoperator.php:207
eZTemplateTypeOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplatetypeoperator.php:112
eZTemplateTypeOperator\$PHPNameMap
$PHPNameMap
Definition: eztemplatetypeoperator.php:438
eZTemplateTypeOperator\$IsNumericName
$IsNumericName
Definition: eztemplatetypeoperator.php:429
eZTemplateTypeOperator\namedParameterList
namedParameterList()
Definition: eztemplatetypeoperator.php:297
eZTemplateTypeOperator\$IsBooleanName
$IsBooleanName
Definition: eztemplatetypeoperator.php:426
eZTemplateTypeOperator\$GetTypeName
$GetTypeName
Definition: eztemplatetypeoperator.php:436
eZTemplateTypeOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters, $placement)
Definition: eztemplatetypeoperator.php:305
eZTemplateTypeOperator\operatorList
operatorList()
Definition: eztemplatetypeoperator.php:107
eZTemplateTypeOperator\$Operators
$Operators
The array of operators.
Definition: eztemplatetypeoperator.php:423
eZTemplateTypeOperator\$IsFloatName
$IsFloatName
Definition: eztemplatetypeoperator.php:428
eZTemplateTypeOperator\$IsObjectName
$IsObjectName
Definition: eztemplatetypeoperator.php:431
eZTemplateTypeOperator\$IsArrayName
$IsArrayName
The "less than" name.
Definition: eztemplatetypeoperator.php:425
eZTemplateTypeOperator\$IsUnsetName
$IsUnsetName
Definition: eztemplatetypeoperator.php:435
eZTemplateTypeOperator\$IsIntegerName
$IsIntegerName
Definition: eztemplatetypeoperator.php:427
eZTemplateTypeOperator\$GetClassName
$GetClassName
Definition: eztemplatetypeoperator.php:437
eZTemplateTypeOperator\checkType
checkType( $typeFunction, $tpl, &$value, $operatorParameters, $rootNamespace, $currentNamespace, $placement)
Definition: eztemplatetypeoperator.php:404
eZTemplateTypeOperator\$IsNullName
$IsNullName
Definition: eztemplatetypeoperator.php:433
eZTemplateTypeOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplatetypeoperator.php:289
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.