繁体   English   中英

使用symfony finder在phar中查找文件

[英]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.

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