phar.converttodata.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 174 行
HTML
174 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Convert a phar archive to a non-executable tar or zip file</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="phar.construct.html">Phar::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.converttoexecutable.html">Phar::convertToExecutable</a></div> <div class="up"><a href="class.Phar.html">Phar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="phar.converttodata" class="refentry"> <div class="refnamediv"> <h1 class="refname">Phar::convertToData</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">Phar::convertToData</span> — <span class="dc-title">Convert a phar archive to a non-executable tar or zip file</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type PharData">PharData</span></span> <span class="methodname"><b><b>Phar::convertToData</b></b></span> ([ <span class="methodparam"><span class="type">int</span> <tt class="parameter">$format</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$compression</tt></span> [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$extension</tt></span> ]]] )</div> <p class="para rdfs-comment"> This method is used to convert an executable phar archive to either a tar or zip file. To make the tar or zip non-executable, the phar stub and phar alias files are removed from the newly created archive. </p> <p class="para"> If no changes are specified, this method throws a <b class="classname">BadMethodCallException</b> if the archive is in phar file format. For archives in tar or zip file format, this method converts the archive to a non-executable archive. </p> <p class="para"> If successful, the method creates a new archive on disk and returns a <a href="class.PharData.html" class="classname">PharData</a> object. The old archive is not removed from disk, and should be done manually after the process has finished. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">format</tt></i></span> <dd> <p class="para"> This should be one of <i>Phar::TAR</i> or <i>Phar::ZIP</i>. If set to <b><tt>NULL</tt></b>, the existing file format will be preserved. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">compression</tt></i></span> <dd> <p class="para"> This should be one of <i>Phar::NONE</i> for no whole-archive compression, <i>Phar::GZ</i> for zlib-based compression, and <i>Phar::BZ2</i> for bzip-based compression. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">extension</tt></i></span> <dd> <p class="para"> This parameter is used to override the default file extension for a converted archive. Note that <i>.phar</i> cannot be used anywhere in the filename for a non-executable tar or zip archive. </p> <p class="para"> If converting to a tar-based phar archive, the default extensions are <i>.tar</i>, <i>.tar.gz</i>, and <i>.tar.bz2</i> depending on specified compression. For zip-based archives, the default extension is <i>.zip</i>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The method returns a <a href="class.PharData.html" class="classname">PharData</a> object on success and throws an exception on failure. </p> </div> <div class="refsect1 errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> This method throws <b class="classname">BadMethodCallException</b> when unable to compress, an unknown compression method has been specified, the requested archive is buffering with <a href="phar.startbuffering.html" class="function">Phar::startBuffering()</a> and has not concluded with <a href="phar.stopbuffering.html" class="function">Phar::stopBuffering()</a>, and a <a href="class.PharException.html" class="classname">PharException</a> if any problems are encountered during the phar creation process. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 A <b>Phar::convertToData()</b> example</b></p> <div class="example-contents"><p> Using Phar::convertToData(): </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">try {<br /> </span><span style="color: #0000BB">$tarphar </span><span style="color: #007700">= new </span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.phar.tar'</span><span style="color: #007700">);<br /> </span><span style="color: #FF8000">// note that myphar.phar.tar is *not* unlinked<br /> // convert it to the non-executable tar file format<br /> // creates myphar.tar<br /> </span><span style="color: #0000BB">$tar </span><span style="color: #007700">= </span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-></span><span style="color: #0000BB">comvertToData</span><span style="color: #007700">();<br /> </span><span style="color: #FF8000">// convert to non-executable zip format, creates myphar.zip<br /> </span><span style="color: #0000BB">$zip </span><span style="color: #007700">= </span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-></span><span style="color: #0000BB">convertToData</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">ZIP</span><span style="color: #007700">);<br /> </span><span style="color: #FF8000">// create myphar.tbz<br /> </span><span style="color: #0000BB">$tgz </span><span style="color: #007700">= </span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-></span><span style="color: #0000BB">convertToData</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">TAR</span><span style="color: #007700">, </span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">BZ2</span><span style="color: #007700">, </span><span style="color: #DD0000">'.tbz'</span><span style="color: #007700">);<br /> </span><span style="color: #FF8000">// creates myphar.phar.tgz<br /> </span><span style="color: #0000BB">$phar </span><span style="color: #007700">= </span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-></span><span style="color: #0000BB">convertToData</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">PHAR</span><span style="color: #007700">); </span><span style="color: #FF8000">// throws exception<br /></span><span style="color: #007700">} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// handle the error here<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="phar.converttoexecutable.html" class="function" rel="rdfs-seeAlso">Phar::convertToExecutable()</a></li> <li class="member"><a href="phardata.converttoexecutable.html" class="function" rel="rdfs-seeAlso">PharData::convertToExecutable()</a></li> <li class="member"><a href="phardata.converttodata.html" class="function" rel="rdfs-seeAlso">PharData::convertToData()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phar.construct.html">Phar::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.converttoexecutable.html">Phar::convertToExecutable</a></div> <div class="up"><a href="class.Phar.html">Phar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?