Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 10313

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Using Phar Archives: the Phar and PharData class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phar.using.stream.html">Using Phar Archives: the phar stream wrapper</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phar.creating.html">Creating Phar Archives</a></div>
 <div class="up"><a href="phar.using.html">Using Phar Archives</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="phar.using.object" class="section">
 <h2 class="title">Using Phar Archives: the Phar and PharData class</h2>
 <p class="para">
  The <a href="class.phar.html" class="classname">Phar</a> class supports reading and manipulation
  of Phar archives, as well as iteration through inherited functionality of
  the <a href="class.recursivedirectoryiterator.html" class="classname">RecursiveDirectoryIterator</a>
  class.  With support for the <a href="class.arrayaccess.html" class="classname">ArrayAccess</a>
  interface, files inside a Phar archive can be accessed as if they were
  part of an associative array.
 </p>
 <p class="para">
  The <a href="class.phardata.html" class="classname">PharData</a> class extends the <a href="class.phar.html" class="classname">Phar</a>, and
  allows creating and modifying non-executable (data) tar and zip archives even if
  <em>phar.readonly</em>=1 in php.ini.  As such,
   <span class="function"><a href="phardata.setalias.html" class="function">PharData::setAlias()</a></span> and  <span class="function"><a href="phardata.setstub.html" class="function">PharData::setStub()</a></span>
  are both disabled as the concept of alias and stub are unique to executable phar
  archives.
 </p>
 <p class="para">
  It is important to note that when creating a Phar archive, the full path
  should be passed to the <a href="class.phar.html" class="classname">Phar</a> object constructor.
  Relative paths will fail to initialize.
 </p>
 <p class="para">
  Assuming that <em>$p</em> is a Phar object initialized as follows:
 </p>
 <p class="para">
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$p&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/myphar.phar'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </p>
 <p class="para">
  An empty Phar archive will be created at <em>/path/to/myphar.phar</em>,
  or if <em>/path/to/myphar.phar</em> already exists, it will be opened
  again.  The literal <em>myphar.phar</em> demonstrates the concept of an alias
  that can be used to reference <em>/path/to/myphar.phar</em> in URLs as in:
 </p>
 <p class="para">
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;these&nbsp;two&nbsp;calls&nbsp;to&nbsp;file_get_contents()&nbsp;are&nbsp;equivalent&nbsp;if<br />//&nbsp;/path/to/myphar.phar&nbsp;has&nbsp;an&nbsp;explicit&nbsp;alias&nbsp;of&nbsp;"myphar.phar"<br />//&nbsp;in&nbsp;its&nbsp;manifest,&nbsp;or&nbsp;if&nbsp;the&nbsp;phar&nbsp;was&nbsp;initialized&nbsp;with&nbsp;the<br />//&nbsp;previous&nbsp;example's&nbsp;Phar&nbsp;object&nbsp;setup<br /></span><span style="color: #0000BB">$f&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar:///path/to/myphar.phar/whatever.txt'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$f&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://myphar.phar/whatever.txt'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </p>
 <p class="para">
  With the newly created <em>$p</em> <a href="class.phar.html" class="classname">Phar</a> object,
  the following is possible:
  <ul class="itemizedlist">
   <li class="listitem">
    <span class="simpara">
     <em>$a = $p[&#039;file.php&#039;]</em> creates a <a href="class.pharfileinfo.html" class="classname">PharFileInfo</a>
     class that refers to the contents of <em>phar://myphar.phar/file.php</em>
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <em>$p[&#039;file.php&#039;] = $v</em> creates a new file
     (<em>phar://myphar.phar/file.php</em>), or overwrites
     an existing file within <em>myphar.phar</em>.  <em>$v</em>
     can be either a string or an open file pointer, in which case the entire
     contents of the file will be used to create the new file.  Note that
     <em>$p-&gt;addFromString(&#039;file.php&#039;, $v)</em> is functionally
     equivalent to the above.  Also possible is to add the contents of a file
     with <em>$p-&gt;addFile(&#039;/path/to/file.php&#039;, &#039;file.php&#039;)</em>.
     Lastly, an empty directory can be created with
     <em>$p-&gt;addEmptyDir(&#039;empty&#039;)</em>.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <em>isset($p[&#039;file.php&#039;])</em> can be used to determine
     whether <em>phar://myphar.phar/file.php</em> exists within
     <em>myphar.phar</em>.
    </span>
   </li>
   <li class="listitem">
    <span class="simpara">
     <em>unset($p[&#039;file.php&#039;])</em> erases
     <em>phar://myphar.phar/file.php</em> from
     <em>myphar.phar</em>.
    </span>
   </li>
  </ul>
 </p>
 <p class="para">
  In addition, the <a href="class.phar.html" class="classname">Phar</a> object is the only way to access
  Phar-specific metadata, through
   <span class="function"><a href="phar.getmetadata.html" class="function">Phar::getMetadata()</a></span>,
  and the only way to set or retrieve a Phar archive&#039;s PHP loader stub through
   <span class="function"><a href="phar.getstub.html" class="function">Phar::getStub()</a></span> and
   <span class="function"><a href="phar.setstub.html" class="function">Phar::setStub()</a></span>.
  Additionally, compression for the entire Phar archive at once can only be manipulated
  using the <a href="class.phar.html" class="classname">Phar</a> class.
 </p>
 <p class="para">
  The full list of <a href="class.phar.html" class="classname">Phar</a> object functionality is documented
  below.
 </p>
 <p class="para">
  The <a href="class.pharfileinfo.html" class="classname">PharFileInfo</a> class extends the
  <a href="class.splfileinfo.html" class="classname">SplFileInfo</a>
  class, and adds several methods for manipulating Phar-specific details of a file
  contained within a Phar, such as manipulating compression and metadata.
 </p>
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phar.using.stream.html">Using Phar Archives: the phar stream wrapper</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phar.creating.html">Creating Phar Archives</a></div>
 <div class="up"><a href="phar.using.html">Using Phar Archives</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>