Exakat\Config::readCommandline PHP Method

readCommandline() private method

private readCommandline ( )
    private function readCommandline()
    {
        $args = $this->argv;
        unset($args[0]);
        if (empty($args)) {
            return array();
        }
        foreach (static::$BOOLEAN_OPTIONS as $key => $config) {
            $id = array_search($key, $args);
            if ($id !== false) {
                $this->commandline[$config] = true;
                unset($args[$id]);
            }
        }
        // git is default, so it should be unset if another is set
        $this->commandline['git'] = (bool) (true ^ (isset($this->commandline['svn']) && $this->commandline['svn'] || isset($this->commandline['hg']) && $this->commandline['hg'] || isset($this->commandline['bzr']) && $this->commandline['bzr'] || isset($this->commandline['composer']) && $this->commandline['composer'] || isset($this->commandline['tgz']) && $this->commandline['tgz'] || isset($this->commandline['tbz']) && $this->commandline['tbz'] || isset($this->commandline['zip']) && $this->commandline['zip'] || isset($this->commandline['copy']) && $this->commandline['copy'] || isset($this->commandline['symlink']) && $this->commandline['symlink']));
        $optionsValue = array('-f' => 'filename', '-d' => 'dirname', '-p' => 'project', '-P' => 'program', '-R' => 'repository', '-T' => 'thema', '-report' => 'report', '-format' => 'format', '-file' => 'file', '-style' => 'style', '-neo4j_host' => 'neo4j_host', '-neo4j_port' => 'neo4j_port', '-neo4j_folder' => 'neo4j_folder', '-token_limit' => 1000000);
        foreach ($optionsValue as $key => $config) {
            $id = array_search($key, $args);
            if ($id !== false) {
                if (isset($args[$id + 1])) {
                    if (isset($optionsValue[$args[$id + 1]])) {
                        // in case this option value is actually the next option (exakat -p -T)
                        // We just ignore it
                        unset($args[$id]);
                    } else {
                        // Normal case is here
                        $this->commandline[$config] = $args[$id + 1];
                        unset($args[$id]);
                        unset($args[$id + 1]);
                    }
                }
            }
        }
        if (count($args) > 0) {
            $arg = array_shift($args);
            if (null !== @static::$COMMANDS[$arg]) {
                $this->commandline['command'] = $arg;
            } else {
                array_unshift($args, $arg);
                $this->commandline['command'] = 'version';
            }
        }
        if (count($args) != 0) {
            $c = count($args);
            if (isset($this->commandline['verbose'])) {
                print 'Found ' . $c . ' argument' . ($c > 1 ? 's' : '') . ' that ' . ($c > 1 ? 'are' : 'is') . " not understood.\n\n\"" . implode('", "', $args) . "\"\n\nIgnoring " . ($c > 1 ? 'them all' : 'it' . ".\n");
            }
        }
        if (!isset($this->commandline['command'])) {
            $this->commandline['command'] = 'help';
            // Default behavior
        }
        // Special case for onepage command. It will only work on 'onepage' project
        if ($this->commandline['command'] == 'onepage') {
            $this->commandline['project'] = 'onepage';
            $this->commandline['thema'] = 'OneFile';
            $this->commandline['format'] = 'OnepageJson';
            $this->commandline['file'] = 'onepage';
            $this->commandline['norefresh'] = true;
        }
    }