1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.4 $ -->
<refentry xml:id="phar.webphar" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Phar::webPhar</refname>
<refpurpose>mapPhar for web-based phars. front controller for web applications</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>void</type><methodname>Phar::webPhar</methodname>
<methodparam><type>string</type><parameter>alias</parameter></methodparam>
<methodparam><type>string</type><parameter>index</parameter></methodparam>
<methodparam><type>string</type><parameter>f404</parameter></methodparam>
<methodparam><type>array</type><parameter>mimetypes</parameter></methodparam>
<methodparam><type>array</type><parameter>rewrites</parameter></methodparam>
</methodsynopsis>
<para>
<function>Phar::mapPhar</function> for web-based phars. This method parses
<varname>$_SERVER['REQUEST_URI']</varname> and routes a request from a web
browser to an internal file within the phar archive. In essence, it simulates
a web server, routing requests to the correct file, echoing the correct headers
and parsing PHP files as needed. This powerful method is part of what makes it easy
to convert an existing PHP application into a phar archive. Combined with
<function>Phar::mungServer</function> and <function>Phar::interceptFileFuncs</function>,
any web application can be used unmodified from a phar archive.
</para>
<para>
<function>Phar::webPhar</function> should only be
called from the stub of a phar archive (see <link linkend="phar.fileformat.stub">here</link>
for more information on what a stub is).
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>alias</parameter></term>
<listitem>
<para>
The alias that can be used in <literal>phar://</literal> URLs to
refer to this archive, rather than its full path.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>index</parameter></term>
<listitem>
<para>
The location within the phar of the directory index, defaults to
<literal>index.php</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>f404</parameter></term>
<listitem>
<para>
The location of the script to run when a file is not found. This
script should output the proper HTTP 404 headers.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mimetypes</parameter></term>
<listitem>
<para>
An array mapping additional file extensions to MIME type. By default,
these extensions are mapped to these mime types:
<programlisting role="php">
<![CDATA[
$mimes = array(
'phps' => 2, // pass to highlight_file()
'c' => 'text/plain',
'cc' => 'text/plain',
'cpp' => 'text/plain',
'c++' => 'text/plain',
'dtd' => 'text/plain',
'h' => 'text/plain',
'log' => 'text/plain',
'rng' => 'text/plain',
'txt' => 'text/plain',
'xsd' => 'text/plain',
'php' => 1, // parse as PHP
'inc' => 1, // parse as PHP
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'css' => 'text/css',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'htmls' => 'text/html',
'ico' => 'image/x-ico',
'jpe' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'js' => 'application/x-javascript',
'midi' => 'audio/midi',
'mid' => 'audio/midi',
'mod' => 'audio/mod',
'mov' => 'movie/quicktime',
'mp3' => 'audio/mp3',
'mpg' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'pdf' => 'application/pdf',
'png' => 'image/png',
'swf' => 'application/shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'wav' => 'audio/wav',
'xbm' => 'image/xbm',
'xml' => 'text/xml',
);
]]>
</programlisting>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>rewrites</parameter></term>
<listitem>
<para>
An array mapping URI to internal file, simulating mod_rewrite of apache.
For example:
<programlisting role="php">
<![CDATA[
array(
'myinfo' => 'myinfo.php'
);
]]>
</programlisting>
would route calls to <literal>http://<host>/myphar.phar/myinfo</literal>
to the file <literal>phar:///path/to/myphar.phar/myinfo.php</literal>, preserving
GET/POST. This does not quite work like mod_rewrite in that it would not
match <literal>http://<host>/myphar.phar/myinfo/another</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
No return values
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>PharException</classname> when unable to open the internal
file to output, or if
called from a non-stub. If an invalid array value is passed into
<parameter>mimetypes</parameter> or to <parameter>rewrites</parameter>, then
<classname>UnexpectedValueException</classname> is thrown.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>A <function>Phar::webPhar</function> example</title>
<para>
With the example below, the created phar will display <literal>Hello World</literal>
if one browses to <literal>/myphar.phar/index.php</literal> or to
<literal>/myphar.phar</literal>, and will display the source of
<literal>index.phps</literal> if one browses to <literal>/myphar.phar/index.phps</literal>.
</para>
<programlisting role="php">
<![CDATA[
<?php
// creating the phar archive:
try {
$phar = new Phar('myphar.phar');
$phar['index.php'] = '<?php echo "Hello World"; ?>';
$phar['index.phps'] = '<?php echo "Hello World"; ?>';
$phar->setStub('<?php
Phar::webPhar();
__HALT_COMPILER(); ?>');
} catch (Exception $e) {
// handle error here
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>Phar::mungServer</function></member>
<member><function>Phar::interceptFileFuncs</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|