简体   繁体   English

使用symfony finder在phar中查找文件

[英]Find file inside phar with symfony finder

I have the following code to find files in a directory called robofile-templates in my source tree. 我有以下代码在源代码树中的名为robofile-templates的目录中查找文件。 Now I am packaging the app into a phar file. 现在,我将该应用程序打包到一个phar文件中。

Can I use similar code to iterate over the files contained in the phar file or do I have to rewrite it? 我可以使用类似的代码来遍历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;
}

EDIT: Interesting enough, opendir / readdir work inside the PHAR. 编辑:足够有趣,在PHAR内部运行opendir / readdir I could resort to use those basic file functions, but I think Symfony file finder is built on the same basic commands? 我可以使用这些基本文件功能,但是我认为Symfony文件查找器是基于相同的基本命令构建的吗?

Symfony finder is working as expected, also finding files in phars. Symfony finder可以按预期工作,也可以查找文件。

My problem was on another part of the process: I was building the phar using composer install and my composer.lock was not up to data. 我的问题出在流程的另一部分:我正在使用composer install构建phar,而我的composer.lock没有数据。 As the file I was trying to find in the archive, was in a composer module, it was just not actually included in the phar. 由于我试图在存档中找到的文件位于composer模块中,因此实际上并未包含在phar中。

So who is stumbling across this: Better check if your file is really packaged into the phar. 那么,谁在绊脚石:最好检查一下您的文件是否真的打包到了phar中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM