/Template/src/functions/type_functions.php

https://github.com/F5/zetacomponents · PHP · 161 lines · 57 code · 25 blank · 79 comment · 1 complexity · f81fdfcce0aa80f66a20f1958c7aac54 MD5 · raw file

  1. <?php
  2. /**
  3. * File containing the ezcTemplateTypeFunctions class
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Template
  23. * @version //autogen//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. * @access private
  26. */
  27. /**
  28. * @package Template
  29. * @version //autogen//
  30. * @access private
  31. */
  32. class ezcTemplateTypeFunctions extends ezcTemplateFunctions
  33. {
  34. /**
  35. * Translates a function used in the Template language to a PHP function call.
  36. * The function call is represented by an array with three elements:
  37. *
  38. * 1. The return typehint. Is it an array, a non-array, or both.
  39. * 2. The parameter input definition.
  40. * 3. The AST nodes.
  41. *
  42. * @param string $functionName
  43. * @param array(ezcTemplateAstNode) $parameters
  44. * @return array(mixed)
  45. */
  46. public static function getFunctionSubstitution( $functionName, $parameters )
  47. {
  48. switch ( $functionName )
  49. {
  50. // is_empty( $v )::
  51. // empty( $v )
  52. case "is_empty": return array( array( "%var" ),
  53. self::functionCall( "ezcTemplateType::is_empty", array( "%var" ) ) );
  54. // is_array( $v )::
  55. // is_array( $v )
  56. case "is_array": return array( array( "%var" ),
  57. self::functionCall( "is_array", array( "%var" ) ) );
  58. // is_bool( $v )::
  59. // is_bool( $v )
  60. case "is_bool": return array( array( "%var" ),
  61. self::functionCall( "is_bool", array( "%var" ) ) );
  62. // is_float( $v )::
  63. // is_float( $v )
  64. case "is_float": return array( array( "%var" ),
  65. self::functionCall( "is_float", array( "%var" ) ) );
  66. // is_int( $v )::
  67. // is_int( $v )
  68. case "is_int": return array( array( "%var" ),
  69. self::functionCall( "is_int", array( "%var" ) ) );
  70. // is_bool( $v )::
  71. // is_bool( $v )
  72. case "is_bool": return array( array( "%var" ),
  73. self::functionCall( "is_bool", array( "%var" ) ) );
  74. // is_numeric( $v )::
  75. // is_numeric( $v )
  76. case "is_numeric": return array( array( "%var" ),
  77. self::functionCall( "is_numeric", array( "%var" ) ) );
  78. // is_object( $v )::
  79. // is_object( $v ) ?
  80. case "is_object": return array( array( "%var" ),
  81. self::functionCall( "is_object", array( "%var" ) ) );
  82. // is_class( $v, $class )::
  83. // getclass( $v ) == $class
  84. case "is_class": return array(
  85. ezcTemplateAstNode::TYPE_VALUE,
  86. array( "%var", "%class" ),
  87. array( "ezcTemplateIdenticalOperatorAstNode", array(
  88. self::functionCall( "get_class", array( "%var" ) ),
  89. "%class" )
  90. ) );
  91. // instanceof.
  92. case "is_instance": return array(
  93. ezcTemplateAstnode::TYPE_VALUE,
  94. array( "%var", "%class" ),
  95. self::functionCall( "ezcTemplateType::is_instance", array( "%var", "%class" ) ) );
  96. // is_scalar( $v )::
  97. // is_scalar( $v )
  98. case "is_scalar": return array( array( "%var" ),
  99. self::functionCall( "is_scalar", array( "%var" ) ) );
  100. // is_string( $v )::
  101. // is_string( $v )
  102. case "is_string": return array( array( "%var" ),
  103. self::functionCall( "is_string", array( "%var" ) ) );
  104. // is_set( $v )::
  105. // is_set( $v )
  106. case "is_set": return array( array( "%var:Variable" ),
  107. self::functionCall( "isset", array( "%var:Variable" ) ) );
  108. // is_constant( $const )::
  109. // return defined( $const )
  110. case "is_constant": return array( array( "%var" ),
  111. self::functionCall( "defined", array( "%var" ) ) );
  112. // get_constant( $const )::
  113. // constant( $const );
  114. case "get_constant": return array( array( "%var" ),
  115. self::functionCall( "constant", array( "%var" ) ) );
  116. // get_class( $var )::
  117. // get_class( $var );
  118. case "get_class": return array( array( "%var" ),
  119. self::functionCall( "get_class", array( "%var" ) ) );
  120. // cast_string( $v )::
  121. // (string)$v
  122. case "cast_string": return array( array( "%var" ),
  123. array( "ezcTemplateTypeCastAstNode", array( "string", "%var" ) ) );
  124. // cast_int( $v )::
  125. // (int)$v
  126. case "cast_int": return array( array( "%var" ),
  127. array( "ezcTemplateTypeCastAstNode", array( "int", "%var" ) ) );
  128. // cast_float( $v )::
  129. // (float)$v
  130. case "cast_float": return array( array( "%var" ),
  131. array( "ezcTemplateTypeCastAstNode", array( "float", "%var" ) ) );
  132. }
  133. return null;
  134. }
  135. }
  136. ?>