Cli::getCommandLineOptions PHP Method

getCommandLineOptions() protected method

Process the command line options
protected getCommandLineOptions ( ) : array
return array
    protected function getCommandLineOptions()
    {
        $argv = $this->getArguments();
        $arguments = array();
        foreach ($argv as $k => $arg) {
            $short = false;
            $long = substr($arg, 0, 2) == '--' ? true : false;
            if ($long) {
                $trim = 2;
            } else {
                $short = substr($arg, 0, 1) == '-' ? true : false;
                $trim = 1;
            }
            if ($short || $long) {
                $arg = substr($arg, $trim);
                if (!isset($arguments[$arg]) || !is_array($arguments[$arg])) {
                    $arguments[$arg] = array('default' => true, 'values' => null);
                }
                $key = $arg;
            } else {
                if (!$arguments[$key]['values']) {
                    $arguments[$key]['values'] = array();
                }
                $map = array('true' => true, 'false' => false);
                if (isset($map[$arg])) {
                    $arg = $map[$arg];
                }
                $arguments[$key]['values'][] = $arg;
            }
        }
        foreach ($arguments as $k => $arg) {
            $arguments[$k] = $arg['default'];
            if (is_array($arg['values'])) {
                if (count($arg['values']) == 1) {
                    $arguments[$k] = $arg['values'][0];
                } else {
                    $arguments[$k] = $arg['values'];
                }
            }
        }
        return $arguments;
    }