Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix CS

git-svn-id: http://svn.php.net/repository/pear/packages/Stream_Var/trunk@287138 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 28869394cd22031d3418be88cc42793b9b0cc730 1 parent d99424f
@cweiske cweiske authored
Showing with 219 additions and 177 deletions.
  1. +219 −177 Var.php
View
396 Var.php
@@ -78,42 +78,52 @@
* @package Stream_Var
* @version 0.2.1
* @author Stephan Schmidt <schst@php-tools.net>
+ * @link http://pear.php.net/package/Stream_Var
*/
-class Stream_Var {
+class Stream_Var
+{
- /**
+ /**
* pointer to the variable
- * @var mixed $_pointer
+ *
+ * @var mixed $_pointer
*/
var $_pointer = null;
- /**
+ /**
* flag to indicate whether stream is open
- * @var boolean $_open
+ *
+ * @var boolean
*/
var $_open = false;
- /**
+ /**
* position
- * @var integer $_pos
+ *
+ * @var integer
*/
var $_pos = 0;
- /**
- * mode of the opened filw
- * @var integer $_mode
+ /**
+ * mode of the opened file
+ *
+ * @var integer
*/
var $_mode = 0;
- /**
- * method used by fopen
+ /**
+ * Method used by fopen.
+ *
+ * @param string $path Path to the variable
+ * (e.g. var://GLOBALS/myArray/anyIndex)
+ * @param string $mode Mode to open the stream,
+ * like 'r', 'w,',... ({@see fopen()})
+ * @param array $options Options (not implemented yet)
+ * @param string &$opened_path This will be set to the actual opened path
*
- * @access public
- * @param string $path path to the variable (e.g. var://GLOBALS/myArray/anyIndex)
- * @param string $mode mode to open the stream, like 'r', 'w,',... ({@see fopen()})
- * @param array $options options (not implemented yet)
- * @param string $opened_path this will be set to the actual opened path
* @return boolean $success
+ *
+ * @access public
*/
function stream_open($path, $mode, $options, &$opened_path)
{
@@ -124,23 +134,23 @@ function stream_open($path, $mode, $options, &$opened_path)
$mode = strtolower($mode);
switch ($mode{0}) {
- case "r":
- $status = $this->_setPointer($scope, $varpath, false);
- $this->_mode = $this->_mode | STREAM_VAR_READABLE;
- break;
- case "w":
- case "a":
- $status = $this->_setPointer($scope, $varpath, true);
- $this->_mode = $this->_mode | STREAM_VAR_WRITEABLE;
- break;
- case "x":
- $status = $this->_setPointer($scope, $varpath, false);
- if ($status) {
- return false;
- }
- $status = $this->_setPointer($scope, $varpath, true);
- $this->_mode = $this->_mode | STREAM_VAR_WRITEABLE;
- break;
+ case "r":
+ $status = $this->_setPointer($scope, $varpath, false);
+ $this->_mode = $this->_mode | STREAM_VAR_READABLE;
+ break;
+ case "w":
+ case "a":
+ $status = $this->_setPointer($scope, $varpath, true);
+ $this->_mode = $this->_mode | STREAM_VAR_WRITEABLE;
+ break;
+ case "x":
+ $status = $this->_setPointer($scope, $varpath, false);
+ if ($status) {
+ return false;
+ }
+ $status = $this->_setPointer($scope, $varpath, true);
+ $this->_mode = $this->_mode | STREAM_VAR_WRITEABLE;
+ break;
}
if (!$status) {
@@ -167,30 +177,34 @@ function stream_open($path, $mode, $options, &$opened_path)
return true;
}
- /**
- * check for end of stream
+ /**
+ * Check for end of stream.
+ *
+ * @return boolean True if at end of stream
*
* @access public
- * @return boolean $eof true if at end of stream
*/
function stream_eof()
{
return ($this->_pos >= strlen($this->_pointer));
}
- /**
- * return the current position
+ /**
+ * Return the current position.
+ *
+ * @return integer Current position in stream
*
* @access public
- * @return integer $position current position in stream
*/
function stream_tell()
{
return $this->_pos;
}
- /**
- * close the stream
+ /**
+ * Close the stream.
+ *
+ * @return void
*
* @access public
*/
@@ -200,12 +214,14 @@ function stream_close()
$this->_open = false;
}
- /**
- * read from the stream
+ /**
+ * Read from the stream.
+ *
+ * @param integer $count Amount of bytes to read
+ *
+ * @return string $data Data that has been read
*
* @access public
- * @param integer $count amount of bytes to read
- * @return string $data data that has been read
*/
function stream_read($count)
{
@@ -222,12 +238,14 @@ function stream_read($count)
return $data;
}
- /**
- * write to the stream
+ /**
+ * write to the stream.
+ *
+ * @param mixed $data Data to write
+ *
+ * @return integer Number of bytes that were written
*
* @access public
- * @param mixed $data data to write
- * @return integer $bytes number of bytes that were written
*/
function stream_write($data)
{
@@ -241,55 +259,64 @@ function stream_write($data)
$datalen = strlen($data);
- $this->_pointer = substr($this->_pointer, 0, $this->_pos) . $data . substr($this->_pointer, $this->_pos+$datalen);
+ $this->_pointer = substr($this->_pointer, 0, $this->_pos)
+ . $data
+ . substr($this->_pointer, $this->_pos+$datalen);
+
$this->_pos = $this->_pos + $datalen;
return $datalen;
}
- /**
- * move the position in the stream
+ /**
+ * Move the position in the stream.
+ *
+ * @param integer $offset Offset
+ * @param integer $whence Point from which the offset
+ * should be calculated
+ *
+ * @return boolean True if the position could be reached
*
* @access public
- * @param integer $offset offset
- * @return integer $whence point from which the offset should be calculated
*/
function stream_seek($offset, $whence)
{
switch ($whence) {
- // from start
- case SEEK_SET:
- if ($offset < strlen($this->_pointer) && $offset >= 0) {
- $this->_pos = $offset;
- return true;
- } else {
- return false;
- }
- break;
- // from current position
- case SEEK_CUR:
- if ($offset >= 0) {
- $this->_pos += $offset;
- return true;
- } else {
- return false;
- }
- break;
- // from the end
- case SEEK_END:
- if (strlen($this->_pointer) + $offset >= 0) {
- $this->_pos = strlen($this->_pointer) + $offset;
- return true;
- } else {
- return false;
- }
- break;
- default:
+ // from start
+ case SEEK_SET:
+ if ($offset < strlen($this->_pointer) && $offset >= 0) {
+ $this->_pos = $offset;
+ return true;
+ } else {
+ return false;
+ }
+ break;
+ // from current position
+ case SEEK_CUR:
+ if ($offset >= 0) {
+ $this->_pos += $offset;
+ return true;
+ } else {
return false;
+ }
+ break;
+ // from the end
+ case SEEK_END:
+ if (strlen($this->_pointer) + $offset >= 0) {
+ $this->_pos = strlen($this->_pointer) + $offset;
+ return true;
+ } else {
+ return false;
+ }
+ break;
+ default:
+ return false;
}
}
- /**
- * write all data to storage
+ /**
+ * Write all data to storage.
+ *
+ * @return boolean Always true
*
* @access public
*/
@@ -298,17 +325,18 @@ function stream_flush()
return true;
}
- /**
- * return information about the stream
+ /**
+ * Return information about the stream.
*
* @access public
- * @return array $stat information about the stream (currently only the length is included)
+ * @return array $stat Information about the stream
+ * (currently only the length is included)
*/
function stream_stat()
{
$stat = array(
- 'size' => strlen($this->_pointer)
- );
+ 'size' => strlen($this->_pointer)
+ );
return $stat;
}
@@ -328,28 +356,31 @@ function stream_stat()
*
* 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
+ * - '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
+ * @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
*
@@ -382,13 +413,15 @@ function url_stat($path, $flags)
return array_merge(array_values($keys), $keys);
}
- /**
- * open 'directory'
+ /**
+ * Open 'directory'
+ *
+ * @param string $path Path to the array (i.e. the directory)
+ * @param array $options Not implemented, yet.
+ *
+ * @return boolean $success
*
* @access public
- * @param string $path path to the array (i.e. the directory)
- * @param array $options not implemented, yet.
- * @return boolean $success
*/
function dir_opendir($path, $options)
{
@@ -401,8 +434,9 @@ function dir_opendir($path, $options)
$varpath = '';
}
- if (!$status = $this->_setPointer($scope, $varpath))
- return false;
+ if (!$status = $this->_setPointer($scope, $varpath)) {
+ return false;
+ }
if (!is_array($this->_pointer)) {
return false;
@@ -413,11 +447,12 @@ function dir_opendir($path, $options)
}
- /**
- * close 'directory'
+ /**
+ * Close 'directory'
*
- * @access public
* @return boolean $success
+ *
+ * @access public
*/
function dir_closedir()
{
@@ -425,11 +460,12 @@ function dir_closedir()
return true;
}
- /**
- * rewind 'directory'
+ /**
+ * Rewind 'directory'
*
- * @access public
* @return boolean $success
+ *
+ * @access public
*/
function dir_rewinddir()
{
@@ -440,82 +476,88 @@ function dir_rewinddir()
return true;
}
- /**
- * read one entry from 'directory'
+ /**
+ * Read one entry from 'directory'
+ *
+ * @return mixed $entry Entry that has been read, or
+ * false if there are no entries left
*
* @access public
- * @return mixed $entry entry that has been read, or false if there are no entries left
*/
function dir_readdir()
{
if (!$this->_open) {
return false;
}
- if (current($this->_pointer) == count($this->_pointer)-1) {
+ if (current($this->_pointer) == count($this->_pointer) - 1) {
return false;
}
list($key) = each($this->_pointer);
return $key;
}
- /**
- * set the internal pointer
+ /**
+ * Set the internal pointer
*
* Basically this method only sets the object property _pointer
* as a reference to a variable
*
+ * @param string $scope Scope of the variable: GLOBAL, GET,
+ * POST, COOKIE, SESSION, SERVER, ENV
+ * @param string $path Path to the variable. Array indices
+ * are seperated by a slash
+ * @param boolean $create Create the variable, if it does not exist
+ *
+ * @return boolean true if the pointer was set, false if not found
+ *
* @access private
- * @param string $scope scope of the variable: GLOBAL, GET, POST, COOKIE, SESSION, SERVER, ENV
- * @param string $path path to the variable. Array indices are seperated by a slash
- * @param boolean $create create the variable, if it does not exist
*/
- function _setPointer($scope, $path, $create = false )
+ function _setPointer($scope, $path, $create = false)
{
- $varpath = explode("/", $path);
+ $varpath = explode('/', $path);
switch (strtoupper($scope)) {
- // GET variables
- case "GET":
- case "_GET":
- $this->_pointer = &$_GET;
- break;
-
- // POST variables
- case "POST":
- case "_POST":
- $this->_pointer = &$_POST;
- break;
-
- // SERVER variables
- case "SERVER":
- case "_SERVER":
- $this->_pointer = &$_SERVER;
- break;
-
- // SESSION variables
- case "SESSION":
- case "_SESSION":
- $this->_pointer = &$_SESSION;
- break;
-
- // COOKIE variables
- case "COOKIE":
- case "_COOKIE":
- $this->_pointer = &$_COOKIE;
- break;
-
- // ENV variables
- case "ENV":
- case "_ENV":
- $this->_pointer = &$_ENV;
- break;
-
- // global variables
- case "GLOBALS":
- default:
- $this->_pointer = &$GLOBALS;
- break;
-
+ // GET variables
+ case 'GET':
+ case '_GET':
+ $this->_pointer = &$_GET;
+ break;
+
+ // POST variables
+ case 'POST':
+ case '_POST':
+ $this->_pointer = &$_POST;
+ break;
+
+ // SERVER variables
+ case 'SERVER':
+ case '_SERVER':
+ $this->_pointer = &$_SERVER;
+ break;
+
+ // SESSION variables
+ case 'SESSION':
+ case '_SESSION':
+ $this->_pointer = &$_SESSION;
+ break;
+
+ // COOKIE variables
+ case 'COOKIE':
+ case '_COOKIE':
+ $this->_pointer = &$_COOKIE;
+ break;
+
+ // ENV variables
+ case 'ENV':
+ case '_ENV':
+ $this->_pointer = &$_ENV;
+ break;
+
+ // global variables
+ case 'GLOBALS':
+ default:
+ $this->_pointer = &$GLOBALS;
+ break;
}
if (empty($varpath)) {
return true;
Please sign in to comment.
Something went wrong with that request. Please try again.