/** * Returns a path relative to a site's root directory. */ public static function getRelativePath(IPieCrust $pieCrust, $path, $stripExtension = false) { $relativePath = PathHelper::getRelativePath($pieCrust->getRootDir(), $path); if ($stripExtension) { $relativePath = preg_replace('/\\.[a-zA-Z0-9]+$/', '', $relativePath); } return $relativePath; }
/** * Returns a path relative to a site's root directory. */ public static function getRelativePath(IPieCrust $pieCrust, $path, $stripExtension = false) { $basePath = null; $themeDir = $pieCrust->getThemeDir(); if ($themeDir and strncmp($path, $themeDir, strlen($themeDir)) == 0) { // Theme path. $basePath = $themeDir; } else { // Normal website path. $basePath = $pieCrust->getRootDir(); } if (!$basePath) { throw new PieCrustException("Can't get a relative path for '{$path}': it doesn't seem to be either a website, theme or resource path."); } $relativePath = PathHelper::getRelativePath($basePath, $path); if ($stripExtension) { $relativePath = preg_replace('/\\.[a-zA-Z0-9]+$/', '', $relativePath); } return $relativePath; }
public function initialize(IPieCrust $pieCrust, $logger = null) { $this->rootDirLength = strlen($pieCrust->getRootDir()); }