<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Convert a phar archive to a non-executable tar or zip file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phardata.construct.html">PharData::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="phardata.converttoexecutable.html">PharData::convertToExecutable</a></div> <div class="up"><a href="class.phardata.html">PharData</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="phardata.converttodata" class="refentry"> <div class="refnamediv"> <h1 class="refname">PharData::convertToData</h1> <p class="verinfo">(PHP >= 5.3.0, PECL phar >= 2.0.0)</p><p class="refpurpose"><span class="refname">PharData::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" id="refsect1-phardata.converttodata-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="class.phardata.html" class="type PharData">PharData</a></span> <span class="methodname"><strong>PharData::convertToData</strong></span> ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$format</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$compression</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$extension</code></span> ]]] )</div> <p class="para rdfs-comment"> This method is used to convert a non-executable tar or zip archive to another non-executable format. </p> <p class="para"> If no changes are specified, this method throws a <a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a>. This method should be used to convert a tar archive to zip format or vice-versa. Although it is possible to simply change the compression of a tar archive using this method, it is better to use the <span class="function"><a href="phardata.compress.html" class="function">PharData::compress()</a></span> method for logical consistency. </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" id="refsect1-phardata.converttodata-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">format</code></em></span> <dd> <p class="para"> This should be one of <em>Phar::TAR</em> or <em>Phar::ZIP</em>. If set to <strong><code>NULL</code></strong>, the existing file format will be preserved. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">compression</code></em></span> <dd> <p class="para"> This should be one of <em>Phar::NONE</em> for no whole-archive compression, <em>Phar::GZ</em> for zlib-based compression, and <em>Phar::BZ2</em> for bzip-based compression. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">extension</code></em></span> <dd> <p class="para"> This parameter is used to override the default file extension for a converted archive. Note that <em>.phar</em> 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 <em>.tar</em>, <em>.tar.gz</em>, and <em>.tar.bz2</em> depending on specified compression. For zip-based archives, the default extension is <em>.zip</em>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-phardata.converttodata-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" id="refsect1-phardata.converttodata-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> This method throws <a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a> when unable to compress, an unknown compression method has been specified, the requested archive is buffering with <span class="function"><a href="phar.startbuffering.html" class="function">Phar::startBuffering()</a></span> and has not concluded with <span class="function"><a href="phar.stopbuffering.html" class="function">Phar::stopBuffering()</a></span>, 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" id="refsect1-phardata.converttodata-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-714"> <p><strong>Example #1 A <span class="function"><strong>PharData::convertToData()</strong></span> example</strong></p> <div class="example-contents"><p> Using PharData::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">PharData</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.tar'</span><span style="color: #007700">);<br /> </span><span style="color: #FF8000">// note that myphar.tar is *not* unlinked<br /> // convert it to the non-executable tar file format<br /> // 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">$zip</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" id="refsect1-phardata.converttodata-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="phar.converttoexecutable.html" class="function" rel="rdfs-seeAlso">Phar::convertToExecutable()</a> - Convert a phar archive to another executable phar archive file format</span></li> <li class="member"> <span class="function"><a href="phar.converttodata.html" class="function" rel="rdfs-seeAlso">Phar::convertToData()</a> - Convert a phar archive to a non-executable tar or zip file</span></li> <li class="member"> <span class="function"><a href="phardata.converttoexecutable.html" class="function" rel="rdfs-seeAlso">PharData::convertToExecutable()</a> - Convert a non-executable tar/zip archive to an executable phar archive</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phardata.construct.html">PharData::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="phardata.converttoexecutable.html">PharData::convertToExecutable</a></div> <div class="up"><a href="class.phardata.html">PharData</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>