ast
1 month ago
XmlImportConfig.php
1 month ago
XmlImportCsvParse.php
1 month ago
XmlImportException.php
1 month ago
XmlImportParser.php
1 month ago
XmlImportReaderInterface.php
1 month ago
XmlImportSQLParse.php
1 month ago
XmlImportStringReader.php
1 month ago
XmlImportTemplate.php
1 month ago
XmlImportTemplateCodeGenerator.php
1 month ago
XmlImportTemplateParser.php
1 month ago
XmlImportTemplateScanner.php
3 days ago
XmlImportToken.php
1 month ago
XmlImportXLSParse.php
1 month ago
wpaipclzip.lib.php
1 month ago
XmlImportStringReader.php
68 lines
| 1 | <?php |
| 2 | // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals |
| 3 | /** |
| 4 | * @author Olexandr Zanichkovsky <olexandr.zanichkovsky@zophiatech.com> |
| 5 | * @package General |
| 6 | */ |
| 7 | |
| 8 | require_once dirname(__FILE__) . '/XmlImportReaderInterface.php'; |
| 9 | |
| 10 | /** |
| 11 | * Allows to either peek or read a character from a string buffer |
| 12 | */ |
| 13 | class XmlImportStringReader implements XmlImportReaderInterface |
| 14 | { |
| 15 | /** |
| 16 | * String buffer |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | private $buffer; |
| 21 | |
| 22 | /** |
| 23 | * Current index |
| 24 | * |
| 25 | * @var int |
| 26 | */ |
| 27 | private $index = -1; |
| 28 | |
| 29 | /** |
| 30 | * Creates new instance |
| 31 | * |
| 32 | * @param string $input |
| 33 | */ |
| 34 | public function __construct($input) |
| 35 | { |
| 36 | if (is_string($input)) |
| 37 | $this->buffer = $input; |
| 38 | else |
| 39 | throw new InvalidArgumentException(esc_html("String expected as argument.")); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns the next symbol from the buffer without changes to current index |
| 44 | * or false if buffer ends |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public function peek() |
| 49 | { |
| 50 | if ($this->index + 1 >= strlen($this->buffer)) |
| 51 | return false; |
| 52 | else |
| 53 | return $this->buffer[$this->index + 1]; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the next symbol from the buffer or false if buffer is ended |
| 58 | * |
| 59 | * @return string |
| 60 | */ |
| 61 | public function read() |
| 62 | { |
| 63 | $result = $this->peek(); |
| 64 | if ($this->index < strlen($this->buffer)) |
| 65 | $this->index++; |
| 66 | return $result; |
| 67 | } |
| 68 | } |