[PHP 8.1] Document CURLStringFile (#1154)

Reviewed by  Avatar Alexander Moskalev, CURLStringFile Author ( https://github.com/Irker )

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
This commit is contained in:
Yoshinari Takaoka 2021-11-29 23:27:25 +09:00 committed by GitHub
parent 06116ee1bf
commit 27fd6d7147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 267 additions and 0 deletions

View file

@ -30,6 +30,7 @@
&reference.curl.curlmultihandle;
&reference.curl.curlsharehandle;
&reference.curl.curlfile;
&reference.curl.curlstringfile;
</book>

View file

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<phpdoc:classref xml:id="class.curlstringfile" xmlns:phpdoc="http://php.net/ns/phpdoc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<title>The CURLStringFile class</title>
<titleabbrev>CURLStringFile</titleabbrev>
<partintro>
<!-- {{{ CURLStringFile intro -->
<section xml:id="curlstringfile.intro">
&reftitle.intro;
<para>
<classname>CURLStringFile</classname> makes it possible to upload a file directly from a variable.
This is similar to <classname>CURLFile</classname>, but works with the contents of the file, not filename.
This class should be used to upload the contents of the file with <constant>CURLOPT_POSTFIELDS</constant>.
</para>
</section>
<!-- }}} -->
<section xml:id="curlstringfile.synopsis">
&reftitle.classsynopsis;
<!-- {{{ Synopsis -->
<classsynopsis>
<ooclass>
<classname>CURLStringFile</classname>
</ooclass>
<classsynopsisinfo>
<ooclass>
<classname>CURLStringFile</classname>
</ooclass>
</classsynopsisinfo>
<classsynopsisinfo role="comment">&Properties;</classsynopsisinfo>
<fieldsynopsis>
<modifier>public</modifier>
<type>string</type>
<varname linkend="curlstringfile.props.data">data</varname>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<type>string</type>
<varname linkend="curlstringfile.props.postname">postname</varname>
</fieldsynopsis>
<fieldsynopsis>
<modifier>public</modifier>
<type>string</type>
<varname linkend="curlstringfile.props.mime">mime</varname>
</fieldsynopsis>
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.curlstringfile')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[not(@role='procedural')])">
<xi:fallback/>
</xi:include>
</classsynopsis>
<!-- }}} -->
</section>
<!-- {{{ CURLStringFile properties -->
<section xml:id="curlstringfile.props">
&reftitle.properties;
<variablelist>
<varlistentry xml:id="curlstringfile.props.data">
<term><varname>data</varname></term>
<listitem>
<para>The contents to be uploaded.</para>
</listitem>
</varlistentry>
<varlistentry xml:id="curlstringfile.props.postname">
<term><varname>postname</varname></term>
<listitem>
<para>The name of the file to be used in the upload data.</para>
</listitem>
</varlistentry>
<varlistentry xml:id="curlstringfile.props.mime">
<term><varname>mime</varname></term>
<listitem>
<para>MIME type of the file (default is <literal>application/octet-stream</literal>).</para>
</listitem>
</varlistentry>
</variablelist>
</section>
<!-- }}} -->
<section xml:id="curlstringfile.seealso">
&reftitle.seealso;
<para>
<simplelist>
<member>
<function>curl_setopt</function>
</member>
</simplelist>
</para>
</section>
</partintro>
&reference.curl.entities.curlstringfile;
</phpdoc:classref>
<!-- 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:"~/.phpdoc/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

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="curlstringfile.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>CURLStringFile::__construct</refname>
<refpurpose>Create a CURLStringFile object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<constructorsynopsis>
<modifier>public</modifier> <methodname>CURLStringFile::__construct</methodname>
<methodparam><type>string</type><parameter>data</parameter></methodparam>
<methodparam><type>string</type><parameter>postname</parameter></methodparam>
<methodparam><type>string</type><parameter>mime</parameter><initializer>"application/octet-stream"</initializer></methodparam>
</constructorsynopsis>
<para>
Creates a <classname>CURLStringFile</classname> object, used to upload a file with <constant>CURLOPT_POSTFIELDS</constant>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>data</parameter></term>
<listitem>
<para>
The contents to be uploaded.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>postname</parameter></term>
<listitem>
<para>
The name of the file to be used in the upload data.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mime</parameter></term>
<listitem>
<para>
MIME type of the file (default is <literal>application/octet-stream</literal>).
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a <classname>CURLStringFile</classname> object.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>CURLStringFile::__construct</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
/* http://example.com/upload.php:
<?php
var_dump($_FILES);
var_dump(file_get_contents($_FILES['test_string']['tmp_name']));
?>
*/
// Create a cURL handle
$ch = curl_init('http://example.com/upload.php');
// Create a CURLStringFile object
$cstringfile = new CURLStringFile('test upload contents','test.txt','text/plain');
// Assign POST data
$data = array('test_string' => $cstringfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Execute the handle
curl_exec($ch);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(1) {
["test_string"]=>
array(5) {
["name"]=>
string(8) "test.txt"
["type"]=>
string(10) "text/plain"
["tmp_name"]=>
string(14) "/tmp/phpTtaoCz"
["error"]=>
int(0)
["size"]=>
int(20)
}
}
string(20) "test upload contents"
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>curl_setopt</function></member>
</simplelist>
</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:"~/.phpdoc/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

@ -46,6 +46,9 @@
<function name="curlfile::setmimetype" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
<function name="curlfile::setpostfilename" from="PHP 5 &gt;= 5.5.0, PHP 7, PHP 8"/>
<function name="curlstringfile" from="PHP 8 &gt;= 8.1.0"/>
<function name="curlstringfile::__construct" from="PHP 8 &gt;= 8.1.0"/>
<function name="curlhandle" from="PHP 8"/>
<function name="curlmultihandle" from="PHP 8"/>
<function name="curlsharehandle" from="PHP 8"/>