Changeset 1192

Show
Ignore:
Timestamp:
12/26/07 20:37:22 (8 months ago)
Author:
mikey
Message:

added support for is_readable()
As long as file modes are not supported the result will be true for existing pathes and false for non-existing pathes.

Files:

Legend:

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

    r1191 r1192  
    4343- added vfsStream::path() method as opposite to vfsStream::url() 
    4444- a call to vfsStreamWrapper::register() will now reset the root to null (implemented because of a hint by David Zülke) 
     45- added support for is_readable() 
    4546')); 
    4647 
  • trunk/src/main/php/org/stubbles/vfs/vfsStreamAbstractContent.php

    r1143 r1192  
    7878     * returns the type of the container 
    7979     * 
    80      * @return  string 
     80     * @return  int 
    8181     */ 
    8282    public function getType() 
  • trunk/src/main/php/org/stubbles/vfs/vfsStreamContent.php

    r1143 r1192  
    1515    /** 
    1616     * stream content type: file 
     17     * 
     18     * @see  getType() 
    1719     */ 
    18     const TYPE_FILE = 'file'
     20    const TYPE_FILE = 0100000
    1921    /** 
    2022     * stream content type: directory 
     23     * 
     24     * @see  getType() 
    2125     */ 
    22     const TYPE_DIR  = 'dir'; 
     26    const TYPE_DIR  = 0040000; 
     27    /** 
     28     * stream content type: symbolic link 
     29     * 
     30     * @see  getType(); 
     31     */ 
     32    #const TYPE_LINK = 0120000; 
    2333 
    2434    /** 
     
    5565     * returns the type of the container 
    5666     * 
    57      * @return  string 
     67     * @return  int 
    5868     */ 
    5969    public function getType(); 
  • trunk/src/main/php/org/stubbles/vfs/vfsStreamWrapper.php

    r1189 r1192  
    212212     * 
    213213     * @return  array 
     214     * @todo    implement correct group and user id handling based on content 
     215     * @todo    implement correct file mode handling based on content 
    214216     */ 
    215217    public function stream_stat() 
    216218    { 
    217         return array('size' => $this->content->size()); 
     219        return array(2       => $this->content->getType() + octdec(0777), 
     220                     4       => 0, 
     221                     5       => 0, 
     222                     7       => $this->content->size(), 
     223                     9       => $this->content->filemtime(), 
     224                     'mode'  => $this->content->getType() + octdec(0777), 
     225                     'uid'   => 0, 
     226                     'gid'   => 0, 
     227                     'size'  => $this->content->size(), 
     228                     'mtime' => $this->content->filemtime() 
     229               ); 
    218230    } 
    219231 
     
    422434     * @param   string  $path  path of url to return status for 
    423435     * @return  array 
     436     * @todo    implement correct group and user id handling based on content 
     437     * @todo    implement correct file mode handling based on content 
    424438     */ 
    425439    public function url_stat($path) 
     
    438452        } 
    439453         
    440         return array('size'  => (($content->getType() !== vfsStreamContent::TYPE_DIR) ? ($content->size()) : (0)), 
     454        return array(2       => $content->getType() + octdec(0777), 
     455                     4       => 0, 
     456                     5       => 0, 
     457                     7       => (($content->getType() !== vfsStreamContent::TYPE_DIR) ? ($content->size()) : (0)), 
     458                     9       => $content->filemtime(), 
     459                     'mode'  => $content->getType() + octdec(0777), 
     460                     'uid'   => 0, 
     461                     'gid'   => 0, 
     462                     'size'  => (($content->getType() !== vfsStreamContent::TYPE_DIR) ? ($content->size()) : (0)), 
    441463                     'mtime' => $content->filemtime() 
    442464               ); 
  • trunk/src/test/php/org/stubbles/vfs/vfsStreamWrapperTestCase.php

    r1188 r1192  
    240240        $this->assertTrue($another->hasChild('more')); 
    241241    } 
     242 
     243    /** 
     244     * assert dirname() returns correct directory name 
     245     */ 
     246    public function testDirname() 
     247    { 
     248        $this->assertEqual(dirname($this->barURL), $this->fooURL); 
     249        $this->assertEqual(dirname($this->baz1URL), $this->barURL); 
     250        # returns "vfs:" instead of "." 
     251        # however this seems not to be fixable because dirname() does not 
     252        # call the stream wrapper 
     253        #$this->assertEqual(dirname(vfsStream::url('doesNotExist')), '.'); 
     254    } 
     255 
     256    /** 
     257     * assert basename() returns correct file name 
     258     */ 
     259    public function testBasename() 
     260    { 
     261        $this->assertEqual(basename($this->barURL), 'bar'); 
     262        $this->assertEqual(basename($this->baz1URL), 'baz1'); 
     263        $this->assertEqual(basename(vfsStream::url('doesNotExist')), 'doesNotExist'); 
     264    } 
     265 
     266    /** 
     267     * assert is_readable() returns always true for existing pathes 
     268     * 
     269     * As long as file mode is not supported, existing pathes will lead to true, 
     270     * and non-existing pathes to false. 
     271     */ 
     272    public function testIs_readable() 
     273    { 
     274        $this->assertTrue(is_readable($this->fooURL)); 
     275        $this->assertTrue(is_readable($this->barURL)); 
     276        $this->assertTrue(is_readable($this->baz1URL)); 
     277        $this->assertTrue(is_readable($this->baz2URL)); 
     278        $this->assertFalse(is_readable($this->fooURL . '/another')); 
     279        $this->assertFalse(is_readable(vfsStream::url('another'))); 
     280    } 
    242281} 
    243282?>