Jarves\Jarves::resolvePath PHP Method

resolvePath() public method

('@JarvesBundle/test.png', 'Resources/public/') => /var/www/jarves/src/Jarves/Resources/public/test.png ('@JarvesBundle/test.png') => /var/www/jarves/src/Jarves/test.png ('images/test.png') => /var/www/jarves/images/webtest.png
public resolvePath ( string $path, string $suffix = '', boolean $relativePath = false ) : string
$path string
$suffix string
$relativePath boolean
return string without trailing slash when relative
    public function resolvePath($path, $suffix = '', $relativePath = false)
    {
        $path = preg_replace('/:+/', '/', $path);
        $root = realpath($this->rootDir . '/../');
        if ($bundle = $this->getBundleFromPath($path, $bundleName)) {
            $path = substr($path, strlen($bundleName) + 1);
            $bundlePath = $bundle->getPath();
            $suffix = trim($suffix, '/');
            $path = trim($path, '/');
            $bundlePath = '/' . trim($bundlePath, '/');
            $path = $bundlePath . ($suffix ? '/' . $suffix : '') . '/' . $path;
        } else {
            $path = $root . $path;
        }
        if ($relativePath) {
            return Tools::getRelativePath($path, $root);
        }
        return $path;
    }

Usage Example

Example #1
0
 /**
  * @param string $view
  *
  * @return mixed
  *
  * @throws FileNotFoundException
  * @throws \Jarves\Exceptions\BundleNotFoundException
  */
 public function getViewMTime($view)
 {
     $view = $this->jarves->resolvePath($view, 'Resources/views/');
     if (!file_exists($view)) {
         throw new FileNotFoundException(sprintf('File `%s` not found.', $view));
     }
     return filemtime($view);
 }
All Usage Examples Of Jarves\Jarves::resolvePath