From 38b327f23678602120fb96f9ece4523a5642fa69 Mon Sep 17 00:00:00 2001
From: Safwan Khan <safwkhan@ebay.com>
Date: Tue, 28 Apr 2015 11:06:55 -0500
Subject: [PATCH] MAGETWO-36034: Environment variables are messed up for
 different entry points

- Removed the class as it is not being used by anyone any more.
---
 .../Test/Legacy/_files/obsolete_classes.php   |   1 +
 .../Magento/Framework/App/AbstractShell.php   | 190 ------------------
 .../App/Test/Unit/AbstractShellTest.php       |  75 -------
 3 files changed, 1 insertion(+), 265 deletions(-)
 delete mode 100644 lib/internal/Magento/Framework/App/AbstractShell.php
 delete mode 100644 lib/internal/Magento/Framework/App/Test/Unit/AbstractShellTest.php

diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
index b843bebb849..59cf16d2456 100755
--- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
+++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
@@ -3333,4 +3333,5 @@ return [
     ['Magento\Log\Model\Shell\Command\Status'],
     ['Magento\Log\Model\LogFactory\Clean'],
     ['Magento\Log\Model\Shell\CommandInterface'],
+    ['Magento\Framework\App\Filesystem\DirectoryList\AbstractShell'],
 ];
diff --git a/lib/internal/Magento/Framework/App/AbstractShell.php b/lib/internal/Magento/Framework/App/AbstractShell.php
deleted file mode 100644
index ce24586bb7c..00000000000
--- a/lib/internal/Magento/Framework/App/AbstractShell.php
+++ /dev/null
@@ -1,190 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\Framework\App;
-
-use Magento\Framework\App\Filesystem\DirectoryList;
-
-/**
- * Shell scripts abstract class
- */
-abstract class AbstractShell
-{
-    /**
-     * Raw arguments, that should be parsed
-     *
-     * @var string[]
-     */
-    protected $_rawArgs = [];
-
-    /**
-     * Parsed input arguments
-     *
-     * @var array
-     */
-    protected $_args = [];
-
-    /**
-     * Entry point - script filename that is executed
-     *
-     * @var string
-     */
-    protected $_entryPoint = null;
-
-    /**
-     * @var \Magento\Framework\Filesystem\Directory\ReadInterface
-     */
-    protected $rootDirectory;
-
-    /**
-     * Initializes application and parses input parameters
-     *
-     * @param \Magento\Framework\Filesystem $filesystem
-     * @param string $entryPoint
-     * @throws \Exception
-     */
-    public function __construct(\Magento\Framework\Filesystem $filesystem, $entryPoint)
-    {
-        if (isset($_SERVER['REQUEST_METHOD'])) {
-            throw new \Exception('This script cannot be run from Browser. This is the shell script.');
-        }
-
-        $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
-        $this->_entryPoint = $entryPoint;
-        $this->_rawArgs = $_SERVER['argv'];
-        $this->_applyPhpVariables();
-        $this->_parseArgs();
-    }
-
-    /**
-     * Sets raw arguments to be parsed
-     *
-     * @param string[] $args
-     * @return $this
-     */
-    public function setRawArgs($args)
-    {
-        $this->_rawArgs = $args;
-        $this->_parseArgs();
-        return $this;
-    }
-
-    /**
-     * Parses .htaccess file and apply php settings to shell script
-     *
-     * @return $this
-     */
-    protected function _applyPhpVariables()
-    {
-        $htaccess = '.htaccess';
-        if ($this->rootDirectory->isFile($htaccess)) {
-            // parse htaccess file
-            $data = $this->rootDirectory->readFile($htaccess);
-            $matches = [];
-            preg_match_all('#^\s+?php_value\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
-            if ($matches) {
-                foreach ($matches as $match) {
-                    @ini_set($match[1], str_replace("\r", '', $match[2]));
-                }
-            }
-            preg_match_all('#^\s+?php_flag\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
-            if ($matches) {
-                foreach ($matches as $match) {
-                    @ini_set($match[1], str_replace("\r", '', $match[2]));
-                }
-            }
-        }
-        return $this;
-    }
-
-    /**
-     * Parses input arguments
-     *
-     * @return $this
-     */
-    protected function _parseArgs()
-    {
-        $current = null;
-        foreach ($this->_rawArgs as $arg) {
-            $match = [];
-            if (preg_match(
-                '#^--([\w\d_-]{1,})(=(.*))?$#',
-                $arg,
-                $match
-            ) || preg_match(
-                '#^-([\w\d_]{1,})$#',
-                $arg,
-                $match
-            )
-            ) {
-                if (isset($match[3])) {
-                    $this->_args[$match[1]] = $match[3];
-                    $current = null;
-                } else {
-                    $current = $match[1];
-                    $this->_args[$current] = true;
-                }
-            } else {
-                if ($current) {
-                    $this->_args[$current] = $arg;
-                    $current = null;
-                } elseif (preg_match('#^([\w\d_]{1,})$#', $arg, $match)) {
-                    $this->_args[$match[1]] = true;
-                }
-            }
-        }
-        return $this;
-    }
-
-    /**
-     * Runs script
-     *
-     * @return $this
-     */
-    abstract public function run();
-
-    /**
-     * Shows usage help, if requested
-     *
-     * @return bool
-     */
-    protected function _showHelp()
-    {
-        if (isset($this->_args['h']) || isset($this->_args['help'])) {
-            echo $this->getUsageHelp();
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Retrieves usage help message
-     *
-     * @return string
-     */
-    public function getUsageHelp()
-    {
-        return <<<USAGE
-Usage:  php -f {$this->_entryPoint} -- [options]
-
-  -h            Short alias for help
-  help          This help
-USAGE;
-    }
-
-    /**
-     * Retrieves argument value by name. If argument is not found - returns FALSE.
-     *
-     * @param string $name the argument name
-     * @return mixed
-     */
-    public function getArg($name)
-    {
-        if (isset($this->_args[$name])) {
-            return $this->_args[$name];
-        }
-        return false;
-    }
-}
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/AbstractShellTest.php b/lib/internal/Magento/Framework/App/Test/Unit/AbstractShellTest.php
deleted file mode 100644
index 07c320180d3..00000000000
--- a/lib/internal/Magento/Framework/App/Test/Unit/AbstractShellTest.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-/**
- * Copyright © 2015 Magento. All rights reserved.
- * See COPYING.txt for license details.
- */
-namespace Magento\Framework\App\Test\Unit;
-
-class AbstractShellTest extends \PHPUnit_Framework_TestCase
-{
-    /**
-     * @var \Magento\Framework\App\AbstractShell | \PHPUnit_Framework_MockObject_MockObject
-     */
-    protected $_model;
-
-    protected function setUp()
-    {
-        $this->_model = $this->getMockBuilder(
-            '\Magento\Framework\App\AbstractShell'
-        )->disableOriginalConstructor()->setMethods(
-            ['_applyPhpVariables']
-        )->getMockForAbstractClass();
-    }
-
-    protected function tearDown()
-    {
-        unset($this->_model);
-    }
-
-    /**
-     * @param array $arguments
-     * @param string $argName
-     * @param string $expectedValue
-     *
-     * @dataProvider setGetArgDataProvider
-     */
-    public function testSetGetArg($arguments, $argName, $expectedValue)
-    {
-        $this->_model->setRawArgs($arguments);
-        $this->assertEquals($this->_model->getArg($argName), $expectedValue);
-    }
-
-    /**
-     * @return array
-     */
-    public function setGetArgDataProvider()
-    {
-        return [
-            'argument with no value' => [
-                'arguments' => ['argument', 'argument2'],
-                'argName' => 'argument',
-                'expectedValue' => true,
-            ],
-            'dashed argument with value' => [
-                'arguments' => ['-argument', 'value'],
-                'argName' => 'argument',
-                'expectedValue' => 'value',
-            ],
-            'double-dashed argument with separate value' => [
-                'arguments' => ['--argument-name', 'value'],
-                'argName' => 'argument-name',
-                'expectedValue' => 'value',
-            ],
-            'double-dashed argument with included value' => [
-                'arguments' => ['--argument-name=value'],
-                'argName' => 'argument-name',
-                'expectedValue' => 'value',
-            ],
-            'argument with value, then single argument with no value' => [
-                'arguments' => ['-argument', 'value', 'argument2'],
-                'argName' => 'argument',
-                'expectedValue' => 'value',
-            ]
-        ];
-    }
-}
-- 
GitLab