Re: Bug #4229 [Asn]: Stream_Var needs url_stat method

From: Date: Mon, 09 Jul 2007 00:13:11 +0000
Subject: Re: Bug #4229 [Asn]: Stream_Var needs url_stat method
References: 1  Groups: php.pear.qa 
Request: Send a blank email to pear-qa+get-4433@lists.php.net to get a copy of this message
If the package maintainer, Stephan Schmidt, is happy I can make the necessary changes (as outlined in my bug report) and commit as I already have a PEAR account & access. Thanks Alex > ATTENTION! Do NOT reply to this email! > To reply, use the web interface found at > http://pear.php.net/bugs/bug.php?id=4229&edit=2 > > > ID: 4229 > Updated by: cweiske@php.net > Reported By: alex at amcms dot org > Summary: Stream_Var needs url_stat method > Status: Assigned > Type: Bug > Package: Stream_Var > PHP Version: Irrelevant > Assigned To: schst > New Comment: > > Could someone fix this please? > > > Previous Comments: > ------------------------------------------------------------------------ > > [2006-08-22 21:29:37] ahayes at php dot net > > Please use this class instead of the one placed in previous comment > (slight documentation fixes only). > > Note that this will mean that you will need to replace all occurances > of Stream_Var with Stream_Var_Stat. > > This code is essentially in alpha state (hence the version number). It > has been tested, but not unit tested. Its intention is just to get you > by until a proper solution exists within Stream_Var. > > ============8<============== > <?php > > require_once "Stream/Var.php"; > > // {{{ class Stream_Var_Stat > > /** > * Provides url_stat capabilities to Stream_Var > * > * Until this functionality exists in Stream_Var (see ticket > * http://pear.php.net/bugs/bug.php?id=4229) you can use > * this class to gain access to the url_stat methods that > * are needed by certain functions that utilise streams. > * > * Note however, for instance the fact that file_size does not > * seem to report properly, as url_stat can't seem to find > * $this->_pointer > * > * @category Stream > * @package Stream_Var_Stat > * @version 0.1.0 > * @author Alex Hayes <ahayes@wcg.net.au> > */ > class Stream_Var_Stat extends Stream_Var { > > /** > * This method is called in response to stat() calls on the URL > paths > * > * As taken from the PHP Manual: > * > * "This method is called in response to stat() calls on the URL > paths > * associated with the wrapper and should return as many elements > in > * common with the system function as possible. Unknown or > unavailable > * values should be set to a rational value (usually 0)." > * > * With regards to the implementation that is Stream_Var we can > actually fake > * some of the data. For instance, the uid and gid can be that of > the corrent > * posix_getuid and posix_getgid() > * > * The following outlines the information that we essentially > fake: > * > * - 'dev': is unknown and set to 0 > * - 'ino': is unknown and set to 0 > * - 'mode': set to 33216 (chmod 700 means user has read, write > and execute on the file) > * - 'nlink': is unknown and set to 0 > * - 'uid': if the method posix_getuid exist, this is called, > otherwise 0 is returned > * - 'gid': if the method posix_getgid exist, this is called, > otherwise 0 is returned > * - 'rdev' unknown and set to 0 > * - 'size': is set to the strlen of the pointer. > * - 'atime': set to current value returned by time() > * - 'mtime': set to current value returned by time() > * - 'ctime': set to current value returned by time() > * - 'blksize': is unknown and set to 0 > * - 'blocks': is unknown and set to 0 > * > * @param string $path The path to stat. > * @param integer $flags Holds additional flags set by the > streams API. > * It can hold one or more of the > following values > * OR'd together. > * - STREAM_URL_STAT_LINK - > currently this is > * ignored. > * - STREAM_URL_STAT_QUIET - makes > call to > * strlen quiet > * > * @return array > * > * @see http://au.php.net/stream_wrapper_register > * @author Alex Hayes <ahayes@wcg.net.au> > */ > function url_stat($path, $flags) { > > $time = time(); > > $keys = array( > 'dev' => 0, > 'ino' => 0, > 'mode' => 33216, // chmod 700 means user has > read, write and execute on the file > 'nlink' => 0, > 'uid' => function_exists('posix_getuid') ? > posix_getuid() : 0, // this processes uid > 'gid' => function_exists('posix_getgid') ? > posix_getgid() : 0, // this processes uid > 'rdev' => 0, > 'size' => $flags & STREAM_URL_STAT_QUIET ? > @strlen($this->_pointer) : strlen($this->_pointer), > 'atime' => $time, > 'mtime' => $time, > 'ctime' => $time, > 'blksize' => 0, > 'blocks' => 0 > ); > > return array_merge(array_values($keys), $keys); > > } > > } > > // }}} > > ?> > ============>8============== > > ------------------------------------------------------------------------ > > [2006-08-22 21:13:02] ahayes at php dot net > > Note, for anyone requiring this functionality, you can use the > following class. > > This has been tested on PHP5 only, and things like file_size do not > seem to work properly (as stated in the inline docs) > > ============8<============== > <?php > > require_once "Stream/Var.php"; > > // {{{ class SOAP_Fault_Util > > /** > * Provides url_stat capabilities to Stream_Var > * > * Until this functionality exists in Stream_Var (see ticket > * http://pear.php.net/bugs/bug.php?id=4229) you can use this > class to > gain access > * to the url_stat methods that are needed by certain functions that > utilise streams. > * > * Note however, for instance the fact that file_size does not > * seem to report properly, as url_stat can't seem to find > $this->_pointer > * > * @category Stream > * @package Stream_Var_Stat > * @version 0.1.0 > * @author Alex Hayes <ahayes@wcg.net.au> > */ > class Stream_Var_Stat extends Stream_Var { > > /** > * This method is called in response to stat() calls on the URL > paths > * > * As taken from the PHP Manual: > * > * "This method is called in response to stat() calls on the URL > paths > * associated with the wrapper and should return as many elements > in > * common with the system function as possible. Unknown or > unavailable > * values should be set to a rational value (usually 0)." > * > * With regards to the implementation that is Stream_Var we can > actually fake > * some of the data. For instance, the uid and gid can be that of > the corrent > * posix_getuid and posix_getgid() > * > * The following outlines the information that we essentially > fake: > * > * - dev set to 0 > * - ino set to 0 > * - mode set to 33216 (chmod 700 means user has read, write > and execute on the file) > * - nlink set to 0 > * - uid if the method posix_getuid exist, this is called, > otherwise 0 is returned > * - gid if the method posix_getgid exist, this is called, > otherwise 0 is returned > * - rdev set to 0 > * - size is set to the strlen of the pointer. > * - atime set to current value returned by time() > * - mtime set to current value returned by time() > * - ctime set to current value returned by time() > * - blksize 0 > * - blocks 0 > * > * @param string $path > * > * @see http://au.php.net/stream_wrapper_register > * @author Alex Hayes <ahayes@wcg.net.au> > */ > function url_stat($path, $flags) { > > $time = time(); > > $keys = array( > 'dev' => 0, > 'ino' => 0, > 'mode' => 33216, // chmod 700 means user has > read, write and execute on the file > 'nlink' => 0, > 'uid' => function_exists('posix_getuid') ? > posix_getuid() : 0, // this processes uid > 'gid' => function_exists('posix_getgid') ? > posix_getgid() : 0, // this processes uid > 'rdev' => 0, > 'size' => $flags & STREAM_URL_STAT_QUIET ? > @strlen($this->_pointer) : strlen($this->_pointer), > 'atime' => $time, > 'mtime' => $time, > 'ctime' => $time, > 'blksize' => 0, > 'blocks' => 0 > ); > > return array_merge(array_values($keys), $keys); > > } > > } > > // }}} > > ?> > ============>8============== > > ------------------------------------------------------------------------ > > [2005-11-03 21:33:02] ahayes > > Note however when using file_size() it does not seem to be able to find > $this->_pointer > > This is caused as for some reason, the call to file_size does not seem > to call the constructor for Stream_Var. This to me would point to an > error to do with PHP streams but I'm yet to chase this down. > > ------------------------------------------------------------------------ > > [2005-11-03 21:30:06] ahayes > > I have modified the url_stat method I previously submitted so that it > looks as follows: > > =========>8=========== > > /** > * This method is called in response to stat() calls on the URL paths > * > * @see http://au.php.net/stream_wrapper_register > * @author Alex Hayes <ahayes@wcg.net.au> > */ > function url_stat($path, $flags) { > > $time = time() - $process['times']['stime']; > > $keys = array( > 'dev' => 0, > 'ino' => 0, > 'mode' => 33216, // chmod 700, so the web user has read, > write and execute on the file > 'nlink' => 0, > 'uid' => posix_getuid(), // this processes uid > 'gid' => posix_getgid(), // this processes uid > 'rdev' => 0, > 'size' => strlen($this->_pointer), > 'atime' => $time, > 'mtime' => $time, > 'ctime' => $time, > 'blksize' => 0, > 'blocks' => 0 > ); > > return array_merge(array_values($keys), $keys); > > } > =========8<=========== > > This has not been tested extensively however it does work with > is_readable and file_exists. > > ------------------------------------------------------------------------ > > [2005-04-26 20:24:50] ahayes > > Description: > ------------ > The Stream_Var package should have a url_stat method. This is needed as > otherwise attempts to make file_exist calls (amongst others) will fail. > It already has a stream_stat method, so url_stat could almost be an > extension of this method. > > Reproduce code: > --------------- > require_once "Stream/Var.php"; > stream_wrapper_register("var", "Stream_Var"); > $GLOBALS['somefile'] = 'blah blah blah'; > if(!file_exists("var://GLOBALS/somefile")) { > die('The file does not exist'); > } > echo "file exists"; > > Expected result: > ---------------- > file exists > > Actual result: > -------------- > Actual result would be "The file does not exist" > > To fix this something as simple as: > > /** > * return information about the stream > * > * @access public > * @return array $stat information about the stream (currently > only the length is included) > */ > function url_stat() > { > $stat = $this->stream_stat(); > > $stat[7] = $stat['size']; > > return $stat; > } > > Would most likely do, however it would be nice if we actually checked > that the variable had been defined with isset in stream_stat. > > ------------------------------------------------------------------------ > > > > !DSPAM:468e6a97262801993111255! > > > --

« previous php.pear.qa (#4433) next »