Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(dev/cloud-native#3) CRM_Utils_File - Deprecate baseFilePath() et al #14778

Merged
merged 3 commits into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions CRM/Utils/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,19 @@ public static function restrictBrowsing($publicDir) {
}

/**
* Create the base file path from which all our internal directories are
* offset. This is derived from the template compile directory set
* (Deprecated) Create the file-path from which all other internal paths are
* computed. This implementation determines it as `dirname(CIVICRM_TEMPLATE_COMPILEDIR)`.
*
* This approach is problematic - e.g. it prevents one from authentically
* splitting the CIVICRM_TEMPLATE_COMPILEDIR away from other dirs. The implementation
* is preserved for backwards compatibility (and should only be called by
* CMS-adapters and by Civi\Core\Paths).
*
* Do not use it for new path construction logic. Instead, use Civi::paths().
*
* @deprecated
* @see \Civi::paths()
* @see \Civi\Core\Paths
*/
public static function baseFilePath() {
static $_path = NULL;
Expand Down Expand Up @@ -629,6 +640,10 @@ public static function isAbsolute($path) {
* @param $directory
*
* @return string
* @deprecated
* Computation of a relative path requires some base.
* This implementation is problematic because it relies on an
* implicit base which was constructed problematically.
*/
public static function relativeDirectory($directory) {
// Do nothing on windows
Expand All @@ -655,12 +670,12 @@ public static function relativeDirectory($directory) {

/**
* @param $directory
* @param string|NULL $basePath
* @param string $basePath
* The base path when evaluating relative paths. Should include trailing slash.
*
* @return string
*/
public static function absoluteDirectory($directory, $basePath = NULL) {
public static function absoluteDirectory($directory, $basePath) {
// check if directory is already absolute, if so return immediately
// Note: Windows PHP accepts any mix of "/" or "\", so "C:\htdocs" or "C:/htdocs" would be a valid absolute path
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && preg_match(';^[a-zA-Z]:[/\\\\];', $directory)) {
Expand All @@ -672,8 +687,12 @@ public static function absoluteDirectory($directory, $basePath = NULL) {
return $directory;
}

// make everything absolute from the baseFilePath
$basePath = ($basePath === NULL) ? self::baseFilePath() : $basePath;
if ($basePath === NULL) {
// Previous versions interpreted `NULL` to mean "default to `self::baseFilePath()`".
// However, no code in the known `universe` relies on this interpretation, and
// the `baseFilePath()` function is problematic/deprecated.
throw new \RuntimeException("absoluteDirectory() requires specifying a basePath");
}

// ensure that $basePath has a trailing slash
$basePath = self::addTrailingSlash($basePath);
Expand Down