Phar::mount

(PHP 5 >= 5.3.0, PHP 7, PECL phar >= 2.0.0)

Phar::mountMount an external path or file to a virtual location within the phar archive

说明

final public static Phar::mount ( string $pharpath , string $externalpath ) : void

Much like the unix file system concept of mounting external devices to paths within the directory tree, Phar::mount() allows referring to external files and directories as if they were inside of an archive. This allows powerful abstraction such as referring to external configuration files as if they were inside the archive.

参数

pharpath

The internal path within the phar archive to use as the mounted path location. This must be a relative path within the phar archive, and must not already exist.

externalpath

A path or URL to an external file or directory to mount within the phar archive

返回值

No return. PharException is thrown on failure.

错误/异常

Throws PharException if any problems occur mounting the path.

范例

Example #1 A Phar::mount() example

The following example shows accessing an external configuration file as if it were a path within a phar archive.

First, the code inside of a phar archive:

<?php
$configuration 
simplexml_load_string(file_get_contents(
    
Phar::running(false) . '/config.xml'));
?>

Next the external code used to mount the configuration file:

<?php
// first set up the association between the abstract config.xml
// and the actual one on disk
Phar::mount('phar://config.xml''/home/example/config.xml');
// now run the application
include '/path/to/archive.phar';
?>

Another method is to put the mounting code inside the stub of the phar archive. Here is an example of setting up a default configuration file if no user configuration is specified:

<?php
// first set up the association between the abstract config.xml
// and the actual one on disk
if (defined('EXTERNAL_CONFIG')) {
    
Phar::mount('config.xml'EXTERNAL_CONFIG);
    if (
file_exists(__DIR__ '/extra_config.xml')) {
        
Phar::mount('extra.xml'__DIR__ '/extra_config.xml');
    }
} else {
    
Phar::mount('config.xml''phar://' __FILE__ '/default_config.xml');
    
Phar::mount('extra.xml''phar://' __FILE__ '/default_extra.xml');
}
// now run the application
include 'phar://' __FILE__ '/index.php';
__HALT_COMPILER();
?>

...and the code externally to load this phar archive:

<?php
define
('EXTERNAL_CONFIG''/home/example/config.xml');
// now run the application
include '/path/to/archive.phar';
?>

相关文章
php wincache 函数 retrieves information about resolve file path cachephp phar construct a phar archive from the files within a directoryphp phar compresses the entire phar archive using gzip or bzip2 compressionphp phar compresses all files in the current phar archive using bzip2 compressionphp phar convert a phar archive to a non executable tar or zip filephp phar convert a phar archive to another executable phar archive file formatphp phar copy a file internal to the phar archive to another new file within the pharphp phar get the real path to the phar archive on diskphp phar returns true if the phar archive is based on the tar/phar/zip file format depending on the parameterphp phar mount an external path or file to a virtual location within the phar archivephp phar set the contents of an internal file to those of an external filephp phar returns the full path on disk or full phar url to the currently executing phar archivephp phar stop buffering write requests to the phar archive and save changes to diskphp phardata convert a phar archive to a non executable tar or zip filephp phardata copy a file internal to the phar archive to another new file within the pharphp phardata delete a file within a tar/zip archivephp phardata set the contents of a file within the tar/zip to those of an external file or stringphp pharfileinfo returns the actual size of the file with compression inside the phar archivephp pharfileinfo compresses the current phar entry within the phar using bzip2 compressionphp ziparchive adds a file to a zip archive from the given path
关注编程学问公众号