📄 phar.converttoexecutable.html
字号:
<!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 another executable phar archive file format</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.converttodata.html">Phar::convertToData</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.copy.html">Phar::copy</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.converttoexecutable" class="refentry"> <div class="refnamediv"> <h1 class="refname">Phar::convertToExecutable</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">Phar::convertToExecutable</span> — <span class="dc-title">Convert a phar archive to another executable phar archive file format</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type Phar">Phar</span></span> <span class="methodname"><b><b>Phar::convertToExecutable</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> <blockquote><p><b class="note">Note</b>: Thismethod requires the <var class="filename">php.ini</var> setting <i>phar.readonly</i> to beset to <i>0</i> in order to work for <a href="class.Phar.html" class="classname">Phar</a>objects. Otherwise, a <a href="class.PharException.html" class="classname">PharException</a> will be thrown.<br /></p></blockquote> <p class="para"> This method is used to convert a phar archive to another file format. For instance, it can be used to create a tar-based executable phar archive from a zip-based executable phar archive, or from an executable phar archive in the phar file format. In addition, it can be used to apply whole-archive compression to a tar or phar-based archive. </p> <p class="para"> If no changes are specified, this method throws a <b class="classname">BadMethodCallException</b>. </p> <p class="para"> If successful, the method creates a new archive on disk and returns a <a href="class.Phar.html" class="classname">Phar</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::PHAR</i>, <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 all zip- and tar-based phar archives must contain <i>.phar</i> in their file extension in order to be processed as a phar archive. </p> <p class="para"> If converting to a phar-based archive, the default extensions are <i>.phar</i>, <i>.phar.gz</i>, or <i>.phar.bz2</i> depending on the specified compression. For tar-based phar archives, the default extensions are <i>.phar.tar</i>, <i>.phar.tar.gz</i>, and <i>.phar.tar.bz2</i>. For zip-based phar archives, the default extension is <i>.phar.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.Phar.html" class="classname">Phar</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>, an <b class="classname">UnexpectedValueException</b> if write support is disabled, 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::convertToExecutable()</b> example</b></p> <div class="example-contents"><p> Using Phar::convertToExecutable(): </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">// convert it to the phar file format<br /> // note that myphar.phar.tar is *not* unlinked<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">convertToExecutable</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">// creates myphar.phar<br /> </span><span style="color: #0000BB">$phar</span><span style="color: #007700">-></span><span style="color: #0000BB">setStub</span><span style="color: #007700">(</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-></span><span style="color: #0000BB">createDefaultStub</span><span style="color: #007700">(</span><span style="color: #DD0000">'cli.php'</span><span style="color: #007700">, </span><span style="color: #DD0000">'web/index.php'</span><span style="color: #007700">));<br /> </span><span style="color: #FF8000">// creates myphar.phar.tgz<br /> </span><span style="color: #0000BB">$compressed </span><span style="color: #007700">= </span><span style="color: #0000BB">$phar</span><span style="color: #007700">-></span><span style="color: #0000BB">convertToExecutable</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">GZ</span><span style="color: #007700">, </span><span style="color: #DD0000">'.phar.tgz'</span><span style="color: #007700">);<br />} 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.converttodata.html" class="function" rel="rdfs-seeAlso">Phar::convertToData()</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.converttodata.html">Phar::convertToData</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.copy.html">Phar::copy</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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -