Skip to content

Commit 4bf789e

Browse files
Girgiasiluuu1994
andauthored
Create stub for request_parse_body() (#4108)
Co-authored-by: Ilija Tovilo <[email protected]>
1 parent 587de79 commit 4bf789e

File tree

6 files changed

+227
-0
lines changed

6 files changed

+227
-0
lines changed

language/errors/php7.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
<listitem>
7676
<simpara><classname>FiberError</classname></simpara>
7777
</listitem>
78+
<listitem>
79+
<simpara><classname>RequestParseBodyException</classname></simpara>
80+
</listitem>
7881
</itemizedlist>
7982
</listitem>
8083
<listitem>

language/predefined/exceptions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
&language.predefined.valueerror;
2828
&language.predefined.unhandledmatcherror;
2929
&language.predefined.fibererror;
30+
&language.predefined.requestparsebodyexception;
3031
</part>
3132

3233
<!-- Keep this comment at the end of the file
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<reference xml:id="class.requestparsebodyexception" role="exception" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
4+
<title>RequestParseBodyException</title>
5+
<titleabbrev>RequestParseBodyException</titleabbrev>
6+
7+
<partintro>
8+
9+
<!-- {{{ Exception intro -->
10+
<section xml:id="RequestParseBodyException.intro">
11+
&reftitle.intro;
12+
<simpara>
13+
A <classname>RequestParseBodyException</classname> is thrown in
14+
<function>request_parse_body</function> when the request body is invalid,
15+
according to the <literal>Content-Type</literal> header.
16+
</simpara>
17+
</section>
18+
<!-- }}} -->
19+
20+
<section xml:id="RequestParseBodyException.synopsis">
21+
&reftitle.classsynopsis;
22+
23+
<!-- {{{ Synopsis -->
24+
<classsynopsis class="class">
25+
<ooexception>
26+
<exceptionname>RequestParseBodyException</exceptionname>
27+
</ooexception>
28+
29+
<ooclass>
30+
<modifier>extends</modifier>
31+
<classname>Exception</classname>
32+
</ooclass>
33+
34+
<classsynopsisinfo role="comment">&InheritedProperties;</classsynopsisinfo>
35+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:partintro/db:section/db:classsynopsis/db:fieldsynopsis[preceding-sibling::db:classsynopsisinfo[1][@role='comment' and text()='&Properties;']]))">
36+
<xi:fallback/>
37+
</xi:include>
38+
39+
<classsynopsisinfo role="comment">&InheritedMethods;</classsynopsisinfo>
40+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role='Exception'])">
41+
<xi:fallback/>
42+
</xi:include>
43+
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.exception')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='Exception'])">
44+
<xi:fallback/>
45+
</xi:include>
46+
</classsynopsis>
47+
48+
<!-- }}} -->
49+
50+
</section>
51+
</partintro>
52+
</reference>
53+
<!-- Keep this comment at the end of the file
54+
Local variables:
55+
mode: sgml
56+
sgml-omittag:t
57+
sgml-shorttag:t
58+
sgml-minimize-attributes:nil
59+
sgml-always-quote-attributes:t
60+
sgml-indent-step:1
61+
sgml-indent-data:t
62+
indent-tabs-mode:nil
63+
sgml-parent-document:nil
64+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
65+
sgml-exposed-tags:nil
66+
sgml-local-catalogs:nil
67+
sgml-local-ecat-files:nil
68+
End:
69+
vim600: syn=xml fen fdm=syntax fdl=2 si
70+
vim: et tw=78 syn=sgml
71+
vi: ts=1 sw=1
72+
-->

language/predefined/versions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101

102102
<function name="closedgeneratorexception" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
103103

104+
<function name="requstparsebodyexception" from="PHP 8 &gt;= 8.4.0"/>
105+
104106
<function name="fiber" from="PHP 8 &gt;= 8.1.0"/>
105107
<function name="fiber::__construct" from="PHP 8 &gt;= 8.1.0"/>
106108
<function name="fiber::start" from="PHP 8 &gt;= 8.1.0"/>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<refentry xml:id="function.request-parse-body" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
3+
<refnamediv>
4+
<refname>request_parse_body</refname>
5+
<refpurpose>Read and parse the request body and return the result</refpurpose>
6+
</refnamediv>
7+
8+
<refsect1 role="description">
9+
&reftitle.description;
10+
<methodsynopsis>
11+
<type>array</type><methodname>request_parse_body</methodname>
12+
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>options</parameter><initializer>&null;</initializer></methodparam>
13+
</methodsynopsis>
14+
<simpara>
15+
This function reads the request body and parses it according to the
16+
<literal>Content-Type</literal> header. Currently, two content types are
17+
supported:
18+
</simpara>
19+
<itemizedlist>
20+
<listitem>
21+
<simpara>
22+
<literal>application/x-www-form-urlencoded</literal>
23+
</simpara>
24+
</listitem>
25+
<listitem>
26+
<simpara>
27+
<literal>multipart/form-data</literal>
28+
</simpara>
29+
</listitem>
30+
</itemizedlist>
31+
<simpara>
32+
This function is used primarily to parse
33+
<literal>multipart/form-data</literal> requests with HTTP verbs other than
34+
<literal>POST</literal> which do not automatically populate the
35+
<varname>$_POST</varname> and <varname>$_FILES</varname> superglobals.
36+
</simpara>
37+
38+
<caution>
39+
<simpara>
40+
<function>request_parse_body</function> consumes the request body without
41+
buffering it to the <literal>php://input</literal> stream.
42+
</simpara>
43+
</caution>
44+
</refsect1>
45+
46+
<refsect1 role="parameters">
47+
&reftitle.parameters;
48+
<variablelist>
49+
<varlistentry>
50+
<term><parameter>options</parameter></term>
51+
<listitem>
52+
<simpara>
53+
The <parameter>options</parameter> parameter accepts an associative array
54+
to override the following global &php.ini; settings for parsing of the
55+
request body.
56+
</simpara>
57+
<itemizedlist>
58+
<listitem><simpara><literal>max_file_uploads</literal></simpara></listitem>
59+
<listitem><simpara><literal>max_input_vars</literal></simpara></listitem>
60+
<listitem><simpara><literal>max_multipart_body_parts</literal></simpara></listitem>
61+
<listitem><simpara><literal>post_max_size</literal></simpara></listitem>
62+
<listitem><simpara><literal>upload_max_filesize</literal></simpara></listitem>
63+
</itemizedlist>
64+
</listitem>
65+
</varlistentry>
66+
</variablelist>
67+
</refsect1>
68+
69+
<refsect1 role="returnvalues">
70+
&reftitle.returnvalues;
71+
<simpara>
72+
<function>request_parse_body</function> returns an array pair with the
73+
equivalent of <varname>$_POST</varname> at index <literal>0</literal> and
74+
<varname>$_FILES</varname> at index <literal>1</literal>.
75+
</simpara>
76+
</refsect1>
77+
78+
<refsect1 role="errors">
79+
&reftitle.errors;
80+
<simpara>
81+
When the request body is invalid,
82+
according to the <literal>Content-Type</literal> header,
83+
a <exceptionname>RequestParseBodyException</exceptionname> is thrown.
84+
</simpara>
85+
<simpara>
86+
A <exceptionname>ValueError</exceptionname> is thrown when
87+
<parameter>options</parameter> contains invalid keys,
88+
or invalid values for the corresponding key.
89+
</simpara>
90+
</refsect1>
91+
92+
<refsect1 role="examples">
93+
&reftitle.examples;
94+
<example xml:id="function.request-parse-body.example.basic">
95+
<title><function>request_parse_body</function> example</title>
96+
<programlisting role="php">
97+
<![CDATA[
98+
<?php
99+
// Parse request and store result in the $_POST and $_FILES superglobals.
100+
[$_POST, $_FILES] = request_parse_body();
101+
// Echo the content of some transferred file
102+
echo file_get_contents($_FILES['file_name']['tmp_name']);
103+
?>
104+
]]>
105+
</programlisting>
106+
</example>
107+
<example xml:id="function.request-parse-body.example.options">
108+
<title><function>request_parse_body</function> example with customized options</title>
109+
<programlisting role="php">
110+
<![CDATA[
111+
<?php
112+
// form.php
113+
114+
assert_logged_in();
115+
116+
// Only for this form, we allow a bigger upload size.
117+
[$_POST, $_FILES] = request_parse_body([
118+
'post_max_size' => '10M',
119+
'upload_max_filesize' => '10M',
120+
]);
121+
122+
// Do something with the uploaded files.
123+
?>
124+
]]>
125+
</programlisting>
126+
</example>
127+
</refsect1>
128+
</refentry>
129+
<!-- Keep this comment at the end of the file
130+
Local variables:
131+
mode: sgml
132+
sgml-omittag:t
133+
sgml-shorttag:t
134+
sgml-minimize-attributes:nil
135+
sgml-always-quote-attributes:t
136+
sgml-indent-step:1
137+
sgml-indent-data:t
138+
indent-tabs-mode:nil
139+
sgml-parent-document:nil
140+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
141+
sgml-exposed-tags:nil
142+
sgml-local-catalogs:nil
143+
sgml-local-ecat-files:nil
144+
End:
145+
vim600: syn=xml fen fdm=syntax fdl=2 si
146+
vim: et tw=78 syn=sgml
147+
vi: ts=1 sw=1
148+
-->

reference/network/versions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<function name="net_get_interfaces" from="PHP 7 &gt;= 7.3, PHP 8"/>
3535
<function name="openlog" from="PHP 4, PHP 5, PHP 7, PHP 8"/>
3636
<function name="pfsockopen" from="PHP 4, PHP 5, PHP 7, PHP 8"/>
37+
<function name="request_parse_body" from="PHP 8 &gt;= 8.4.0"/>
3738
<function name="setcookie" from="PHP 4, PHP 5, PHP 7, PHP 8"/>
3839
<function name="setrawcookie" from="PHP 5, PHP 7, PHP 8"/>
3940
<function name="socket_get_status" from="PHP 4, PHP 5, PHP 7, PHP 8"/>

0 commit comments

Comments
 (0)