3 namespace Friendica\Util;
10 * @brief Returns the base filesystem path of the App
12 * It first checks for the internal variable, then for DOCUMENT_ROOT and
15 * @param string|null $basePath The default base path
16 * @param array $server server arguments
20 * @throws \Exception if directory isn't usable
22 public static function create($basePath, $server = [])
24 if (!$basePath && !empty($server['DOCUMENT_ROOT'])) {
25 $basePath = $server['DOCUMENT_ROOT'];
28 if (!$basePath && !empty($server['PWD'])) {
29 $basePath = $server['PWD'];
32 return self::getRealPath($basePath);
36 * @brief Returns a normalized file path
38 * This is a wrapper for the "realpath" function.
39 * That function cannot detect the real path when some folders aren't readable.
40 * Since this could happen with some hosters we need to handle this.
42 * @param string $path The path that is about to be normalized
43 * @return string normalized path - when possible
45 public static function getRealPath($path)
47 $normalized = realpath($path);
49 if (!is_bool($normalized)) {
57 * @brief Checks if a given directory is usable for the system
60 * @param bool $check_writable
62 * @return boolean the directory is usable
64 public static function isDirectoryUsable($directory, $check_writable = true)
66 if ($directory == '') {
67 Core\Logger::log('Directory is empty. This shouldn\'t happen.', Core\Logger::DEBUG);
71 if (!file_exists($directory)) {
72 Core\Logger::log('Path "' . $directory . '" does not exist for user ' . Core\System::getUser(), Core\Logger::DEBUG);
76 if (is_file($directory)) {
77 Core\Logger::log('Path "' . $directory . '" is a file for user ' . Core\System::getUser(), Core\Logger::DEBUG);
81 if (!is_dir($directory)) {
82 Core\Logger::log('Path "' . $directory . '" is not a directory for user ' . Core\System::getUser(), Core\Logger::DEBUG);
86 if ($check_writable && !is_writable($directory)) {
87 Core\Logger::log('Path "' . $directory . '" is not writable for user ' . Core\System::getUser(), Core\Logger::DEBUG);