[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZTemplateTypeOperator class 4 // 5 // Created on: <18-Apr-2002 12:15:07 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZTemplateTypeOperator eztemplatetypeoperator.php 31 \ingroup eZTemplateOperators 32 \brief Operators for checking variable type 33 34 Usage: 35 $var|is_array or is_array( $var ) 36 $var|is_boolean or is_boolean( $var ) 37 $var|is_integer or is_integer( $var ) 38 $var|is_float or is_float( $var ) 39 $var|is_numeric or is_numeric( $var ) 40 $var|is_string or is_string( $var ) 41 $var|is_object or is_object( $var ) 42 $var|is_class('my_class') or is_class( 'my_class', $var ) 43 $var|is_null or is_null( $var ) 44 is_set( $var ) 45 is_unset( $var ) 46 $var|get_type or get_type( $var ) 47 $var|get_class or get_class( $var ) 48 49 50 */ 51 52 class eZTemplateTypeOperator 53 { 54 /*! 55 Initializes the operator class with the various operator names. 56 */ 57 function eZTemplateTypeOperator( /*! The name array */ 58 $isArrayName = "is_array", 59 $isBooleanName = "is_boolean", 60 $isIntegerName = "is_integer", 61 $isFloatName = "is_float", 62 $isNumericName = "is_numeric", 63 $isStringName = "is_string", 64 $isObjectName = "is_object", 65 $isClassName = "is_class", 66 $isNullName = "is_null", 67 $isSetName = "is_set", 68 $isUnsetName = "is_unset", 69 $getTypeName = "get_type", 70 $getClassName = "get_class" ) 71 { 72 $this->Operators = array( $isArrayName, 73 $isBooleanName, 74 $isIntegerName, 75 $isFloatName, 76 $isNumericName, 77 $isStringName, 78 $isObjectName, 79 $isClassName, 80 $isNullName, 81 $isSetName, 82 $isUnsetName, 83 $getTypeName, 84 $getClassName ); 85 $this->IsArrayName = $isArrayName; 86 $this->IsBooleanName = $isBooleanName; 87 $this->IsIntegerName = $isIntegerName; 88 $this->IsFloatName = $isFloatName; 89 $this->IsNumericName = $isNumericName; 90 $this->IsStringName = $isStringName; 91 $this->IsObjectName = $isObjectName; 92 $this->IsClassName = $isClassName; 93 $this->IsNullName = $isNullName; 94 $this->IsSetName = $isSetName; 95 $this->IsUnsetName = $isUnsetName; 96 $this->GetTypeName = $getTypeName; 97 $this->GetClassName = $getClassName; 98 $this->PHPNameMap = array( $isArrayName => 'is_array', 99 $isBooleanName => 'is_bool', 100 $isIntegerName => 'is_integer', 101 $isFloatName => 'is_float', 102 $isNumericName => 'is_numeric', 103 $isStringName => 'is_string', 104 $isObjectName => 'is_object', 105 $isNullName => 'is_null' ); 106 } 107 108 /*! 109 Returns the operators in this class. 110 */ 111 function &operatorList() 112 { 113 return $this->Operators; 114 } 115 116 function operatorTemplateHints() 117 { 118 return array( $this->IsArrayName => array( 'input' => true, 119 'output' => true, 120 'parameters' => true, 121 'element-transformation' => true, 122 'transform-parameters' => true, 123 'input-as-parameter' => true, 124 'element-transformation-func' => 'isTransform'), 125 $this->IsBooleanName => array( 'input' => true, 126 'output' => true, 127 'parameters' => true, 128 'element-transformation' => true, 129 'transform-parameters' => true, 130 'input-as-parameter' => true, 131 'element-transformation-func' => 'isTransform' ), 132 $this->IsIntegerName => array( 'input' => true, 133 'output' => true, 134 'parameters' => true, 135 'element-transformation' => true, 136 'transform-parameters' => true, 137 'input-as-parameter' => true, 138 'element-transformation-func' => 'isTransform' ), 139 $this->IsFloatName => array( 'input' => true, 140 'output' => true, 141 'parameters' => true, 142 'element-transformation' => true, 143 'transform-parameters' => true, 144 'input-as-parameter' => true, 145 'element-transformation-func' => 'isTransform' ), 146 $this->IsNumericName => array( 'input' => true, 147 'output' => true, 148 'parameters' => true, 149 'element-transformation' => true, 150 'transform-parameters' => true, 151 'input-as-parameter' => true, 152 'element-transformation-func' => 'isTransform' ), 153 $this->IsStringName => array( 'input' => true, 154 'output' => true, 155 'parameters' => true, 156 'element-transformation' => true, 157 'transform-parameters' => true, 158 'input-as-parameter' => true, 159 'element-transformation-func' => 'isTransform' ), 160 $this->IsObjectName => array( 'input' => true, 161 'output' => true, 162 'parameters' => true, 163 'element-transformation' => true, 164 'transform-parameters' => true, 165 'input-as-parameter' => true, 166 'element-transformation-func' => 'isTransform' ), 167 $this->IsClassName => array( 'input' => true, 168 'output' => true, 169 'parameters' => true, 170 'element-transformation' => true, 171 'transform-parameters' => true, 172 'input-as-parameter' => true, 173 'element-transformation-func' => 'isTransform' ), 174 $this->IsNullName => array( 'input' => true, 175 'output' => true, 176 'parameters' => true, 177 'element-transformation' => true, 178 'transform-parameters' => true, 179 'input-as-parameter' => true, 180 'element-transformation-func' => 'isTransform' ), 181 $this->IsSetName => array( 'input' => true, 182 'output' => true, 183 'parameters' => true, 184 'element-transformation' => true, 185 'transform-parameters' => true, 186 'input-as-parameter' => true, 187 'element-transformation-func' => 'isTransform' ), 188 $this->IsUnsetName => array( 'input' => true, 189 'output' => true, 190 'parameters' => true, 191 'element-transformation' => true, 192 'transform-parameters' => true, 193 'input-as-parameter' => true, 194 'element-transformation-func' => 'isTransform' ), 195 $this->GetTypeName => array( 'input' => true, 196 'output' => true, 197 'parameters' => true, 198 'element-transformation' => true, 199 'transform-parameters' => true, 200 'input-as-parameter' => true, 201 'element-transformation-func' => 'isTransform' ), 202 $this->GetClassName => array( 'input' => true, 203 'output' => true, 204 'parameters' => true, 205 'element-transformation' => true, 206 'transform-parameters' => true, 207 'input-as-parameter' => true, 208 'element-transformation-func' => 'isTransform' ) ); 209 } 210 211 /*! 212 \reimp 213 */ 214 function isTransform( $operatorName, &$node, &$tpl, &$resourceData, 215 &$element, &$lastElement, &$elementList, &$elementTree, &$parameters ) 216 { 217 $values = array(); 218 $values[] = $parameters[0]; 219 $code = '%output% = '; 220 221 switch( $operatorName ) 222 { 223 case $this->IsArrayName: 224 { 225 $code .= 'is_array( %1% );'; 226 } break; 227 228 case $this->IsBooleanName: 229 { 230 $code .= 'is_bool( %1% );'; 231 } break; 232 233 case $this->IsIntegerName: 234 { 235 $code .= 'is_int( %1% );'; 236 } break; 237 238 case $this->IsFloatName: 239 { 240 $code .= 'is_float( %1% );'; 241 } break; 242 243 case $this->IsNumericName: 244 { 245 $code .= 'is_numeric( %1% );'; 246 } break; 247 248 case $this->IsStringName: 249 { 250 $code .= 'is_string( %1% );'; 251 } break; 252 253 case $this->IsObjectName: 254 { 255 $code .= 'is_object( %1% );'; 256 } break; 257 258 case $this->IsClassName: 259 { 260 $code .= '( get_class( %1% ) == strtolower( %2% ) );'; 261 $values[] = $parameters[1]; 262 } break; 263 264 case $this->IsNullName: 265 { 266 $code .= 'is_null( %1% );'; 267 } break; 268 269 case $this->IsSetName: 270 { 271 $code .= 'isset( %1% );'; 272 } break; 273 274 case $this->IsUnsetName: 275 { 276 $code .= '!isset( %1% );'; 277 } break; 278 279 case $this->GetTypeName: 280 { 281 return false; 282 } break; 283 284 case $this->GetClassName: 285 { 286 $code .= 'get_class( %1% );'; 287 } break; 288 } 289 290 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) ); 291 } 292 293 /*! 294 \return true to tell the template engine that the parameter list exists per operator type. 295 */ 296 function namedParameterPerOperator() 297 { 298 return true; 299 } 300 301 /*! 302 See eZTemplateOperator::namedParameterList 303 */ 304 function namedParameterList() 305 { 306 return array(); 307 } 308 309 /*! 310 Examines the input value and outputs a boolean value. See class documentation for more information. 311 */ 312 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$value, &$namedParameters, $placement ) 313 { 314 if ( isset( $this->PHPNameMap[$operatorName] ) ) 315 { 316 $typeFunction = $this->PHPNameMap[$operatorName]; 317 $this->checkType( $typeFunction, $tpl, $value, $operatorParameters, $rootNamespace, $currentNamespace, $placement ); 318 return; 319 } 320 switch ( $operatorName ) 321 { 322 case $this->IsClassName: 323 { 324 if ( count( $operatorParameters ) == 1 ) 325 { 326 $className =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ); 327 $value = get_class( $value ) == strtolower( $className ); 328 } 329 else 330 { 331 $className =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ); 332 $value = get_class( $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement ) ) == strtolower( $className ); 333 } 334 } break; 335 case $this->IsSetName: 336 { 337 if ( count( $operatorParameters ) > 0 ) 338 { 339 if ( count( $operatorParameters ) > 1 ) 340 { 341 $tpl->extraParameters( $operatorName, count( $operatorParameters ), 1 ); 342 } 343 344 $operand =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement, true ); 345 $value = $operand !== null; 346 347 348 } 349 else 350 $tpl->missingParameter( $operatorName, 'input' ); 351 352 } break; 353 case $this->IsUnsetName: 354 { 355 if ( count( $operatorParameters ) > 0 ) 356 { 357 if ( count( $operatorParameters ) > 1 ) 358 $tpl->extraParameters( $operatorName, 359 count( $operatorParameters ), 360 1 ); 361 $operand =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement, true ); 362 $value = $operand === null; 363 } 364 else 365 $tpl->missingParameter( $operatorName, 'input' ); 366 } break; 367 case $this->GetTypeName: 368 { 369 if ( count( $operatorParameters ) > 0 ) 370 { 371 if ( count( $operatorParameters ) > 1 ) 372 $tpl->extraParameters( $operatorName, 373 count( $operatorParameters ), 374 1 ); 375 $operand =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ); 376 } 377 else 378 $operand =& $value; 379 if ( $operand === null ) 380 $value = 'null'; 381 else if ( is_bool( $operand ) ) 382 $value = 'boolean[' . ( $operand ? 'true' : 'false' ) . ']'; 383 else if ( is_object( $operand ) ) 384 $value = 'object[' . get_class( $operand ) . ']'; 385 else if ( is_array( $operand ) ) 386 $value = 'array[' . count( $operand ) . ']'; 387 else if ( is_string( $operand ) ) 388 $value = 'string[' . strlen( $operand ) . ']'; 389 else 390 $value = gettype( $operand ); 391 } break; 392 case $this->GetClassName: 393 { 394 if ( count( $operatorParameters ) > 0 ) 395 { 396 if ( count( $operatorParameters ) > 1 ) 397 $tpl->extraParameters( $operatorName, 398 count( $operatorParameters ), 399 1 ); 400 $operand =& $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ); 401 $value = get_class( $operand ); 402 } 403 else 404 { 405 $value = get_class( $value ); 406 } 407 } break; 408 } 409 } 410 411 function checkType( $typeFunction, &$tpl, &$value, &$operatorParameters, &$rootNamespace, &$currentNamespace, $placement ) 412 { 413 if ( count( $operatorParameters ) > 0 ) 414 { 415 $value = true; 416 for ( $i = 0; $i < count( $operatorParameters ); ++$i ) 417 { 418 $operand =& $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement ); 419 if ( !$typeFunction( $operand) ) 420 $value = false; 421 } 422 } 423 else 424 { 425 $value = $typeFunction( $value ); 426 } 427 } 428 429 /// The array of operators 430 var $Operators; 431 /// The "less than" name 432 var $IsArrayName; 433 }; 434 435 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |