philip Fri Mar 16 02:16:06 2007 UTC
Modified files:
/phpdoc/en/reference/phar using.xml
Log:
markup
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/phar/using.xml?r1=1.3&r2=1.4&diff_format=u
Index: phpdoc/en/reference/phar/using.xml
diff -u phpdoc/en/reference/phar/using.xml:1.3
phpdoc/en/reference/phar/using.xml:1.4
--- phpdoc/en/reference/phar/using.xml:1.3 Tue Feb 6 05:46:41 2007
+++ phpdoc/en/reference/phar/using.xml Fri Mar 16 02:16:04 2007
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.3 $ -->
+<!-- $Revision: 1.4 $ -->
<section id="phar.using.basics">
<title>Using Phar Archives: Introduction</title>
<para>
@@ -18,13 +18,17 @@
<para>
Using a Phar archive library is identical to using any other PHP library:
</para>
- <programlisting role="php">
- <![CDATA[
+ <para>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
<?php
include 'coollibrary.phar';
?>
- ]]>
- </programlisting>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
<para>
What makes Phar archives incredibly useful is the <literal>phar</literal>
stream wrapper, which is explained in depth <link
linkend="phar.using.stream">here</link>.
@@ -33,24 +37,30 @@
The <literal>phar</literal> stream wrapper supports all read/write operations
on files, and <function>opendir</function> on directories.
</para>
- <programlisting role="php">
- <![CDATA[
+ <para>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
<?php
include 'phar://coollibrary.phar/internal/file.php';
header('Content-type: image/jpeg');
// phars can be accessed by full path or by alias
echo file_get_contents('phar:///fullpath/to/coollibrary.phar/images/wow.jpg');
?>
- ]]>
- </programlisting>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
<para>
Also provided with the Phar extension is the <classname>Phar</classname>
class,
which allows accessing the files of the Phar archive as if it were an
associative array, and other functionality. The Phar class is explained
<link linkend="phar.using.object">here</link>.
</para>
- <programlisting role="php">
- <![CDATA[
+ <para>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
<?php
try {
// open an existing phar
@@ -99,8 +109,10 @@
echo 'Could not open Phar: ', $e;
}
?>
- ]]>
- </programlisting>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
</section>
<section id="phar.using.stream">
<title>Using Phar Archives: the phar stream wrapper</title>
@@ -116,16 +128,20 @@
Individual file compression and per-file metadata can also be manipulated
in a Phar archive using stream contexts:
</para>
- <programlisting role="php">
- <![CDATA[
+ <para>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
<?php
$context = stream_context_create(array('phar' =>
array('compression' => Phar::GZ)),
array('metadata' => array('user' =>
'cellog')));
file_put_contents('phar://my.phar/somefile.php', 0, $context);
?>
- ]]>
- </programlisting>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
<para>
The <literal>phar</literal> stream wrapper does not operate on remote files,
and cannot operate on remote files, and so is allowed even when the
@@ -157,19 +173,28 @@
</para>
<para>
Assuming that <literal>$p</literal> is a Phar object initialized as follows:
- <programlisting role="php">
- <![CDATA[
+ </para>
+ <para>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
<?php
$p = new Phar('/path/to/myphar.phar', 0, 'myphar.phar');
?>
- ]]>
- </programlisting>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
+ <para>
An empty Phar archive will be created at
<literal>/path/to/myphar.phar</literal>,
or if <literal>/path/to/myphar.phar</literal> already exists, it will be
opened
again. The literal <literal>myphar.phar</literal> deomnstrates the concept
of an alias
that can be used to reference <literal>/path/to/myphar.phar</literal> in
URLs as in:
- <programlisting role="php">
- <![CDATA[
+ </para>
+ <para>
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
<?php
// these two calls to file_get_contents() are equivalent if
// /path/to/myphar.phar has an explicit alias of "myphar.phar"
@@ -178,8 +203,11 @@
$f = file_get_contents('phar:///path/to/myphar.phar/whatever.txt');
$f = file_get_contents('phar://myphar.phar/whatever.txt');
?>
- ]]>
- </programlisting>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
+ <para>
With the newly created <literal>$p</literal> <classname>Phar</classname>
object,
the following is possible:
<itemizedlist>