2008-01-21 15:23:52 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 08:40:37 +00:00
|
|
|
<!-- $Revision$ -->
|
2008-01-21 21:54:18 +00:00
|
|
|
<refentry xml:id="phar.webphar" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
2008-01-21 15:23:52 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>Phar::webPhar</refname>
|
2021-07-10 17:08:36 +00:00
|
|
|
<refpurpose>Routes a request from a web browser to an internal file within the phar archive</refpurpose>
|
2008-01-21 15:23:52 +00:00
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
|
|
|
<methodsynopsis>
|
2013-06-18 05:36:30 +00:00
|
|
|
<modifier>final</modifier> <modifier>public</modifier> <modifier>static</modifier> <type>void</type><methodname>Phar::webPhar</methodname>
|
2021-05-23 17:38:16 +00:00
|
|
|
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>alias</parameter><initializer>&null;</initializer></methodparam>
|
|
|
|
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>index</parameter><initializer>&null;</initializer></methodparam>
|
|
|
|
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>fileNotFoundScript</parameter><initializer>&null;</initializer></methodparam>
|
|
|
|
<methodparam choice="opt"><type>array</type><parameter>mimeTypes</parameter><initializer>[]</initializer></methodparam>
|
|
|
|
<methodparam choice="opt"><type class="union"><type>callable</type><type>null</type></type><parameter>rewrite</parameter><initializer>&null;</initializer></methodparam>
|
2008-01-21 15:23:52 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2021-07-10 17:08:36 +00:00
|
|
|
<function>Phar::webPhar</function> serves as <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.
|
|
|
|
It simulates a web server, routing requests to the correct file, echoing the correct
|
|
|
|
headers and parsing PHP files as needed. Combined with <function>Phar::mungServer</function>
|
|
|
|
and <function>Phar::interceptFileFuncs</function>, any web application can be used
|
|
|
|
unmodified from a phar archive.
|
2008-01-21 21:54:18 +00:00
|
|
|
</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).
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>alias</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-01-21 21:54:18 +00:00
|
|
|
The alias that can be used in <literal>phar://</literal> URLs to
|
|
|
|
refer to this archive, rather than its full path.
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>index</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2009-11-25 14:49:47 +00:00
|
|
|
The location within the phar of the directory index.
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2021-05-23 17:38:16 +00:00
|
|
|
<term><parameter>fileNotFoundScript</parameter></term>
|
2008-01-21 15:23:52 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-01-21 21:54:18 +00:00
|
|
|
The location of the script to run when a file is not found. This
|
|
|
|
script should output the proper HTTP 404 headers.
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2021-05-23 17:38:16 +00:00
|
|
|
<term><parameter>mimeTypes</parameter></term>
|
2008-01-21 15:23:52 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-08-16 17:41:10 +00:00
|
|
|
An array mapping additional file extensions to MIME type.
|
|
|
|
If the default mapping is sufficient, pass an empty array.
|
|
|
|
By default, these extensions are mapped to these MIME types:
|
2008-01-21 21:54:18 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2009-04-16 15:15:33 +00:00
|
|
|
<?php
|
2008-01-21 21:54:18 +00:00
|
|
|
$mimes = array(
|
2011-08-16 17:41:10 +00:00
|
|
|
'phps' => Phar::PHPS, // pass to highlight_file()
|
2008-01-21 21:54:18 +00:00
|
|
|
'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',
|
2011-08-16 17:41:10 +00:00
|
|
|
'php' => Phar::PHP, // parse as PHP
|
|
|
|
'inc' => Phar::PHP, // parse as PHP
|
2008-01-21 21:54:18 +00:00
|
|
|
'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',
|
|
|
|
);
|
2009-04-16 15:15:33 +00:00
|
|
|
?>
|
2008-01-21 21:54:18 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2021-05-23 17:38:16 +00:00
|
|
|
<term><parameter>rewrite</parameter></term>
|
2008-01-21 15:23:52 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-11-26 23:02:42 +00:00
|
|
|
The rewrites function is passed a string as its only parameter and must return a <type>string</type> or &false;.
|
2012-11-26 21:15:35 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If you are using fast-cgi or cgi then the parameter passed to the function is the value of the
|
|
|
|
<varname>$_SERVER['PATH_INFO']</varname> variable. Otherwise, the parameter passed to the function is the value
|
|
|
|
of the <varname>$_SERVER['REQUEST_URI']</varname> variable.
|
|
|
|
</para>
|
|
|
|
<para>
|
2012-11-26 23:02:42 +00:00
|
|
|
If a string is returned it is used as the internal file path. If &false; is returned then webPhar() will
|
2012-11-26 21:15:35 +00:00
|
|
|
send a HTTP 403 Denied Code.
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
2009-03-22 21:51:02 +00:00
|
|
|
&return.void;
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="errors">
|
|
|
|
&reftitle.errors;
|
|
|
|
<para>
|
2008-01-21 21:54:18 +00:00
|
|
|
Throws <classname>PharException</classname> when unable to open the internal
|
2008-05-08 02:54:52 +00:00
|
|
|
file to output, or if
|
2008-01-21 21:54:18 +00:00
|
|
|
called from a non-stub. If an invalid array value is passed into
|
2021-05-23 17:38:16 +00:00
|
|
|
<parameter>mimeTypes</parameter> or an invalid callback is passed into <parameter>rewrite</parameter>, then
|
2008-01-21 21:54:18 +00:00
|
|
|
<classname>UnexpectedValueException</classname> is thrown.
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2021-05-23 17:38:16 +00:00
|
|
|
<refsect1 role="changelog">
|
|
|
|
&reftitle.changelog;
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>&Version;</entry>
|
|
|
|
<entry>&Description;</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry>8.0.0</entry>
|
|
|
|
<entry>
|
|
|
|
<parameter>fileNotFoundScript</parameter>, <parameter>mimeTypes</parameter>
|
|
|
|
and <parameter>rewrite</parameter> are nullable now.
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
</refsect1>
|
|
|
|
|
2008-01-21 15:23:52 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>A <function>Phar::webPhar</function> example</title>
|
|
|
|
<para>
|
2008-01-21 21:54:18 +00:00
|
|
|
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>.
|
2008-01-21 15:23:52 +00:00
|
|
|
</para>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2008-01-21 21:54:18 +00:00
|
|
|
// 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
|
2008-01-21 15:23:52 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
<simplelist>
|
2008-01-21 21:54:18 +00:00
|
|
|
<member><function>Phar::mungServer</function></member>
|
|
|
|
<member><function>Phar::interceptFileFuncs</function></member>
|
2008-01-21 15:23:52 +00:00
|
|
|
</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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2008-01-21 15:23:52 +00:00
|
|
|
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
|
|
|
|
-->
|