2017-08-30 67 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中。