Phar::mount

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

Phar::mount — phar 아카이브 내의 가상 위치에 외부 경로 또는 파일을 마운트합니다.


설명

final public static Phar::mount(string $pharPath, string $externalPath): void

디렉토리 트리 내의 경로에 외부 장치를 마운트하는 유닉스 파일 시스템 개념과 매우 유사하게 Phar::mount()를 사용하면 외부 파일 및 디렉토리를 아카이브 내부에 있는 것처럼 참조할 수 있습니다. 이것은 마치 아카이브 내부에 있는 것처럼 외부 구성 파일을 참조하는 것과 같은 강력한 추상화를 허용합니다.


매개변수

pharPath
마운트된 경로 위치로 사용할 phar 아카이브 내의 내부 경로. 이것은 phar 아카이브 내의 상대 경로여야 하며 이미 존재하지 않아야 합니다.
externalPath
phar 아카이브 내에서 마운트할 외부 파일 또는 디렉토리의 경로 또는 URL

반환 값

반환이 없습니다. 실패 시 PharException이 발생합니다.


오류/예외

경로를 마운트하는 데 문제가 발생하면 PharException이 발생합니다.


Examples

예제 #1 Phar::mount() 예제

다음 예는 phar 아카이브 내의 경로인 것처럼 외부 구성 파일에 액세스하는 것을 보여줍니다.

먼저 phar 아카이브 내부의 코드:

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

다음으로 구성 파일을 마운트하는 데 사용되는 외부 코드:

                  
<?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';
?>
                  
                

또 다른 메서드는 phar 아카이브의 스텁 안에 마운팅 코드를 넣는 것입니다. 다음은 사용자 구성이 지정되지 않은 경우 기본 구성 파일을 설정하는 예입니다.

                  
<?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();
?>
                  
                

...이 phar 아카이브를 로드하기 위한 외부 코드:

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