namespace Friendica\Util;
-use Friendica\Core;
-
class BasePath
{
/**
* It first checks for the internal variable, then for DOCUMENT_ROOT and
* finally for PWD
*
- * @param string|null $basepath
+ * @param string|null $basePath The default base path
+ * @param array $server server arguments
*
* @return string
*
* @throws \Exception if directory isn't usable
*/
- public static function create($basepath)
+ public static function create($basePath, $server = [])
{
- if (!$basepath && !empty($_SERVER['DOCUMENT_ROOT'])) {
- $basepath = $_SERVER['DOCUMENT_ROOT'];
+ if (!$basePath && !empty($server['DOCUMENT_ROOT'])) {
+ $basePath = $server['DOCUMENT_ROOT'];
}
- if (!$basepath && !empty($_SERVER['PWD'])) {
- $basepath = $_SERVER['PWD'];
+ if (!$basePath && !empty($server['PWD'])) {
+ $basePath = $server['PWD'];
}
- return self::getRealPath($basepath);
+ return self::getRealPath($basePath);
}
/**
return $path;
}
}
-
-
- /**
- * @brief Checks if a given directory is usable for the system
- *
- * @param $directory
- * @param bool $check_writable
- *
- * @return boolean the directory is usable
- */
- public static function isDirectoryUsable($directory, $check_writable = true)
- {
- if ($directory == '') {
- Core\Logger::log('Directory is empty. This shouldn\'t happen.', Core\Logger::DEBUG);
- return false;
- }
-
- if (!file_exists($directory)) {
- Core\Logger::log('Path "' . $directory . '" does not exist for user ' . Core\System::getUser(), Core\Logger::DEBUG);
- return false;
- }
-
- if (is_file($directory)) {
- Core\Logger::log('Path "' . $directory . '" is a file for user ' . Core\System::getUser(), Core\Logger::DEBUG);
- return false;
- }
-
- if (!is_dir($directory)) {
- Core\Logger::log('Path "' . $directory . '" is not a directory for user ' . Core\System::getUser(), Core\Logger::DEBUG);
- return false;
- }
-
- if ($check_writable && !is_writable($directory)) {
- Core\Logger::log('Path "' . $directory . '" is not writable for user ' . Core\System::getUser(), Core\Logger::DEBUG);
- return false;
- }
-
- return true;
- }
}