Changeset 1189

Show
Ignore:
Timestamp:
12/25/07 19:20:13 (8 months ago)
Author:
mikey
Message:

added vfsStream::path() method as opposite to vfsStream::url()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/vfs/package.php

    r1188 r1189  
    4141- moved vfsStreamWrapper::PROTOCOL to vfsStream::SCHEME 
    4242- added new vfsStream::url() method to assist in creating correct vfsStream urls 
     43- added vfsStream::path() method as opposite to vfsStream::url() 
    4344- a call to vfsStreamWrapper::register() will now reset the root to null (implemented because of a hint by David Zülke) 
    4445EOT; 
  • trunk/src/main/php/org/stubbles/vfs/vfsStream.php

    r1183 r1189  
    2323     * prepends the scheme to the given URL 
    2424     * 
     25     * @param   string  $path 
     26     * @return  string 
     27     */ 
     28    public static function url($path) 
     29    { 
     30        return self::SCHEME . '://' . str_replace(DIRECTORY_SEPARATOR, '/', $path); 
     31    } 
     32 
     33    /** 
     34     * restores the path from the url 
     35     * 
    2536     * @param   string  $url 
    2637     * @return  string 
    2738     */ 
    28     public static function url($url) 
     39    public static function path($url) 
    2940    { 
    30         return self::SCHEME . '://' . $url; 
     41        $path = substr($url, strlen(self::SCHEME . '://')); 
     42        $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); 
     43        return $path; 
    3144    } 
    3245} 
  • trunk/src/main/php/org/stubbles/vfs/vfsStreamWrapper.php

    r1188 r1189  
    8787 
    8888    /** 
    89      * helper method to parse the path 
    90      * 
    91      * @param   string  $path 
    92      * @return  string 
    93      */ 
    94     protected static function parsePath($path) 
    95     { 
    96         $path = substr($path, strlen(vfsStream::SCHEME . '://')); 
    97         $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); 
    98         return $path; 
    99     } 
    100  
    101     /** 
    10289     * open the stream 
    10390     * 
     
    115102        } 
    116103         
    117         $path = self::parsePath($path); 
     104        $path = vfsStream::path($path); 
    118105        if (self::$root->getName() === $path) { 
    119106            $this->content = self::$root; 
     
    243230        } 
    244231         
    245         $realPath = self::parsePath($path); 
     232        $realPath = vfsStream::path($path); 
    246233        if (self::$root->getName() === $realPath) { 
    247234            // delete root? very brave. :) 
     
    295282        } 
    296283         
    297         $path         = self::parsePath($path); 
     284        $path         = vfsStream::path($path); 
    298285        $lastSlashPos = strrpos($path, '/'); 
    299286        $recursive    = ((STREAM_MKDIR_RECURSIVE & $options) !== 0) ? (true) : (false); 
     
    378365        } 
    379366         
    380         $path = self::parsePath($path); 
     367        $path = vfsStream::path($path); 
    381368        if (self::$root->getName() === $path) { 
    382369            $this->dir = self::$root; 
     
    442429        } 
    443430         
    444         $path = self::parsePath($path); 
     431        $path = vfsStream::path($path); 
    445432        if (self::$root->getName() === $path) { 
    446433            $content = self::$root; 
  • trunk/src/test/php/org/stubbles/vfs/vfsStreamTestCase.php

    r1183 r1189  
    1717class vfsStreamTestCase extends UnitTestCase 
    1818{ 
    19  
    2019    /** 
    21      * assure that a url builder works correct 
     20     * assure that path2url conversion works correct 
    2221     */ 
    2322    public function testURL() 
     
    2524        $this->assertEqual('vfs://foo', vfsStream::url('foo')); 
    2625        $this->assertEqual('vfs://foo/bar.baz', vfsStream::url('foo/bar.baz')); 
     26        $this->assertEqual('vfs://foo/bar.baz', vfsStream::url('foo\bar.baz')); 
     27    } 
     28 
     29    /** 
     30     * assure that url2path conversion works correct 
     31     */ 
     32    public function testPath() 
     33    { 
     34        $this->assertEqual('foo', vfsStream::path('vfs://foo')); 
     35        $this->assertEqual('foo/bar.baz', vfsStream::path('vfs://foo/bar.baz')); 
     36        $this->assertEqual('foo/bar.baz', vfsStream::path('vfs://foo\bar.baz')); 
    2737    } 
    2838}