Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console-core / src / functions.php
1 <?php
2
3 /**
4  * @param string $path
5  * @return null|string
6  */
7 function calculateRealPath($path)
8 {
9     if (!$path) {
10         return null;
11     }
12
13     if (realpath($path)) {
14         return $path;
15     }
16
17     return transformToRealPath($path);
18 }
19
20 /**
21  * @param $path
22  * @return string
23  */
24 function transformToRealPath($path)
25 {
26     if (strpos($path, '~') === 0) {
27         $home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/');
28         $path = preg_replace('/~/', $home, $path, 1);
29     }
30
31     if (!(strpos($path, '/') === 0)) {
32         $path = sprintf('%s/%s', getcwd(), $path);
33     }
34
35     return realpath($path);
36 }