From bc372ddfe4a790b143c92d48ab7749543929b646 Mon Sep 17 00:00:00 2001
From: Thomas Flori <tflori@pb-systems.de>
Date: Thu, 2 Mar 2017 08:26:33 +0100
Subject: [PATCH 1/3] support for php 7.1 and 7.0

---
 .travis.yml   | 2 ++
 composer.json | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 6c7b0e4..8b4374f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,7 @@
 language: php
 php:
+  - 7.1
+  - 7.0
   - 5.6
   - 5.5
   - 5.4
diff --git a/composer.json b/composer.json
index 8ed9ee8..11778eb 100644
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,7 @@
         "php": ">=5.3.0"
     },
     "require-dev": {
-        "phpunit/phpunit": "3.7.*"
+        "phpunit/phpunit": "^4.8"
     },
     "autoload": {
         "psr-0": {
-- 
GitLab


From f403a9b957d035a94cfc4cab48b77e928c61b190 Mon Sep 17 00:00:00 2001
From: Thomas Flori <tflori@pb-systems.de>
Date: Thu, 2 Mar 2017 08:45:58 +0100
Subject: [PATCH 2/3] use argv[0] for scriptName

We should use $_SERVER['argv'] instead of global $argv - argv is may be not in globals but usually in $_SERVER. When he passes an array (he nows where he got the arguments) but he need to be able to set the scriptName manually.
---
 src/Ulrichsg/Getopt/Getopt.php      | 17 +++++++++++++++--
 test/Ulrichsg/Getopt/GetoptTest.php | 11 +++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/Ulrichsg/Getopt/Getopt.php b/src/Ulrichsg/Getopt/Getopt.php
index bd6b7ad..6d03e34 100644
--- a/src/Ulrichsg/Getopt/Getopt.php
+++ b/src/Ulrichsg/Getopt/Getopt.php
@@ -49,6 +49,16 @@ class Getopt implements \Countable, \ArrayAccess, \IteratorAggregate
         }
     }
 
+    /**
+     * Set the scriptName manually
+     *
+     * @param $scriptName
+     */
+    public function setScriptName($scriptName)
+    {
+        $this->scriptName = $scriptName;
+    }
+
     /**
      * Extends the list of known options. Takes the same argument types as the constructor.
      *
@@ -119,10 +129,13 @@ class Getopt implements \Countable, \ArrayAccess, \IteratorAggregate
      */
     public function parse($arguments = null)
     {
+        if (!$this->scriptName && isset($_SERVER['argv'][0])) {
+            $this->scriptName = $_SERVER['argv'][0];
+        }
+
         $this->options = array();
         if (!isset($arguments)) {
-            global $argv;
-            $arguments = $argv;
+            $arguments = isset($_SERVER['argv']) ? $_SERVER['argv'] : [];
             $this->scriptName = array_shift($arguments); // $argv[0] is the script's name
         } elseif (is_string($arguments)) {
             $this->scriptName = $_SERVER['PHP_SELF'];
diff --git a/test/Ulrichsg/Getopt/GetoptTest.php b/test/Ulrichsg/Getopt/GetoptTest.php
index 0fc13f4..79b05cf 100644
--- a/test/Ulrichsg/Getopt/GetoptTest.php
+++ b/test/Ulrichsg/Getopt/GetoptTest.php
@@ -87,8 +87,7 @@ class GetoptTest extends \PHPUnit_Framework_TestCase
 
     public function testParseUsesGlobalArgvWhenNoneGiven()
     {
-        global $argv;
-        $argv = array('foo.php', '-a');
+        $_SERVER['argv'] = array('foo.php', '-a');
 
         $getopt = new Getopt('a');
         $getopt->parse();
@@ -185,6 +184,14 @@ class GetoptTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($expected, $getopt->getHelpText());
     }
 
+    public function testHelpTextWithCustomScriptName()
+    {
+        $getopt = new Getopt();
+        $getopt->setScriptName('test');
+        $expected = "Usage: test [options] [operands]\nOptions:\n";
+        $this->assertSame($expected, $getopt->getHelpText());
+    }
+
     public function testHelpTextWithCustomBanner()
     {
         $script = $_SERVER['PHP_SELF'];
-- 
GitLab


From 0612213c7cc798d202a29f6bc88208bf91cebd90 Mon Sep 17 00:00:00 2001
From: Thomas Flori <tflori@pb-systems.de>
Date: Thu, 2 Mar 2017 09:44:53 +0100
Subject: [PATCH 3/3] change to traditional array style for php5.3

---
 src/Ulrichsg/Getopt/Getopt.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Ulrichsg/Getopt/Getopt.php b/src/Ulrichsg/Getopt/Getopt.php
index 6d03e34..31fac1a 100644
--- a/src/Ulrichsg/Getopt/Getopt.php
+++ b/src/Ulrichsg/Getopt/Getopt.php
@@ -135,7 +135,7 @@ class Getopt implements \Countable, \ArrayAccess, \IteratorAggregate
 
         $this->options = array();
         if (!isset($arguments)) {
-            $arguments = isset($_SERVER['argv']) ? $_SERVER['argv'] : [];
+            $arguments = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
             $this->scriptName = array_shift($arguments); // $argv[0] is the script's name
         } elseif (is_string($arguments)) {
             $this->scriptName = $_SERVER['PHP_SELF'];
-- 
GitLab