2017-08-30 70 views
0

我有以下代碼來查找我的源代碼樹中名爲robofile-templates的目錄中的文件。 現在我將應用程序打包到phar文件中。使用symfony查找程序在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; 
} 

編輯:夠有意思,裏面藥業opendir/readdir工作。我可以訴諸使用這些基本的文件功能,但我認爲Symfony文件查找程序是基於相同的基本命令構建的?

回答

0

Symfony finder按預期工作,也在phars中查找文件。

我的問題出現在另一部分過程中:我正在使用作曲家安裝構建phar,而我的composer.lock不符合數據。正如我試圖在檔案中找到的那個文件,是在作曲家模塊中,它實際上並沒有包含在phar中。

那麼,誰在絆倒這個問題:最好檢查一下你的文件是否真的被封裝在phar中。