XmlImportAstElseif.php
14 years ago
XmlImportAstExpression.php
14 years ago
XmlImportAstFloat.php
14 years ago
XmlImportAstForeach.php
14 years ago
XmlImportAstFunction.php
14 years ago
XmlImportAstIf.php
14 years ago
XmlImportAstInteger.php
14 years ago
XmlImportAstLiteral.php
14 years ago
XmlImportAstMath.php
14 years ago
XmlImportAstPrint.php
14 years ago
XmlImportAstSequence.php
14 years ago
XmlImportAstStatement.php
14 years ago
XmlImportAstString.php
14 years ago
XmlImportAstText.php
14 years ago
XmlImportAstWith.php
14 years ago
XmlImportAstXPath.php
14 years ago
XmlImportAstXpathClause.php
14 years ago
XmlImportAstIf.php
162 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @author Olexandr Zanichkovsky <olexandr.zanichkovsky@zophiatech.com> |
| 4 | * @package AST |
| 5 | */ |
| 6 | |
| 7 | require_once dirname(__FILE__) . '/XmlImportAstStatement.php'; |
| 8 | require_once dirname(__FILE__) . '/XmlImportAstElseif.php'; |
| 9 | |
| 10 | /** |
| 11 | * Represents an IF clause |
| 12 | */ |
| 13 | class XmlImportAstIf extends XmlImportAstStatement |
| 14 | { |
| 15 | /** |
| 16 | * Condition |
| 17 | * |
| 18 | * @var XmlImportAstExpression |
| 19 | */ |
| 20 | private $condition; |
| 21 | |
| 22 | /** |
| 23 | * If body |
| 24 | * |
| 25 | * @var XmlImportAstSequence |
| 26 | */ |
| 27 | private $ifBody; |
| 28 | |
| 29 | /** |
| 30 | * List of elseif subclauses |
| 31 | * |
| 32 | * @var array |
| 33 | */ |
| 34 | private $elseIfs = array(); |
| 35 | |
| 36 | /** |
| 37 | * Else body |
| 38 | * |
| 39 | * @var XmlImportAstSequence |
| 40 | */ |
| 41 | private $elseBody; |
| 42 | |
| 43 | /** |
| 44 | * Creates new instance |
| 45 | * |
| 46 | * @param XmlImportAstExpression $condition |
| 47 | */ |
| 48 | public function __construct(XmlImportAstExpression $condition) |
| 49 | { |
| 50 | $this->condition = $condition; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets condition |
| 55 | * |
| 56 | * @return XmlImportAstExpression |
| 57 | */ |
| 58 | public function getCondition() |
| 59 | { |
| 60 | return $this->condition; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets if body |
| 65 | * |
| 66 | * @return XmlImportAstSequence |
| 67 | */ |
| 68 | public function getIfBody() |
| 69 | { |
| 70 | return $this->ifBody; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Adds If body |
| 75 | * |
| 76 | * @param XmlImportAstSequence $body |
| 77 | */ |
| 78 | public function addIfBody(XmlImportAstSequence $body) |
| 79 | { |
| 80 | $this->ifBody = $body; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Gets list of elseif subcloses |
| 85 | * |
| 86 | * @return array |
| 87 | */ |
| 88 | public function getElseIfs() |
| 89 | { |
| 90 | return $this->elseIfs; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Gets else body |
| 95 | * |
| 96 | * @return XmlImportAstSequence |
| 97 | */ |
| 98 | public function getElseBody() |
| 99 | { |
| 100 | return $this->elseBody; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Adds else body |
| 105 | * |
| 106 | * @param XmlImportAstSequence $body |
| 107 | */ |
| 108 | public function addElseBody(XmlImportAstSequence $body) |
| 109 | { |
| 110 | $this->elseBody = $body; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Adds elseif subclause |
| 115 | * |
| 116 | * @param XmlImportAstElseif $elseif |
| 117 | */ |
| 118 | public function addElseif(XmlImportAstElseif $elseif) |
| 119 | { |
| 120 | $this->elseIfs[] = $elseif; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * String represetation of an IF clause |
| 125 | * |
| 126 | * @return string |
| 127 | */ |
| 128 | public function __toString() |
| 129 | { |
| 130 | $result = "--> begin " . get_class($this) . "\n"; |
| 131 | $result .= ' Condition: ' . $this->condition . "\n"; |
| 132 | $result .= " Body:\n"; |
| 133 | $array = explode("\n", $this->ifBody); |
| 134 | for ($i = 0; $i < count($array); $i++) |
| 135 | { |
| 136 | $array[$i] = ' ' . $array[$i]; |
| 137 | } |
| 138 | $result .= implode("\n", $array) . "\n"; |
| 139 | foreach($this->elseIfs as $elseIf) |
| 140 | { |
| 141 | $array = explode("\n", $elseIf); |
| 142 | for ($i = 0; $i < count($array); $i++) |
| 143 | { |
| 144 | $array[$i] = '' . $array[$i]; |
| 145 | } |
| 146 | $result .= implode("\n", $array) . "\n"; |
| 147 | } |
| 148 | if (!is_null($this->elseBody)) |
| 149 | { |
| 150 | $result .= " Else:\n"; |
| 151 | $array = explode("\n", $this->elseBody); |
| 152 | for ($i = 0; $i < count($array); $i++) |
| 153 | { |
| 154 | $array[$i] = ' ' . $array[$i]; |
| 155 | } |
| 156 | $result .= implode("\n", $array) . "\n"; |
| 157 | } |
| 158 | $result .= "--> end " . get_class($this) . "\n"; |
| 159 | return $result; |
| 160 | } |
| 161 | } |
| 162 |