friendica/src/Util/BasePath.php

54 lines
1.2 KiB
PHP
Raw Normal View History

2019-02-03 22:22:04 +01:00
<?php
namespace Friendica\Util;
class BasePath
{
/**
* @brief Returns the base filesystem path of the App
*
* It first checks for the internal variable, then for DOCUMENT_ROOT and
* finally for PWD
*
2019-02-05 22:27:57 +01:00
* @param string|null $basePath The default base path
* @param array $server server arguments
2019-02-03 22:22:04 +01:00
*
* @return string
*
* @throws \Exception if directory isn't usable
*/
2019-02-05 22:27:57 +01:00
public static function create($basePath, $server = [])
2019-02-03 22:22:04 +01:00
{
2019-02-05 22:27:57 +01:00
if (!$basePath && !empty($server['DOCUMENT_ROOT'])) {
$basePath = $server['DOCUMENT_ROOT'];
2019-02-03 22:22:04 +01:00
}
2019-02-05 22:27:57 +01:00
if (!$basePath && !empty($server['PWD'])) {
$basePath = $server['PWD'];
2019-02-03 22:22:04 +01:00
}
2019-02-05 22:27:57 +01:00
return self::getRealPath($basePath);
2019-02-03 22:22:04 +01:00
}
/**
* @brief Returns a normalized file path
*
* This is a wrapper for the "realpath" function.
* That function cannot detect the real path when some folders aren't readable.
* Since this could happen with some hosters we need to handle this.
*
* @param string $path The path that is about to be normalized
* @return string normalized path - when possible
*/
public static function getRealPath($path)
{
$normalized = realpath($path);
if (!is_bool($normalized)) {
return $normalized;
} else {
return $path;
}
}
}