Version 1
[yaffs-website] / vendor / drupal / console-core / src / functions.php
diff --git a/vendor/drupal/console-core/src/functions.php b/vendor/drupal/console-core/src/functions.php
new file mode 100644 (file)
index 0000000..044a703
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * @param string $path
+ * @return null|string
+ */
+function calculateRealPath($path)
+{
+    if (!$path) {
+        return null;
+    }
+
+    if (realpath($path)) {
+        return $path;
+    }
+
+    return transformToRealPath($path);
+}
+
+/**
+ * @param $path
+ * @return string
+ */
+function transformToRealPath($path)
+{
+    if (strpos($path, '~') === 0) {
+        $home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/');
+        $path = preg_replace('/~/', $home, $path, 1);
+    }
+
+    if (!(strpos($path, '/') === 0)) {
+        $path = sprintf('%s/%s', getcwd(), $path);
+    }
+
+    return realpath($path);
+}