function.stream-wrapper-register.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 486 行 · 第 1/3 页
HTML
486 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Register a URL wrapper implemented as a PHP class</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stream-socket-shutdown.html">stream_socket_shutdown</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-wrapper-restore.html">stream_wrapper_restore</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.stream-wrapper-register" class="refentry"> <div class="refnamediv"> <h1 class="refname">stream_wrapper_register</h1> <p class="verinfo">(PHP 4 >= 4.3.2, PHP 5)</p><p class="refpurpose"><span class="refname">stream_wrapper_register</span> — <span class="dc-title">Register a URL wrapper implemented as a PHP class</span></p> </div> <div class="refsect1 unknown"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>stream_wrapper_register</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$protocol</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$classname</tt></span> )</div> <p class="para rdfs-comment"> <b>stream_wrapper_register()</b> allows you to implement your own protocol handlers and streams for use with all the other filesystem functions (such as <a href="function.fopen.html" class="function">fopen()</a>, <a href="function.fread.html" class="function">fread()</a> etc.). </p> <p class="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 <i><tt class="parameter">classname</tt></i> and then call methods on that instance. You must implement the methods exactly as described below - doing otherwise will lead to undefined behaviour. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara"> As of PHP 5.0.0 the instance of <i><tt class="parameter">classname</tt></i> will be populated with a <i><tt class="parameter">context</tt></i> property referencing a <i>Context Resource</i> which may be accessed with <a href="function.stream-context-get-options.html" class="function">stream_context_get_options()</a>. If no context was passed to the stream creation function, <i><tt class="parameter">context</tt></i> will be set to <b><tt>NULL</tt></b>. </span> </p></blockquote> <p class="para"> <b>stream_wrapper_register()</b> will return <b><tt>FALSE</tt></b> if the <i><tt class="parameter">protocol</tt></i> already has a handler. </p> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>stream_open</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$path</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$mode</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$options</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$opened_path</tt></span> )</div> <p class="para rdfs-comment"> This method is called immediately after your stream object is created. <i><tt class="parameter">path</tt></i> specifies the URL that was passed to <a href="function.fopen.html" class="function">fopen()</a> and that this object is expected to retrieve. You can use <a href="function.parse-url.html" class="function">parse_url()</a> to break it apart. </p> <p class="para"> <i><tt class="parameter">mode</tt></i> is the mode used to open the file, as detailed for <a href="function.fopen.html" class="function">fopen()</a>. You are responsible for checking that <i><tt class="parameter">mode</tt></i> is valid for the <i><tt class="parameter">path</tt></i> requested. </p> <p class="para"> <i><tt class="parameter">options</tt></i> holds additional flags set by the streams API. It can hold one or more of the following values OR'd together. <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Flag</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">STREAM_USE_PATH</td> <td colspan="1" rowspan="1" align="left">If <i><tt class="parameter">path</tt></i> is relative, search for the resource using the include_path. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">STREAM_REPORT_ERRORS</td> <td colspan="1" rowspan="1" align="left">If this flag is set, you are responsible for raising errors using <a href="function.trigger-error.html" class="function">trigger_error()</a> during opening of the stream. If this flag is not set, you should not raise any errors. </td> </tr> </tbody> </colgroup> </table> </p> <p class="para"> If the <i><tt class="parameter">path</tt></i> is opened successfully, and STREAM_USE_PATH is set in <i><tt class="parameter">options</tt></i>, you should set <i><tt class="parameter">opened_path</tt></i> to the full path of the file/resource that was actually opened. </p> <p class="para"> If the requested resource was opened successfully, you should return <b><tt>TRUE</tt></b>, otherwise you should return <b><tt>FALSE</tt></b> </p> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>stream_close</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> This method is called when the stream is closed, using <a href="function.fclose.html" class="function">fclose()</a>. You must release any resources that were locked or allocated by the stream. </p> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>stream_read</b></b></span> ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$count</tt></span> )</div> <p class="para rdfs-comment"> This method is called in response to <a href="function.fread.html" class="function">fread()</a> and <a href="function.fgets.html" class="function">fgets()</a> calls on the stream. You must return up-to <i><tt class="parameter">count</tt></i> bytes of data from the current read/write position as a string. If there are less than <i><tt class="parameter">count</tt></i>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?