【问题标题】:symfony symlinks and path resolution to srcsymfony 符号链接和到 src 的路径解析
【发布时间】:2014-07-04 18:23:01
【问题描述】:

如果您在服务器上有设置,例如:

/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 文件夹等?

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

【问题讨论】:

    标签: php linux symfony unix symfony1


    【解决方案1】:

    通过反思!

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 2013-02-20
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      相关资源
      最近更新 更多