<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.phar.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'phar.converttodata.php',
    1 => 'Phar::convertToData',
    2 => 'Convert a phar archive to a non-executable tar or zip file',
  ),
  'up' => 
  array (
    0 => 'class.phar.php',
    1 => 'Phar',
  ),
  'prev' => 
  array (
    0 => 'phar.construct.php',
    1 => 'Phar::__construct',
  ),
  'next' => 
  array (
    0 => 'phar.converttoexecutable.php',
    1 => 'Phar::convertToExecutable',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/phar/Phar/convertToData.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="phar.converttodata" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::convertToData</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">Phar::convertToData</span> &mdash; <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-phar.converttodata-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Phar::convertToData</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$format</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$compression</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$extension</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="class.phardata.php" class="type PharData">PharData</a></span></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 <span class="classname"><a href="class.badmethodcallexception.php" class="classname">BadMethodCallException</a></span>
   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 <span class="classname"><a href="class.phardata.php" class="classname">PharData</a></span>
   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-phar.converttodata-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">format</code></dt>
     <dd>
      <p class="para">
       This should be one of <code class="literal">Phar::TAR</code>
       or <code class="literal">Phar::ZIP</code>.  If set to <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the existing file format
       will be preserved.
      </p>
     </dd>
    
    
     <dt><code class="parameter">compression</code></dt>
     <dd>
      <p class="para">
       This should be one of <code class="literal">Phar::NONE</code> for no whole-archive
       compression, <code class="literal">Phar::GZ</code> for zlib-based compression, and
       <code class="literal">Phar::BZ2</code> for bzip-based compression.
      </p>
     </dd>
    
    
     <dt><code class="parameter">extension</code></dt>
     <dd>
      <p class="para">
       This parameter is used to override the default file extension for a
       converted archive.  Note that <code class="literal">.phar</code> 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 <code class="literal">.tar</code>, <code class="literal">.tar.gz</code>,
       and <code class="literal">.tar.bz2</code> depending on specified compression.
       For zip-based archives, the
       default extension is <code class="literal">.zip</code>.
      </p>
     </dd>
    
   </dl>
  </p>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-phar.converttodata-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   The method returns a <span class="classname"><a href="class.phardata.php" class="classname">PharData</a></span> object on success,
   or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phar.converttodata-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   This method throws <span class="classname"><a href="class.badmethodcallexception.php" class="classname">BadMethodCallException</a></span> when unable
   to compress, an unknown compression method has been specified, the requested
   archive is buffering with <span class="function"><a href="phar.startbuffering.php" class="function">Phar::startBuffering()</a></span> and
   has not concluded with <span class="function"><a href="phar.stopbuffering.php" class="function">Phar::stopBuffering()</a></span>, 
   and a <span class="classname"><a href="class.pharexception.php" class="classname">PharException</a></span> if any problems are encountered
   during the phar creation process.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-phar.converttodata-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">format</code>, <code class="parameter">compression</code>, and <code class="parameter">extension</code> are now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-phar.converttodata-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>Phar::convertToData()</strong></span> example</strong></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">&lt;?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">-&gt;</span><span style="color: #0000BB">convertToData</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">-&gt;</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">-&gt;</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">-&gt;</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">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-phar.converttodata-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="phar.converttoexecutable.php" class="function" rel="rdfs-seeAlso">Phar::convertToExecutable()</a> - Convert a phar archive to another executable phar archive file format</span></li>
    <li><span class="function"><a href="phardata.converttoexecutable.php" class="function" rel="rdfs-seeAlso">PharData::convertToExecutable()</a> - Convert a non-executable tar/zip archive to an executable phar archive</span></li>
    <li><span class="function"><a href="phardata.converttodata.php" class="function" rel="rdfs-seeAlso">PharData::convertToData()</a> - Convert a phar archive to a non-executable tar or zip file</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>