]> git.mxchange.org Git - friendica.git/blob - src/Util/BasePath.php
Merge pull request #6601 from annando/false-notifications
[friendica.git] / src / Util / BasePath.php
1 <?php
2
3 namespace Friendica\Util;
4
5 class BasePath
6 {
7         /**
8          * @brief Returns the base filesystem path of the App
9          *
10          * It first checks for the internal variable, then for DOCUMENT_ROOT and
11          * finally for PWD
12          *
13          * @param string|null $basePath The default base path
14          * @param array       $server   server arguments
15          *
16          * @return string
17          *
18          * @throws \Exception if directory isn't usable
19          */
20         public static function create($basePath, $server = [])
21         {
22                 if (!$basePath && !empty($server['DOCUMENT_ROOT'])) {
23                         $basePath = $server['DOCUMENT_ROOT'];
24                 }
25
26                 if (!$basePath && !empty($server['PWD'])) {
27                         $basePath = $server['PWD'];
28                 }
29
30                 return self::getRealPath($basePath);
31         }
32
33         /**
34          * @brief Returns a normalized file path
35          *
36          * This is a wrapper for the "realpath" function.
37          * That function cannot detect the real path when some folders aren't readable.
38          * Since this could happen with some hosters we need to handle this.
39          *
40          * @param string $path The path that is about to be normalized
41          * @return string normalized path - when possible
42          */
43         public static function getRealPath($path)
44         {
45                 $normalized = realpath($path);
46
47                 if (!is_bool($normalized)) {
48                         return $normalized;
49                 } else {
50                         return $path;
51                 }
52         }
53 }