Beispiel #1
0
    /**
     * @param	string							$name				Application name
     * @param	string							$version
     * @param	string							$phpMinimumVersion
     * @param	Huxtable\Core\File\Directory	$dirApp
     * @param	Huxtable\CLI\Input				$input
     */
    public function __construct($name, $version, $phpMinimumVersion = null, File\Directory $dirApp, Input $input = null)
    {
        if (!is_null($phpMinimumVersion)) {
            if (version_compare(PHP_VERSION, $phpMinimumVersion, '>=') == false) {
                $this->exit = 1;
                $this->output = "{$name}: Requires PHP {$phpMinimumVersion}+, found " . PHP_VERSION . PHP_EOL;
                $this->stop();
            }
        }
        $this->name = $name;
        $this->version = $version;
        $this->input = is_null($input) ? new Input() : $input;
        /* Application root directory */
        $this->dirApp = $dirApp;
        /* Helper function, which has probably never been used */
        if ($this->userDir instanceof File\Directory) {
            if (!$this->userDir->exists()) {
                $this->userDir->mkdir();
            }
        }
        /* Register default commands */
        $help = new Command('help', "Display help information about {$this->name}", [$this, 'commandHelp']);
        $help->setUsage('help <command>');
        $this->registerCommand($help);
        if (isset($this->projectPath) && isset($this->remoteConfigURL)) {
            $upgrade = new \Huxtable\Command('upgrade', "Fetch the newest version of {$this->name}", [$this, 'commandUpgrade']);
            $upgrade->registerOption('verbose');
            $upgradeUsage = <<<USAGE
upgrade [options]

OPTIONS
     --verbose
         be verbose


USAGE;
            $upgrade->setUsage($upgradeUsage);
            $this->registerCommand($upgrade);
        }
        /* Cookie Controller */
        $fileCookies = $this->dirApp->child('.cookies');
        $this->cookies = new Cookie($fileCookies);
    }