XmlImportAstElseif.php
1 month ago
XmlImportAstExpression.php
1 month ago
XmlImportAstFloat.php
1 month ago
XmlImportAstForeach.php
1 month ago
XmlImportAstFunction.php
1 month ago
XmlImportAstIf.php
1 month ago
XmlImportAstInteger.php
1 month ago
XmlImportAstLiteral.php
1 month ago
XmlImportAstMath.php
1 month ago
XmlImportAstPrint.php
1 month ago
XmlImportAstSequence.php
1 month ago
XmlImportAstSpintax.php
1 month ago
XmlImportAstStatement.php
1 month ago
XmlImportAstString.php
1 month ago
XmlImportAstText.php
1 month ago
XmlImportAstWith.php
1 month ago
XmlImportAstXPath.php
1 month ago
XmlImportAstXpathClause.php
1 month ago
XmlImportAstXpathClause.php
85 lines
| 1 | <?php |
| 2 | // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals |
| 3 | /** |
| 4 | * @author Olexandr Zanichkovsky <olexandr.zanichkovsky@zophiatech.com> |
| 5 | * @package AST |
| 6 | */ |
| 7 | |
| 8 | require_once dirname(__FILE__) . '/XmlImportAstStatement.php'; |
| 9 | require_once dirname(__FILE__) . '/XmlImportAstXPath.php'; |
| 10 | require_once dirname(__FILE__) . '/XmlImportAstSequence.php'; |
| 11 | |
| 12 | /** |
| 13 | * Represents a clause that is based on XPath |
| 14 | */ |
| 15 | abstract class XmlImportAstXPathClause extends XmlImportAstStatement |
| 16 | { |
| 17 | /** |
| 18 | * XPath expression |
| 19 | * |
| 20 | * @var XmlImportAstXPath |
| 21 | */ |
| 22 | private $xpath; |
| 23 | |
| 24 | /** |
| 25 | * Clause body |
| 26 | * |
| 27 | * @var XmlImportAstSequence |
| 28 | */ |
| 29 | private $body; |
| 30 | |
| 31 | /** |
| 32 | * Creates new instance |
| 33 | * |
| 34 | * @param XmlImportAstXPath $xpath |
| 35 | * @param XmlImportAstSequence $body |
| 36 | */ |
| 37 | public function __construct(XmlImportAstXPath $xpath, XmlImportAstSequence $body) |
| 38 | { |
| 39 | $this->xpath = $xpath; |
| 40 | $this->body = $body; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Gets XPath |
| 45 | * |
| 46 | * @return XmlImportAstXPath |
| 47 | */ |
| 48 | public function getXpath() |
| 49 | { |
| 50 | return $this->xpath; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets clause body |
| 55 | * |
| 56 | * @return XmlImportAstSequence |
| 57 | */ |
| 58 | public function getBody() |
| 59 | { |
| 60 | return $this->body; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * String representation of a clause |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | public function __toString() |
| 69 | { |
| 70 | $result = "--> begin " . get_class($this) . "\n"; |
| 71 | $result .= ' XPath: ' . $this->xpath . "\n"; |
| 72 | $result .= " Body:\n"; |
| 73 | |
| 74 | $array = explode("\n", $this->body); |
| 75 | for ($i = 0; $i < count($array); $i++) |
| 76 | { |
| 77 | $array[$i] = ' ' . $array[$i]; |
| 78 | } |
| 79 | |
| 80 | $result .= implode("\n", $array) . "\n"; |
| 81 | $result .= "--> end " . get_class($this) . "\n"; |
| 82 | return $result; |
| 83 | } |
| 84 | } |
| 85 |