Changeset 218

Show
Ignore:
Timestamp:
02/06/07 10:05:27 (2 years ago)
Author:
mikey
Message:

renamed net.stubbles.star.StarLoader? to net.stubbles.star.StarStreamWrapper?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/star/build.xml

    r128 r218  
    2828    <echo>-----------------------------</echo> 
    2929    <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" /> 
    3132    <copy file="${pkg.dir}/LICENSE" tofile="${build.src.dir}/LICENSE" /> 
    3233    <append destFile="${build.src.dir}/VERSION">star version ${version}</append> 
  • trunk/build/star/compile-writer-archive.ini

    r115 r218  
    33 
    44[INCLUDES] 
    5 net.stubbles.star.StarException="src/main/php/net/stubbles/star/StarException.php" 
    65net.stubbles.star.StarFile="src/main/php/net/stubbles/star/StarFile.php" 
    76net.stubbles.star.StarWriter="src/main/php/net/stubbles/star/StarWriter.php" 
  • trunk/build/star/compile-writer-cli.ini

    r117 r218  
    33 
    44[INCLUDES] 
    5 net.stubbles.star.StarException="src/main/php/net/stubbles/star/StarException.php" 
    65net.stubbles.star.StarFile="src/main/php/net/stubbles/star/StarFile.php" 
    76net.stubbles.star.StarWriter="src/main/php/net/stubbles/star/StarWriter.php" 
  • trunk/build/star/preface-writer.php

    r115 r218  
    11<?php 
    2 require 'star://' . __FILE__ . '?net.stubbles.star.StarException'; 
    32require 'star://' . __FILE__ . '?net.stubbles.star.StarFile'; 
    43require 'star://' . __FILE__ . '?net.stubbles.star.StarWriter'; 
  • trunk/lib/starReader.php

    r178 r218  
    11<?php 
    22/** 
    3  * Class for reading classes from star archives via stream wrapper. 
     3 * Class for reading data from star archives via stream wrapper. 
    44 *  
    55 * This class contains code from lang.base.php of the XP-framework, 
     
    1010 */ 
    1111/** 
    12  * Class for reading classes from star archives via stream wrapper. 
     12 * Class for reading data from star archives via stream wrapper. 
    1313 *  
    1414 * This class contains code from lang.base.php of the XP-framework, 
     
    1616 *  
    1717 * @package  star 
    18  */ 
    19 class StarLoader 
     18 * @see      http://php.net/stream_wrapper_register 
     19 */ 
     20class StarStreamWrapper 
    2021{ 
    2122    /** 
     23     * switch whether class has already been registered as stream wrapper or not 
     24     * 
     25     * @var  bool 
     26     */ 
     27    private static $registered = false; 
     28    /** 
    2229     * current position in star archive 
    2330     * 
     
    3239    protected $archive; 
    3340    /** 
    34      * full qualified class name of current class to retrieve 
     41     * id of the file entry to retrieve 
    3542     * 
    3643     * @var  string 
    3744     */ 
    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    } 
    3964     
    4065    /** 
     
    94119        $this->parsePath($path); 
    95120        $current = self::acquire($this->archive); 
    96         return isset($current['index'][$this->fqClassName]); 
     121        return isset($current['index'][$this->id]); 
    97122    } 
    98123     
     
    103128     * @return  string 
    104129     */ 
    105     function stream_read($count) 
     130    public function stream_read($count) 
    106131    { 
    107132        $current = self::acquire($this->archive); 
    108         if (isset($current['index'][$this->fqClassName]) == false) { 
     133        if (isset($current['index'][$this->id]) == false) { 
    109134            return false; 
    110135        } 
    111136         
    112         if ($current['index'][$this->fqClassName]['size'] == $this->position || 0 == $count) { 
     137        if ($current['index'][$this->id]['size'] == $this->position || 0 == $count) { 
    113138            return false; 
    114139        } 
    115140 
    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); 
    119144        return $bytes; 
    120145    } 
     
    125150     * @return  bool 
    126151     */ 
    127     function stream_eof() 
     152    public function stream_eof() 
    128153    { 
    129154        $current= self::acquire($this->archive); 
    130         return $this->position >= $current['index'][$this->fqClassName]['size']; 
     155        return $this->position >= $current['index'][$this->id]['size']; 
    131156    } 
    132157 
     
    139164    { 
    140165        $current = self::acquire($this->archive); 
    141         return array('size' => $current['index'][$this->fqClassName]['size']); 
     166        return array('size' => $current['index'][$this->id]['size']); 
    142167    } 
    143168 
     
    153178        $current = self::acquire($this->archive); 
    154179 
    155         if (isset($current['index'][$this->fqClassName]) == false) { 
     180        if (isset($current['index'][$this->id]) == false) { 
    156181            return false; 
    157182        } 
    158183         
    159         return array('size' => $current['index'][$this->fqClassName]['size']); 
     184        return array('size' => $current['index'][$this->id]['size']); 
    160185    } 
    161186     
     
    167192    protected function parsePath($path) 
    168193    { 
    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
    172197    } 
    173198} 
    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 */ 
     211class StarException extends Exception 
     212
     213    // intentionally left empty 
     214
     215?><?php StarStreamWrapper::register(); ?><?php 
    175216require 'star://' . __FILE__ . '?net.stubbles.star.StarClassRegistry'; 
    176 ?><?php __halt_compiler();star1net.stubbles.star.StarClassRegistryStarClassRegistry.phpsrc/main/php/net/stubbles/star45585257<?php 
     217?><?php __halt_compiler();star1net.stubbles.star.StarClassRegistryStarClassRegistry.phpsrc/main/php/net/stubbles/star45656151<?php 
    177218/** 
    178219 * Class registry for mapping of classes to star files. 
     
    307348                } 
    308349                 
    309                 $archiveData = StarLoader::acquire($file->getPathname()); 
     350                $archiveData = StarStreamWrapper::acquire($file->getPathname()); 
    310351                if (empty($archiveData) == true) { 
    311352                    continue; 
  • trunk/src/main/php/net/stubbles/star/LICENSE

    r92 r218  
    2929 
    3030Star is inspired by and contains code from the XP-framework's xar  
    31 archive files. Code from the XP-framework has been used for StarLoader.php 
    32 and StarArchive.php. The following license applies to the affected code: 
     31archive files. Code from the XP-framework has been used for  
     32StarStreamWrapper.php and StarArchive.php. The following license  
     33applies to the affected code: 
    3334XP: LICENCE 
    3435======================================================================== 
  • trunk/src/main/php/net/stubbles/star/StarArchive.php

    r159 r218  
    3232    protected $preface; 
    3333    /** 
    34      * switch whether to prepend the StarLoader class in preface or not 
     34     * switch whether to prepend the StarStreamWrapper class in preface or not 
    3535     * 
    3636     * @var  bool 
    3737     */ 
    38     protected $prependStarLoader = true; 
     38    protected $prependStreamWrapper = true; 
    3939    /** 
    4040     * the index of files to put into the star 
     
    4242     * @var  array 
    4343     */ 
    44     protected $index = array(); 
     44    protected $index                = array(); 
    4545    /** 
    4646     * star archive version 
    4747     */ 
    48     const VERSION    = 1; 
     48    const VERSION                   = 1; 
    4949     
    5050    /** 
     
    8080     * 
    8181     * @param  string  $preface 
    82      * @param  bool    $prependStarLoader  optional 
     82     * @param  bool    $prependStreamWrapper  optional 
    8383     */ 
    84     public function setPreface($preface, $prependStarLoader = true) 
     84    public function setPreface($preface, $prependStreamWrapper = true) 
    8585    { 
    8686        $this->preface = $preface; 
     
    9191        } 
    9292         
    93         $this->prependStarLoader = $prependStarLoader; 
     93        $this->prependStreamWrapper = $prependStreamWrapper; 
    9494    } 
    9595     
     
    105105        if (strlen($this->preface) > 0) { 
    106106            $preFace = ''; 
    107             if (true == $this->prependStarLoader) { 
    108                 $preFace .= file_get_contents(dirname(__FILE__) . '/StarLoader.php'); 
    109                 $preFace .= "<?php stream_wrapper_register('star', 'StarLoader'); ?>"; 
     107            if (true == $this->prependStreamWrapper) { 
     108                $preFace .= file_get_contents(dirname(__FILE__) . '/StarStreamWrapper.php'); 
     109                $preFace .= file_get_contents(dirname(__FILE__) . '/StarException.php'); 
     110                $preFace .= "<?php StarStreamWrapper::register(); ?>"; 
    110111            } 
    111112            $preFace .= trim($this->preface) . "<?php __halt_compiler();"; 
  • trunk/src/main/php/net/stubbles/star/StarClassRegistry.php

    r160 r218  
    132132                } 
    133133                 
    134                 $archiveData = StarLoader::acquire($file->getPathname()); 
     134                $archiveData = StarStreamWrapper::acquire($file->getPathname()); 
    135135                if (empty($archiveData) == true) { 
    136136                    continue; 
  • trunk/src/main/php/net/stubbles/star/StarStreamWrapper.php

    r132 r218  
    11<?php 
    22/** 
    3  * Class for reading classes from star archives via stream wrapper. 
     3 * Class for reading data from star archives via stream wrapper. 
    44 *  
    55 * This class contains code from lang.base.php of the XP-framework, 
     
    1010 */ 
    1111/** 
    12  * Class for reading classes from star archives via stream wrapper. 
     12 * Class for reading data from star archives via stream wrapper. 
    1313 *  
    1414 * This class contains code from lang.base.php of the XP-framework, 
     
    1616 *  
    1717 * @package  star 
     18 * @see      http://php.net/stream_wrapper_register 
    1819 */ 
    19 class StarLoader 
     20class StarStreamWrapper 
    2021{ 
     22    /** 
     23     * switch whether class has already been registered as stream wrapper or not 
     24     * 
     25     * @var  bool 
     26     */ 
     27    private static $registered = false; 
    2128    /** 
    2229     * current position in star archive 
     
    3239    protected $archive; 
    3340    /** 
    34      * full qualified class name of current class to retrieve 
     41     * id of the file entry to retrieve 
    3542     * 
    3643     * @var  string 
    3744     */ 
    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    } 
    3964     
    4065    /** 
     
    94119        $this->parsePath($path); 
    95120        $current = self::acquire($this->archive); 
    96         return isset($current['index'][$this->fqClassName]); 
     121        return isset($current['index'][$this->id]); 
    97122    } 
    98123     
     
    103128     * @return  string 
    104129     */ 
    105     function stream_read($count) 
     130    public function stream_read($count) 
    106131    { 
    107132        $current = self::acquire($this->archive); 
    108         if (isset($current['index'][$this->fqClassName]) == false) { 
     133        if (isset($current['index'][$this->id]) == false) { 
    109134            return false; 
    110135        } 
    111136         
    112         if ($current['index'][$this->fqClassName]['size'] == $this->position || 0 == $count) { 
     137        if ($current['index'][$this->id]['size'] == $this->position || 0 == $count) { 
    113138            return false; 
    114139        } 
    115140 
    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); 
    119144        return $bytes; 
    120145    } 
     
    125150     * @return  bool 
    126151     */ 
    127     function stream_eof() 
     152    public function stream_eof() 
    128153    { 
    129154        $current= self::acquire($this->archive); 
    130         return $this->position >= $current['index'][$this->fqClassName]['size']; 
     155        return $this->position >= $current['index'][$this->id]['size']; 
    131156    } 
    132157 
     
    139164    { 
    140165        $current = self::acquire($this->archive); 
    141         return array('size' => $current['index'][$this->fqClassName]['size']); 
     166        return array('size' => $current['index'][$this->id]['size']); 
    142167    } 
    143168 
     
    153178        $current = self::acquire($this->archive); 
    154179 
    155         if (isset($current['index'][$this->fqClassName]) == false) { 
     180        if (isset($current['index'][$this->id]) == false) { 
    156181            return false; 
    157182        } 
    158183         
    159         return array('size' => $current['index'][$this->fqClassName]['size']); 
     184        return array('size' => $current['index'][$this->id]['size']); 
    160185    } 
    161186     
     
    167192    protected function parsePath($path) 
    168193    { 
    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
    172197    } 
    173198}