Phar::webPhar
(No version information available, might be only in CVS) Phar::webPhar — mapPhar for web-based phars. front controller for web applications
Description
void Phar::webPhar
( string $alias
, string $index
, string $f404
, array $mimetypes
, array $rewrites
)
Phar::webPhar() should only be
called from the stub of a phar archive (see here
for more information on what a stub is).
Parameters
-
alias
-
The alias that can be used in phar:// URLs to
refer to this archive, rather than its full path.
-
index
-
The location within the phar of the directory index, defaults to
index.php.
-
f404
-
The location of the script to run when a file is not found. This
script should output the proper HTTP 404 headers.
-
mimetypes
-
An array mapping additional file extensions to MIME type. By default,
these extensions are mapped to these mime types:
$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',
);
-
rewrites
-
An array mapping URI to internal file, simulating mod_rewrite of apache.
For example:
array(
'myinfo' => 'myinfo.php'
);
would route calls to http://<host>/myphar.phar/myinfo
to the file phar:///path/to/myphar.phar/myinfo.php, preserving
GET/POST. This does not quite work like mod_rewrite in that it would not
match http://<host>/myphar.phar/myinfo/another.
Return Values
No return values
Errors/Exceptions
Throws PharException when unable to open the internal
file to output, or if
called from a non-stub. If an invalid array value is passed into
mimetypes
or to rewrites
, then
UnexpectedValueException is thrown.
Examples
Example #1 A Phar::webPhar() example
With the example below, the created phar will display Hello World
if one browses to /myphar.phar/index.php or to
/myphar.phar, and will display the source of
index.phps if one browses to /myphar.phar/index.phps.
<?php
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) {
}
?>
add a note
User Contributed Notes
mapPhar for web-based phars. front controller for web applications
There are no user contributed notes for this page.
|
|