Changeset 218
- Timestamp:
- 02/06/07 10:05:27 (2 years ago)
- Files:
-
- trunk/build/star/build.xml (modified) (1 diff)
- trunk/build/star/compile-writer-archive.ini (modified) (1 diff)
- trunk/build/star/compile-writer-cli.ini (modified) (1 diff)
- trunk/build/star/preface-writer.php (modified) (1 diff)
- trunk/lib/starReader.php (modified) (11 diffs)
- trunk/src/main/php/net/stubbles/star/LICENSE (modified) (1 diff)
- trunk/src/main/php/net/stubbles/star/StarArchive.php (modified) (5 diffs)
- trunk/src/main/php/net/stubbles/star/StarClassRegistry.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/star/StarStreamWrapper.php (moved) (moved from trunk/src/main/php/net/stubbles/star/StarLoader.php) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/star/build.xml
r128 r218 28 28 <echo>-----------------------------</echo> 29 29 <delete dir="${build.src.dir}"/> 30 <copy file="${pkg.dir}/StarLoader.php" tofile="${build.src.dir}/StarLoader.php" /> 30 <copy file="${pkg.dir}/StarStreamWrapper.php" tofile="${build.src.dir}/StarStreamWrapper.php" /> 31 <copy file="${pkg.dir}/StarException.php" tofile="${build.src.dir}/StarException.php" /> 31 32 <copy file="${pkg.dir}/LICENSE" tofile="${build.src.dir}/LICENSE" /> 32 33 <append destFile="${build.src.dir}/VERSION">star version ${version}</append> trunk/build/star/compile-writer-archive.ini
r115 r218 3 3 4 4 [INCLUDES] 5 net.stubbles.star.StarException="src/main/php/net/stubbles/star/StarException.php"6 5 net.stubbles.star.StarFile="src/main/php/net/stubbles/star/StarFile.php" 7 6 net.stubbles.star.StarWriter="src/main/php/net/stubbles/star/StarWriter.php" trunk/build/star/compile-writer-cli.ini
r117 r218 3 3 4 4 [INCLUDES] 5 net.stubbles.star.StarException="src/main/php/net/stubbles/star/StarException.php"6 5 net.stubbles.star.StarFile="src/main/php/net/stubbles/star/StarFile.php" 7 6 net.stubbles.star.StarWriter="src/main/php/net/stubbles/star/StarWriter.php" trunk/build/star/preface-writer.php
r115 r218 1 1 <?php 2 require 'star://' . __FILE__ . '?net.stubbles.star.StarException';3 2 require 'star://' . __FILE__ . '?net.stubbles.star.StarFile'; 4 3 require 'star://' . __FILE__ . '?net.stubbles.star.StarWriter'; trunk/lib/starReader.php
r178 r218 1 1 <?php 2 2 /** 3 * Class for reading classesfrom star archives via stream wrapper.3 * Class for reading data from star archives via stream wrapper. 4 4 * 5 5 * This class contains code from lang.base.php of the XP-framework, … … 10 10 */ 11 11 /** 12 * Class for reading classesfrom star archives via stream wrapper.12 * Class for reading data from star archives via stream wrapper. 13 13 * 14 14 * This class contains code from lang.base.php of the XP-framework, … … 16 16 * 17 17 * @package star 18 */ 19 class StarLoader 18 * @see http://php.net/stream_wrapper_register 19 */ 20 class StarStreamWrapper 20 21 { 21 22 /** 23 * switch whether class has already been registered as stream wrapper or not 24 * 25 * @var bool 26 */ 27 private static $registered = false; 28 /** 22 29 * current position in star archive 23 30 * … … 32 39 protected $archive; 33 40 /** 34 * full qualified class name of current classto retrieve41 * id of the file entry to retrieve 35 42 * 36 43 * @var string 37 44 */ 38 protected $fqClassName; 45 protected $id; 46 47 /** 48 * registers the class as stream wrapper for the star protocol 49 * 50 * @throws StarException 51 */ 52 public static function register() 53 { 54 if (true == self::$registered) { 55 return; 56 } 57 58 if (stream_wrapper_register('star', __CLASS__) == false) { 59 throw new StarException('A handler has already been registered for the star protocol.'); 60 } 61 62 self::$registered = true; 63 } 39 64 40 65 /** … … 94 119 $this->parsePath($path); 95 120 $current = self::acquire($this->archive); 96 return isset($current['index'][$this-> fqClassName]);121 return isset($current['index'][$this->id]); 97 122 } 98 123 … … 103 128 * @return string 104 129 */ 105 function stream_read($count)130 public function stream_read($count) 106 131 { 107 132 $current = self::acquire($this->archive); 108 if (isset($current['index'][$this-> fqClassName]) == false) {133 if (isset($current['index'][$this->id]) == false) { 109 134 return false; 110 135 } 111 136 112 if ($current['index'][$this-> fqClassName]['size'] == $this->position || 0 == $count) {137 if ($current['index'][$this->id]['size'] == $this->position || 0 == $count) { 113 138 return false; 114 139 } 115 140 116 fseek($current['handle'], 0x0100 + sizeof($current['index']) * 0x0100 + $current['index'][$this-> fqClassName]['offset'] + $this->position, SEEK_SET);117 $bytes = fread($current['handle'], min($current['index'][$this-> fqClassName]['size'] - $this->position, $count));118 $this->position += strlen($bytes); 141 fseek($current['handle'], 0x0100 + sizeof($current['index']) * 0x0100 + $current['index'][$this->id]['offset'] + $this->position, SEEK_SET); 142 $bytes = fread($current['handle'], min($current['index'][$this->id]['size'] - $this->position, $count)); 143 $this->position += strlen($bytes); 119 144 return $bytes; 120 145 } … … 125 150 * @return bool 126 151 */ 127 function stream_eof()152 public function stream_eof() 128 153 { 129 154 $current= self::acquire($this->archive); 130 return $this->position >= $current['index'][$this-> fqClassName]['size'];155 return $this->position >= $current['index'][$this->id]['size']; 131 156 } 132 157 … … 139 164 { 140 165 $current = self::acquire($this->archive); 141 return array('size' => $current['index'][$this-> fqClassName]['size']);166 return array('size' => $current['index'][$this->id]['size']); 142 167 } 143 168 … … 153 178 $current = self::acquire($this->archive); 154 179 155 if (isset($current['index'][$this-> fqClassName]) == false) {180 if (isset($current['index'][$this->id]) == false) { 156 181 return false; 157 182 } 158 183 159 return array('size' => $current['index'][$this-> fqClassName]['size']);184 return array('size' => $current['index'][$this->id]['size']); 160 185 } 161 186 … … 167 192 protected function parsePath($path) 168 193 { 169 list($archive, $ fqClassName) = sscanf($path, 'star://%[^?]?%[^$]');170 $this->archive = $archive;171 $this-> fqClassName = $fqClassName;194 list($archive, $id) = sscanf($path, 'star://%[^?]?%[^$]'); 195 $this->archive = $archive; 196 $this->id = $id; 172 197 } 173 198 } 174 ?><?php stream_wrapper_register('star', 'StarLoader'); ?><?php 199 ?><?php 200 /** 201 * Exception to be thrown in case something wents wrong with handlign star files. 202 * 203 * @author Frank Kleine <mikey@stubbles.net> 204 * @package star 205 */ 206 /** 207 * Exception to be thrown in case something wents wrong with handlign star files. 208 * 209 * @package star 210 */ 211 class StarException extends Exception 212 { 213 // intentionally left empty 214 } 215 ?><?php StarStreamWrapper::register(); ?><?php 175 216 require 'star://' . __FILE__ . '?net.stubbles.star.StarClassRegistry'; 176 ?><?php __halt_compiler();star1
