Textpattern | PHP Cross Reference | Content Management Systems |
Description: Iterates over the given Textpack strings.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Iterates over the given Textpack strings. 26 * 27 * <code> 28 * foreach (Txp::get('\Textpattern\Textpack\String\Iterator', 'en-gb.textpack') as $name => $string) { 29 * echo "{$name} is translated to: {$string} in " . $string->getLanguage(); 30 * } 31 * </code> 32 * 33 * @since 4.6.0 34 * @package Textpack 35 */ 36 37 namespace Textpattern\Textpack\String; 38 39 class Iterator extends \Textpattern\Iterator\FileIterator implements \Textpattern\Textpack\StringInterface 40 { 41 /** 42 * Stores Textpack parser instance. 43 * 44 * @var \Textpattern\Textpack\Parser 45 */ 46 47 protected $parser; 48 49 /** 50 * {@inheritdoc} 51 */ 52 53 public function __construct($filename) 54 { 55 $this->parser = \Txp::get('\Textpattern\Textpack\Parser'); 56 parent::__construct($filename); 57 } 58 59 /** 60 * Returns the translation string. 61 * 62 * @return string 63 */ 64 65 public function __toString() 66 { 67 return (string)$this->getString(); 68 } 69 70 /** 71 * Returns the current element. 72 * 73 * @return Iterator 74 */ 75 76 public function current() 77 { 78 return $this; 79 } 80 81 /** 82 * {@inheritdoc} 83 */ 84 85 public function getName() 86 { 87 return $this->current['name']; 88 } 89 90 /** 91 * {@inheritdoc} 92 */ 93 94 public function getLanguage() 95 { 96 return $this->current['lang']; 97 } 98 99 /** 100 * {@inheritdoc} 101 */ 102 103 public function getString() 104 { 105 return $this->current['data']; 106 } 107 108 /** 109 * {@inheritdoc} 110 */ 111 112 public function getEvent() 113 { 114 return $this->current['event']; 115 } 116 117 /** 118 * {@inheritdoc} 119 */ 120 121 public function getOwner() 122 { 123 return $this->current['owner']; 124 } 125 126 /** 127 * {@inheritdoc} 128 */ 129 130 public function getVersion() 131 { 132 return $this->current['version']; 133 } 134 135 /** 136 * {@inheritdoc} 137 */ 138 139 public function getLastmod() 140 { 141 return $this->current['lastmod']; 142 } 143 144 /** 145 * {@inheritdoc} 146 */ 147 148 public function next() 149 { 150 $buffer = ''; 151 152 while (1) { 153 parent::next(); 154 155 if ($this->valid() === false) { 156 return; 157 } 158 159 $buffer .= $this->current."\n"; 160 161 if ($string = $this->parser->parse($buffer)) { 162 $this->current = $string[0]; 163 $this->key = $this->current['name']; 164 165 return; 166 } 167 } 168 } 169 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title