[英]Find file inside phar with symfony finder
我有以下代碼在源代碼樹中的名為robofile-templates的目錄中查找文件。 現在,我將該應用程序打包到一個phar文件中。
我可以使用類似的代碼來遍歷phar文件中包含的文件,還是必須重寫它?
protected function getTemplateRoboFiles() {
$base = dirname( __DIR__ );
$templates = [];
$finder = new Finder();
$finder->directories()->in( $base )->name( 'robofile-templates' );
foreach ( $finder as $directory ) {
$fileFinder = new Finder();
$fileFinder->files()->in( $directory->getRealPath() )->name( '*.php' );
foreach ( $fileFinder as $file ) {
$templates[ $file->getBasename( '.php' ) ] = $file->getRealPath();
}
}
return $templates;
}
編輯:足夠有趣,在PHAR內部運行opendir
/ readdir
。 我可以使用這些基本文件功能,但是我認為Symfony文件查找器是基於相同的基本命令構建的嗎?
Symfony finder可以按預期工作,也可以查找文件。
我的問題出在流程的另一部分:我正在使用composer install構建phar,而我的composer.lock沒有數據。 由於我試圖在存檔中找到的文件位於composer模塊中,因此實際上並未包含在phar中。
那么,誰在絆腳石:最好檢查一下您的文件是否真的打包到了phar中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.