]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/BasePath.php
Move mod/toggle_mobile to src/Module/ToggleMobile
[friendica.git] / src / Util / BasePath.php
index fecc63a2ab60e2a6c28f21306b822d74a67db66e..f29c2e864ec414b7d1219344e4e14d6fd0b622f9 100644 (file)
@@ -2,8 +2,6 @@
 
 namespace Friendica\Util;
 
-use Friendica\Core;
-
 class BasePath
 {
        /**
@@ -19,17 +17,23 @@ class BasePath
         *
         * @throws \Exception if directory isn't usable
         */
-       public static function create($basePath, $server = [])
+       public static function create($basePath, array $server = [])
        {
-               if (!$basePath && !empty($server['DOCUMENT_ROOT'])) {
+               if ((!$basePath || !is_dir($basePath)) && !empty($server['DOCUMENT_ROOT'])) {
                        $basePath = $server['DOCUMENT_ROOT'];
                }
 
-               if (!$basePath && !empty($server['PWD'])) {
+               if ((!$basePath || !is_dir($basePath)) && !empty($server['PWD'])) {
                        $basePath = $server['PWD'];
                }
 
-               return self::getRealPath($basePath);
+               $basePath = self::getRealPath($basePath);
+
+               if (!is_dir($basePath)) {
+                       throw new \Exception(sprintf('\'%s\' is not a valid basepath', $basePath));
+               }
+
+               return $basePath;
        }
 
        /**
@@ -52,42 +56,4 @@ class 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;
-       }
 }