work around PHP bug #68347: parse ini files in raw mode
[phorkie.git] / src / phorkie / Repository / ConnectionInfo.php
index 3815856a8444d62449e72828adfc3d53fd04fe3f..501f7d0434963b405b90d2028713456d451bd108 100644 (file)
@@ -10,7 +10,10 @@ class Repository_ConnectionInfo
     public function __construct(Repository $repo)
     {
         $this->repo = $repo;
-        $this->arConfig = parse_ini_file($this->repo->gitDir . '/config', true);
+        //we need raw parsing; https://bugs.php.net/bug.php?id=68347
+        $this->arConfig = parse_ini_file(
+            $this->repo->gitDir . '/config', true, INI_SCANNER_RAW
+        );
     }
 
     public function isFork()
@@ -18,6 +21,11 @@ class Repository_ConnectionInfo
         return $this->getOrigin() !== null;
     }
 
+    public function hasForks()
+    {
+        return count($this->getForks()) > 0;
+    }
+
 
     public function getOrigin()
     {
@@ -36,7 +44,18 @@ class Repository_ConnectionInfo
         return new Repository_Remote($name, $this->arConfig['remote ' . $name]);
     }
 
+    public function getForks()
+    {
+        $arForks = array();
+        foreach ($this->arConfig as $name => $data) {
+            if (substr($name, 0, 12) != 'remote fork-') {
+                continue;
+            }
+            $arForks[substr($name, 7)] = new Repository_Remote(
+                substr($name, 7), $data
+            );
+        }
+        return $arForks;
+    }
 }
-
-
 ?>