Exemplo n.º 1
0
 /**
  * Execute
  *
  * @return void
  */
 public function execute()
 {
     if ($this->_args->verbose) {
         $this->logger->setVerbose(true);
     }
     $action = $this->_args->action ? $this->_args->action : "help";
     if ($this->_args->help || $this->_args->h || $action == 'help') {
         $this->displayHelp();
         return self::STATUS_SUCCESS;
     }
     if ($this->_args->version || $action == 'version') {
         print Version::renderVersion();
         return self::STATUS_SUCCESS;
     }
     $this->logger->info("Current path: " . getcwd());
     $configFileOverride = false;
     if ($this->_args->conf) {
         $this->_configFilename = $this->_args->conf;
         // If a specified file fails, we want to bail since there are
         // destructive commands run (rm -rf) on paths that the user may not
         // have intended with a custom config file
         $configFileOverride = true;
     }
     switch ($action) {
         case 'init':
             $this->logger->notice("Initializing environment for Holograph");
             $this->writeConfig();
             break;
         case 'config':
             $this->showConfig();
             break;
         case 'build':
             $config = $this->readConfigFile($this->_configFilename, $configFileOverride);
             if ($this->_args->compat) {
                 $config['compatMode'] = $this->_args->compat;
             }
             $builder = new Builder($config, $this->logger);
             try {
                 $builder->execute();
             } catch (\Exception $exception) {
                 $this->_halt($exception->getMessage());
             }
             break;
         case 'live':
             $config = $this->readConfigFile($this->_configFilename, $configFileOverride);
             $autoloadPath = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
             if (!file_exists($autoloadPath . 'vendor/autoload.php')) {
                 $autoloadPath = dirname(dirname(dirname(dirname($autoloadPath))));
             }
             $indexContents = "<?php\n";
             $indexContents .= sprintf("/* Holograph Live\nGenerated %s\n*/\n", date("Y-m-d H:i:s"));
             $indexContents .= sprintf("require_once '%s/vendor/autoload.php';\n", $autoloadPath);
             $indexContents .= "\$contents = \\Holograph\\Live::reload(\$_SERVER['REQUEST_URI']);\n";
             $indexContents .= "print \$contents;\n";
             $fileio = new FileOps();
             $fileio->writeFile($config['destination'] . DIRECTORY_SEPARATOR . "index.php", $indexContents);
             $serverCmd = 'php -S localhost:8000 -t ' . $config['destination'];
             $this->logger->info($serverCmd);
             passthru($serverCmd);
             break;
         default:
             $this->logger->warning("Unrecognized action '{$action}'");
             $this->_status = self::STATUS_ERROR;
             break;
     }
     return $this->_status;
 }