PageRenderTime 71ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/Template/src/syntax_trees/ast/nodes/constructs/isset.php

https://github.com/Yannix/zetacomponents
PHP | 97 lines | 37 code | 5 blank | 55 comment | 5 complexity | aaab2e3a78af587f79878b0fab85e0ea MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcTemplateIssetAstNode 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. * Represents an isset construct.
  29. *
  30. * @package Template
  31. * @version //autogen//
  32. * @access private
  33. */
  34. class ezcTemplateIssetAstNode extends ezcTemplateStatementAstNode
  35. {
  36. /**
  37. * The expression to evaluate if exists.
  38. * @var array(ezcTemplateAstNode)
  39. */
  40. public $expressions;
  41. /**
  42. * Initialize with function name code and optional arguments
  43. *
  44. * @param array(ezcTemplateAstNode) $expressions
  45. */
  46. public function __construct( Array $expressions = null )
  47. {
  48. parent::__construct();
  49. $this->expressions = array();
  50. if ( $expressions !== null )
  51. {
  52. foreach ( $expressions as $expression )
  53. {
  54. if ( !$expression instanceof ezcTemplateAstNode )
  55. {
  56. throw new ezcBaseValueException( "expressions[$id]", $expression, 'ezcTemplateAstNode' );
  57. }
  58. $this->expressions[] = $expression;
  59. }
  60. }
  61. }
  62. /**
  63. * Appends the expression to be checked for existance.
  64. *
  65. * @param ezcTemplateAstNode $expression Expression to check.
  66. */
  67. public function appendExpression( ezcTemplateAstNode $expression )
  68. {
  69. $this->expressions[] = $expression;
  70. }
  71. /**
  72. * Returns a list of expressions which will be checked for existance.
  73. * @return array(ezcTemplateAstNode)
  74. */
  75. public function getExpressions()
  76. {
  77. return $this->expressions;
  78. }
  79. /**
  80. * Validates the expressions against their constraints.
  81. *
  82. * @throws ezcTemplateInternalException if the constraints are not met.
  83. */
  84. public function validate()
  85. {
  86. if ( count( $this->expressions ) == 0 )
  87. {
  88. throw new ezcTemplateInternalException( "Too few expressions for class <" . get_class( $this ) . ">, needs at least 1 but got 0." );
  89. }
  90. }
  91. }
  92. ?>