Stream_Var
[ class tree: Stream_Var ] [ index: Stream_Var ] [ all elements ]

Class: Stream_Var

Source Location: /Stream_Var-1.2.0/Stream/Var.php

Class Overview


Stream wrapper to access a variable


Author(s):

Version:

  • Release: 1.2.0

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 79]
Stream wrapper to access a variable

Stream wrappers allow you to access any datasource using PHP's file manipulation functions like fopen(), fclose(), fseek(), ftell(),.. as well as directory functions like opendir() readdir() and closedir().

This wrapper allows you to access any variable using these functions. You have to specify a scope (GLOBALS, _GET, _POST, etc.) as the host and the variable name as the path. If you want to access a string, that is stored in an array, you can use this array like you would use a directory.

Usage:

  1.   require_once '../Var.php';
  2.   stream_wrapper_register"var""Stream_Var" );
  3.  
  4.   $fp fopen('var://GLOBALS/myArray/index','r');
  5.   $data fread($fp,100);
  6.   fclose($fp);

This wrapper also has support for dir functions, so it's possible to read any array, like you would read a directory. The following code will list all keys in an array. You could use fopen() to read the values for the keys.

  1.   require_once '../Var.php';
  2.   stream_wrapper_register"var""Stream_Var" );
  3.  
  4.   $dh opendir('var://_SERVER');
  5.   while ($entry readdir($dh)) {
  6.       echo $entry."<br />";
  7.   }
  8.   closedir($dh);

This wrapper allows you to replace files and directories with structures in memory in any application, that relies on filesystem functions. But keep in mind that variables are not persistent during several request, unless you write to var://SESSION. But this can be used to replace temporary files with variables.

Note that glob() does not work with stream wrappers.



[ Top ]


Class Variables

$_mode =  0

[line 108]

Mode of the opened file
  • Access: protected

Type:   integer


[ Top ]

$_open =  false

[line 94]

Flag to indicate whether stream is open
  • Access: protected

Type:   boolean


[ Top ]

$_pointer =  null

[line 87]

Pointer to the current variable
  • Access: protected

Type:   mixed


[ Top ]

$_pos =  0

[line 101]

Position
  • Access: protected

Type:   integer


[ Top ]



Method Detail

dir_closedir   [line 423]

boolean dir_closedir( )

Close 'directory'
  • Access: public

[ Top ]

dir_opendir   [line 403]

boolean dir_opendir( string $path, array $options)

Open 'directory'
  • Access: public

Parameters:

string   $path   —  Path to the array (i.e. the directory)
array   $options   —  Not implemented, yet.

[ Top ]

dir_readdir   [line 449]

mixed dir_readdir( )

Read one entry from 'directory'
  • Return: Entry that has been read, or false if there are no entries left
  • Access: public

[ Top ]

dir_rewinddir   [line 434]

boolean dir_rewinddir( )

Rewind 'directory'
  • Access: public

[ Top ]

setPointerFromPath   [line 550]

boolean setPointerFromPath( string $path, [boolean $create = false])

Set the internal pointer variable from the given variable path.
  • Return: True if the pointer could be set (variable found)
  • Access: protected

Parameters:

string   $path   —  Variable path like GLOBALS/foo/bar
boolean   $create   —  If the variable should be created if it does not exists

[ Top ]

stream_close   [line 194]

void stream_close( )

Close the stream.
  • Access: public

[ Top ]

stream_eof   [line 174]

boolean stream_eof( )

Check for end of stream.
  • Return: True if at end of stream
  • Access: public

[ Top ]

stream_flush   [line 298]

boolean stream_flush( )

Write all data to storage.
  • Return: Always true
  • Access: public

[ Top ]

stream_open   [line 122]

boolean stream_open( string $path, string $mode, array $options, &$opened_path, string $opened_path)

Method used by fopen.
  • Access: public

Parameters:

string   $path   —  Path to the variable (e.g. var://GLOBALS/myArray/anyIndex)
string   $mode   —  Mode to open the stream, like 'r', 'w,',... ({@see fopen()})
array   $options   —  Options (not implemented yet)
string   $opened_path   —  This will be set to the actual opened path
   &$opened_path   — 

[ Top ]

stream_read   [line 207]

string stream_read( integer $count)

Read from the stream.
  • Return: Data that has been read
  • Access: public

Parameters:

integer   $count   —  Amount of bytes to read

[ Top ]

stream_seek   [line 258]

boolean stream_seek( integer $offset, integer $whence)

Move the position in the stream.
  • Return: True if the position could be reached
  • Access: public

Parameters:

integer   $offset   —  Offset
integer   $whence   —  Point from which the offset should be calculated

[ Top ]

stream_stat   [line 309]

array stream_stat( )

Return information about the stream.
  • Return: Information about the stream (currently only the length is included)
  • Access: public

[ Top ]

stream_tell   [line 184]

integer stream_tell( )

Return the current position.
  • Return: Current position in stream
  • Access: public

[ Top ]

stream_write   [line 229]

integer stream_write( mixed $data)

Write to the stream.
  • Return: Number of bytes that were written
  • Access: public

Parameters:

mixed   $data   —  Data to write

[ Top ]

url_stat   [line 364]

array url_stat( string $path, integer $flags)

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


Parameters:

string   $path   —  The path to stat.
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

[ Top ]

_setPointer   [line 475]

boolean _setPointer( string $scope, string $path, [boolean $create = false])

Set the internal pointer

Basically this method only sets the object property _pointer as a reference to a variable

  • Return: true if the pointer was set, false if not found
  • Access: protected

Parameters:

string   $scope   —  Scope of the variable: GLOBAL, GET, POST, COOKIE, SESSION, SERVER, ENV
string   $path   —  Path to the variable. Array indices are seperated by a slash
boolean   $create   —  Create the variable, if it does not exist

[ Top ]


Documentation generated on Fri, 11 Dec 2015 23:00:02 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.