php-doc-en/reference/phar/Phar/mapPhar.xml

127 lines
3.4 KiB
XML
Raw Permalink Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="phar.mapphar" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Phar::mapPhar</refname>
<refpurpose>Reads the currently executed file (a phar) and registers its manifest</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <modifier>static</modifier> <type>bool</type><methodname>Phar::mapPhar</methodname>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>alias</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
This static method can only be used inside a Phar archive's loader stub
in order to initialize the phar when it is directly executed, or when
it is included in another script.
</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>offset</parameter></term>
<listitem>
<para>
Unused variable, here for compatibility with PEAR's PHP_Archive.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
<classname>PharException</classname> is thrown if not called directly within PHP execution,
if no __HALT_COMPILER(); token is found in the current source file, or if
the file cannot be opened for reading.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>A <function>Phar::mapPhar</function> example</title>
<para>
mapPhar should be used only inside a phar's loader stub. Use
loadPhar to load an external phar into memory.
</para>
<para>
Here is a sample Phar loader stub that uses mapPhar.
</para>
<programlisting role="php">
<![CDATA[
<?php
function __autoload($class)
{
include 'phar://me.phar/' . str_replace('_', '/', $class) . '.php';
}
try {
Phar::mapPhar('me.phar');
include 'phar://me.phar/startup.php';
} catch (PharException $e) {
echo $e->getMessage();
die('Cannot initialize Phar');
}
__HALT_COMPILER();
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>Phar::loadPhar</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:"~/.phpdoc/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
-->