Phar存档没有Symfony文件系统的读写权限 [英] Phar archive no read and write permissions with symfony filesystem
问题描述
我创建了一个cli应用程序,该应用程序尝试使用symfony 3 fileSystem组件创建文件.一切正常,但是如果我将应用程序放在phar存档中,symfony无法写入该文件.
i have created a cli app which tries to create a file with symfony 3 fileSystem component. All works fine, but if i put the app in a phar archive symfony can't write the file.
这是我创建phar存档的方式:
This is how i created the phar archive:
<?php
$phar = new Phar('app.phar', 0, 'app.phar');
$phar->buildFromDirectory(dirname(__FILE__) );
$phar->setStub($phar->createDefaultStub('app.php'));
app.php调用symfony文件系统组件:
The app.php call the symfony filesystem component:
<?php
....
$this->fileSystem->dumpFile(
'testfile.txt',
'my test content'
);
如果我直接执行app.php,这很好.但是,如果我将其作为.phar执行,则会收到此消息.
This works fine if i execute app.php directly. But if i execute it as a .phar i get this message.
[Symfony\Component\Filesystem\Exception\IOException]
Failed to create ".": mkdir(): File exists.
其他操作,例如echo
正常运行.
我认为,phar存档的IO操作存在问题.但是我不理解问题出在哪里.在我的php.ini中,配置了phar.readonly = Off.
Other operations like echo
working fine.
In my opinion i think, that the phar archive has a problem with IO operations. But i don't unterstand whats the problem. In my php.ini is phar.readonly=Off configured.
我希望有人能给我提示. :)
I hope someone can give me a hint. :)
推荐答案
Phar具有不同的路径结构,而symfony方法确实具有dirname($filename);
Phar's have a different path structure, and that symfony method does dirname($filename);
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Filesystem/Filesystem.php#L679
尝试定义完整路径.
$path = '.';
if (!empty($pharPath = \Phar::running(false))) {
$path = dirname($pharPath);
}
$this->fileSystem->dumpFile(
$path.'/testfile.txt',
'my test content'
);
这篇关于Phar存档没有Symfony文件系统的读写权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!