gpt4 book ai didi

php - symfony 符号链接(symbolic link)和 src 路径解析

转载 作者:太空宇宙 更新时间:2023-11-04 03:56:18 24 4
gpt4 key购买 nike

如果您的服务器上有如下设置:

/path/sites/site1
app/
bin/
web/
src/
vendor/ -> /path/vendor/Symfony_2.0.3/vendor (symbolic links)
/path/sites/site2
app/
bin/
web/
src/
vendor/ -> /path/vendor/Symfony_2.0.3/vendor (symbolic links)
/path/vendor/Symfony_2.0.3/vendor

symfony 如何知道在哪里可以找到 src 文件夹等?

作为 php 中的 __DIR__ 等,会将/path/sites/site2/vendor 解析为实际的真实路径...

最佳答案

通过反射(reflection)!

Symfony 1.x

sfProjectConfiguration.class.php

static public function guessRootDir()
{
$r = new ReflectionClass('ProjectConfiguration');

return realpath(dirname($r->getFileName()).'/..');
}

Symfony 2

Symfony\Component\HttpKernel\Kernel

public function getRootDir()
{
if (null === $this->rootDir) {
$r = new \ReflectionObject($this);
$this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
}

return $this->rootDir;
}

关于php - symfony 符号链接(symbolic link)和 src 路径解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24579296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com