Documentation shuffle per rename of:

stream_register_wrapper() and stream_register_filter() to
stream_wrapper_register() and stream_filter_register().


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@127778 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Sara Golemon 2003-05-19 17:30:43 +00:00
parent a88e30e347
commit 809d19a962
8 changed files with 353 additions and 313 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<!-- $Revision: 1.7 $ -->
<refentry id="function.stream-filter-append">
<refnamediv>
<refname>stream_filter_append</refname>
@ -80,13 +80,13 @@ Guvf vf n grfg
<note>
<title>When using custom (user) filters</title>
<simpara>
<function>stream_register_filter</function> must be called first
<function>stream_filter_register</function> must be called first
in order to register the desired user filter to <parameter>filtername</parameter>.
</simpara>
</note>
<simpara>
See also
<function>stream_register_filter</function>, and
<function>stream_filter_register</function>, and
<function>stream_filter_prepend</function>
</simpara>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- $Revision: 1.6 $ -->
<refentry id="function.stream-filter-prepend">
<refnamediv>
<refname>stream_filter_prepend</refname>
@ -41,13 +41,13 @@
<note>
<title>When using custom (user) filters</title>
<simpara>
<function>stream_register_filter</function> must be called first
<function>stream_filter_register</function> must be called first
in order to register the desired user filter to <parameter>filtername</parameter>.
</simpara>
</note>
<simpara>
See also
<function>stream_register_filter</function>, and
<function>stream_filter_register</function>, and
<function>stream_filter_append</function>
</simpara>
</refsect1>

View file

@ -1,19 +1,22 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<refentry id="function.stream-register-filter">
<!-- $Revision: 1.1 $ -->
<refentry id="function.stream-filter-register">
<refnamediv>
<refname>stream_register_filter</refname>
<refpurpose>Register a stream filter implemented as a PHP class derived from <literal>php_user_filter</literal></refpurpose>
<refname>stream_filter_register</refname>
<refpurpose>
Register a stream filter implemented as a PHP class
derived from <literal>php_user_filter</literal>
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>stream_register_filter</methodname>
<type>bool</type><methodname>stream_filter_register</methodname>
<methodparam><type>string</type><parameter>filtername</parameter></methodparam>
<methodparam><type>string</type><parameter>classname</parameter></methodparam>
</methodsynopsis>
<para>
<function>stream_register_filter</function> allows you to implement
<function>stream_filter_register</function> allows you to implement
your own filter on any registered stream used with all the other
filesystem functions (such as <function>fopen</function>,
<function>fread</function> etc.).
@ -29,7 +32,7 @@
behaviour.
</para>
<para>
<function>stream_register_filter</function> will return &false; if the
<function>stream_filter_register</function> will return &false; if the
<parameter>filtername</parameter> is already defined.
</para>
@ -109,7 +112,7 @@ class strtoupper_filter extends php_user_filter {
}
/* Register our filter with PHP */
stream_register_filter("strtoupper", "strtoupper_filter")
stream_filter_register("strtoupper", "strtoupper_filter")
or die("Failed to register filter");
$fp = fopen("foo-bar.txt", "w");
@ -142,7 +145,7 @@ EASY AS 123
</para>
<simpara>
See Also:
<function>stream_register_wrapper</function>,
<function>stream_wrapper_register</function>,
<function>stream_filter_prepend</function>, and
<function>stream_filter_append</function>
</simpara>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<refentry id="function.stream-get-filters">
<refnamediv>
<refname>stream_get_filters</refname>
@ -43,7 +43,7 @@ Array (
</para>
<para>
See also
<function>stream_register_filter</function>, and
<function>stream_filter_register</function>, and
<function>stream_get_wrappers</function>
</para>
</refsect1>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<refentry id="function.stream-get-wrappers">
<refnamediv>
<refname>stream_get_wrappers</refname>
@ -17,7 +17,7 @@
</para>
<para>
See also
<function>stream_register_wrapper</function>
<function>stream_wrapper_register</function>
</para>
</refsect1>
</refentry>

View file

@ -1,303 +1,21 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.141 -->
<refentry id="function.stream-register-wrapper">
<!-- $Revision: 1.3 $ -->
<refentry id="stream.stream-register-wrapper">
<refnamediv>
<refname>stream_register_wrapper</refname>
<refpurpose>Register a URL wrapper implemented as a PHP class</refpurpose>
<refpurpose>Alias of <function>stream_wrapper_register</function></refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>stream_register_wrapper</methodname>
<methodparam><type>string</type><parameter>protocol</parameter></methodparam>
<methodparam><type>string</type><parameter>classname</parameter></methodparam>
</methodsynopsis>
<para>
<function>stream_register_wrapper</function> allows you to implement
your own protocol handlers and streams for use with all the other
filesystem functions (such as <function>fopen</function>,
<function>fread</function> etc.).
This function is an alias of <function>stream_wrapper_register</function>.
This function is included for compatability with <literal>PHP 4.3.0</literal>
and <literal>PHP 4.3.1</literal> only. <function>stream_wrapper_register</function>
should be used instead.
</para>
<para>
To implement a wrapper, you need to define a class with a number of
member functions, as defined below. When someone fopens your stream,
PHP will create an instance of <parameter>classname</parameter> and
then call methods on that instance. You must implement the methods
exactly as described below - doing otherwise will lead to undefined
behaviour.
</para>
<para>
<function>stream_register_wrapper</function> will return &false; if the
<parameter>protocol</parameter> already has a handler.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_open</methodname>
<methodparam><type>string</type><parameter>path</parameter></methodparam>
<methodparam><type>string</type><parameter>mode</parameter></methodparam>
<methodparam><type>int</type><parameter>options</parameter></methodparam>
<methodparam><type>string</type><parameter>opened_path</parameter></methodparam>
</methodsynopsis>
<para>
This method is called immediately after your stream object is
created. <parameter>path</parameter> specifies the URL that was
passed to <function>fopen</function> and that this object is
expected to retrieve. You can use <function>parse_url</function>
to break it apart.
</para>
<para>
<parameter>mode</parameter> is the mode used to open the file,
as detailed for <function>fopen</function>. You are responsible
for checking that <parameter>mode</parameter> is valid for the
<parameter>path</parameter> requested.
</para>
<para>
<parameter>options</parameter> holds additional flags set
by the streams API. It can hold one or more of the following
values OR'd together.
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Flag</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>STREAM_USE_PATH</entry>
<entry>If <parameter>path</parameter> is relative, search
for the resource using the include_path.
</entry>
</row>
<row>
<entry>STREAM_REPORT_ERRORS</entry>
<entry>If this flag is set, you are responsible for raising
errors using <function>trigger_error</function> during
opening of the stream. If this flag is not set, you
should not raise any errors.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
If the <parameter>path</parameter> is opened successfully,
and STREAM_USE_PATH is set in <parameter>options</parameter>,
you should set <parameter>opened_path</parameter> to the full
path of the file/resource that was actually opened.
</para>
<para>
If the requested resource was opened successfully, you should
return &true;, otherwise you should return &false;
</para>
<methodsynopsis>
<type>void</type><methodname>stream_close</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called when the stream is closed, using
<function>fclose</function>. You must release any resources
that were locked or allocated by the stream.
</para>
<methodsynopsis>
<type>string</type><methodname>stream_read</methodname>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fread</function>
and <function>fgets</function> calls on the stream. You
must return up-to <parameter>count</parameter> bytes of data
from the current read/write position as a string.
If there are less than <parameter>count</parameter>
bytes available, return as many as are available. If no
more data is available, return either &false; or an
empty string.
You must also update the read/write position of the stream
by the number of bytes that were successfully read.
</para>
<methodsynopsis>
<type>int</type><methodname>stream_write</methodname>
<methodparam><type>string</type><parameter>data</parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fwrite</function>
calls on the stream. You should store <parameter>data</parameter>
into the underlying storage used by your stream. If there is not
enough room, try to store as many bytes as possible.
You should return the number of bytes that were successfully
stored in the stream, or 0 if none could be stored.
You must also update the read/write position of the stream
by the number of bytes that were successfully written.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_eof</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>feof</function>
calls on the stream. You should return &true; if the read/write
position is at the end of the stream and if no more data is available
to be read, or &false; otherwise.
</para>
<methodsynopsis>
<type>int</type><methodname>stream_tell</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>ftell</function>
calls on the stream. You should return the current read/write
position of the stream.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_seek</methodname>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
<methodparam><type>int</type><parameter>whence</parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fseek</function>
calls on the stream. You should update the read/write position
of the stream according to <parameter>offset</parameter> and
<parameter>whence</parameter>. See <function>fseek</function>
for more information about these parameters.
Return &true; if the position was updated, &false; otherwise.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_flush</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fflush</function>
calls on the stream. If you have cached data in your stream
but not yet stored it into the underlying storage, you should
do so now.
Return &true; if the cached data was successfully stored (or
if there was no data to store), or &false; if the data could
not be stored.
</para>
<para>
The example below implements a var:// protocol handler that
allows read/write access to a named global variable using
standard filesystem stream functions such as <function>fread</function>.
The var:// protocol implemented below, given the url
"var://foo" will read/write data to/from $GLOBALS["foo"].
<example>
<title>A Stream for reading/writing global variables</title>
<programlisting role="php">
<![CDATA[
class VariableStream {
var $position;
var $varname;
function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url["host"];
$this->position = 0;
return true;
}
function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_write($data)
{
$left = substr($GLOBALS[$this->varname], 0, $this->position);
$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
$GLOBALS[$this->varname] = $left . $data . $right;
$this->position += strlen($data);
return strlen($data);
}
function stream_tell()
{
return $this->position;
}
function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}
function stream_seek($offset, $whence)
{
switch($whence) {
case SEEK_SET:
if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
$this->position = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($offset >= 0) {
$this->position += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
$this->position = strlen($GLOBALS[$this->varname]) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
}
stream_register_wrapper("var", "VariableStream")
or die("Failed to register protocol");
$myvar = "";
$fp = fopen("var://myvar", "r+");
fwrite($fp, "line1\n");
fwrite($fp, "line2\n");
fwrite($fp, "line3\n");
rewind($fp);
while(!feof($fp)) {
echo fgets($fp);
}
fclose($fp);
var_dump($myvar);
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml

View file

@ -0,0 +1,319 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<refentry id="function.stream-wrapper-register">
<refnamediv>
<refname>stream_wrapper_register</refname>
<refpurpose>Register a URL wrapper implemented as a PHP class</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>stream_wrapper_register</methodname>
<methodparam><type>string</type><parameter>protocol</parameter></methodparam>
<methodparam><type>string</type><parameter>classname</parameter></methodparam>
</methodsynopsis>
<para>
<function>stream_wrapper_register</function> allows you to implement
your own protocol handlers and streams for use with all the other
filesystem functions (such as <function>fopen</function>,
<function>fread</function> etc.).
</para>
<para>
To implement a wrapper, you need to define a class with a number of
member functions, as defined below. When someone fopens your stream,
PHP will create an instance of <parameter>classname</parameter> and
then call methods on that instance. You must implement the methods
exactly as described below - doing otherwise will lead to undefined
behaviour.
</para>
<para>
<function>stream_wrapper_register</function> will return &false; if the
<parameter>protocol</parameter> already has a handler.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_open</methodname>
<methodparam><type>string</type><parameter>path</parameter></methodparam>
<methodparam><type>string</type><parameter>mode</parameter></methodparam>
<methodparam><type>int</type><parameter>options</parameter></methodparam>
<methodparam><type>string</type><parameter>opened_path</parameter></methodparam>
</methodsynopsis>
<para>
This method is called immediately after your stream object is
created. <parameter>path</parameter> specifies the URL that was
passed to <function>fopen</function> and that this object is
expected to retrieve. You can use <function>parse_url</function>
to break it apart.
</para>
<para>
<parameter>mode</parameter> is the mode used to open the file,
as detailed for <function>fopen</function>. You are responsible
for checking that <parameter>mode</parameter> is valid for the
<parameter>path</parameter> requested.
</para>
<para>
<parameter>options</parameter> holds additional flags set
by the streams API. It can hold one or more of the following
values OR'd together.
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Flag</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>STREAM_USE_PATH</entry>
<entry>If <parameter>path</parameter> is relative, search
for the resource using the include_path.
</entry>
</row>
<row>
<entry>STREAM_REPORT_ERRORS</entry>
<entry>If this flag is set, you are responsible for raising
errors using <function>trigger_error</function> during
opening of the stream. If this flag is not set, you
should not raise any errors.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
If the <parameter>path</parameter> is opened successfully,
and STREAM_USE_PATH is set in <parameter>options</parameter>,
you should set <parameter>opened_path</parameter> to the full
path of the file/resource that was actually opened.
</para>
<para>
If the requested resource was opened successfully, you should
return &true;, otherwise you should return &false;
</para>
<methodsynopsis>
<type>void</type><methodname>stream_close</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called when the stream is closed, using
<function>fclose</function>. You must release any resources
that were locked or allocated by the stream.
</para>
<methodsynopsis>
<type>string</type><methodname>stream_read</methodname>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fread</function>
and <function>fgets</function> calls on the stream. You
must return up-to <parameter>count</parameter> bytes of data
from the current read/write position as a string.
If there are less than <parameter>count</parameter>
bytes available, return as many as are available. If no
more data is available, return either &false; or an
empty string.
You must also update the read/write position of the stream
by the number of bytes that were successfully read.
</para>
<methodsynopsis>
<type>int</type><methodname>stream_write</methodname>
<methodparam><type>string</type><parameter>data</parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fwrite</function>
calls on the stream. You should store <parameter>data</parameter>
into the underlying storage used by your stream. If there is not
enough room, try to store as many bytes as possible.
You should return the number of bytes that were successfully
stored in the stream, or 0 if none could be stored.
You must also update the read/write position of the stream
by the number of bytes that were successfully written.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_eof</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>feof</function>
calls on the stream. You should return &true; if the read/write
position is at the end of the stream and if no more data is available
to be read, or &false; otherwise.
</para>
<methodsynopsis>
<type>int</type><methodname>stream_tell</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>ftell</function>
calls on the stream. You should return the current read/write
position of the stream.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_seek</methodname>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
<methodparam><type>int</type><parameter>whence</parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fseek</function>
calls on the stream. You should update the read/write position
of the stream according to <parameter>offset</parameter> and
<parameter>whence</parameter>. See <function>fseek</function>
for more information about these parameters.
Return &true; if the position was updated, &false; otherwise.
</para>
<methodsynopsis>
<type>bool</type><methodname>stream_flush</methodname>
<methodparam><type>void</type><parameter></parameter></methodparam>
</methodsynopsis>
<para>
This method is called in response to <function>fflush</function>
calls on the stream. If you have cached data in your stream
but not yet stored it into the underlying storage, you should
do so now.
Return &true; if the cached data was successfully stored (or
if there was no data to store), or &false; if the data could
not be stored.
</para>
<para>
The example below implements a var:// protocol handler that
allows read/write access to a named global variable using
standard filesystem stream functions such as <function>fread</function>.
The var:// protocol implemented below, given the url
"var://foo" will read/write data to/from $GLOBALS["foo"].
<example>
<title>A Stream for reading/writing global variables</title>
<programlisting role="php">
<![CDATA[
class VariableStream {
var $position;
var $varname;
function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url["host"];
$this->position = 0;
return true;
}
function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_write($data)
{
$left = substr($GLOBALS[$this->varname], 0, $this->position);
$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
$GLOBALS[$this->varname] = $left . $data . $right;
$this->position += strlen($data);
return strlen($data);
}
function stream_tell()
{
return $this->position;
}
function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}
function stream_seek($offset, $whence)
{
switch($whence) {
case SEEK_SET:
if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
$this->position = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($offset >= 0) {
$this->position += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
$this->position = strlen($GLOBALS[$this->varname]) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
}
stream_wrapper_register("var", "VariableStream")
or die("Failed to register protocol");
$myvar = "";
$fp = fopen("var://myvar", "r+");
fwrite($fp, "line1\n");
fwrite($fp, "line2\n");
fwrite($fp, "line3\n");
rewind($fp);
while(!feof($fp)) {
echo fgets($fp);
}
fclose($fp);
var_dump($myvar);
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<reference id="ref.stream">
<title>Stream functions</title>
<titleabbrev>Streams</titleabbrev>
@ -25,7 +25,7 @@
request for a file on a remote server. There are many wrappers
built into <literal>PHP</literal> by default (See <xref linkend="wrappers"/>),
and additional, custom wrappers may be added either within a
PHP script using <function>stream_register_wrapper</function>,
PHP script using <function>stream_wrapper_register</function>,
or directly from an extension using the API Reference in <xref linkend="streams"/>.
Because any variety of wrapper may be added to <literal>PHP</literal>,
there is no set limit on what can be done with them. To access the list
@ -64,7 +64,7 @@
operations on data as it is being read from or written to a stream.
Any number of filters may be stacked onto a stream. Custom
filters can be defined in a <literal>PHP</literal> script using
<function>stream_register_filter</function> or in an extension using the
<function>stream_filter_register</function> or in an extension using the
API Reference in <xref linkend="streams"/>. To access the list of currently
registered filters, use <function>stream_get_filters</function>.
</simpara>
@ -131,13 +131,13 @@
<section id="stream.resources">
<title>Stream Classes</title>
<simpara>
User designed wrappers can be registered via <function>stream_register_wrapper</function>,
User designed wrappers can be registered via <function>stream_wrapper_register</function>,
using the class definition shown on that manual page.
</simpara>
<simpara>
<literal>class</literal> php_user_filter is predefined and is an abstract
baseclass for use with user defined filters. See the manual page for
<function>stream_register_filter</function> for details on implementing
<function>stream_filter_register</function> for details on implementing
user defined filters.
</simpara>
</section>