Example #1
0
 /**
  * @param Config $config
  */
 public function run(Config $config)
 {
     // Create logger
     $logFile = $config->getLogFile();
     $this->logger = $logFile ? new Logger($logFile) : new StdOutLogger();
     $this->logger->useColors = $config->useColors();
     // Create temp dir
     if (!is_dir($tempDir = $config->getTempDir())) {
         $this->logger->log("Creating temporary directory {$tempDir}");
         @mkdir($tempDir, 0777, TRUE);
     }
     // Start time
     $time = time();
     $this->logger->log("Started at " . date('[Y/m/d H:i]'));
     // Get sections and get sections names
     $sections = $config->getSections();
     $sectionNames = array_map(function (Section $s) {
         return $s->getName();
     }, $sections);
     // Show info
     $this->logger->log(sprintf('Found sections: %d (%s)', count($sectionNames), implode(',', $sectionNames)));
     // Process all sections
     foreach ($sections as $section) {
         // Show info
         $this->logger->log("\nDeploying section [{$section->getName()}]");
         // Create deployer
         $deployment = $this->createDeployer($config, $section);
         $deployment->tempDir = $tempDir;
         // Detect mode -> generate
         if ($config->getMode() === 'generate') {
             $this->logger->log('Scanning files');
             $localFiles = $deployment->collectPaths();
             $this->logger->log("Saved " . $deployment->writeDeploymentFile($localFiles));
             continue;
         }
         // Show info
         if ($deployment->testMode) {
             $this->logger->log('Test mode');
         } else {
             $this->logger->log('Live mode');
         }
         if (!$deployment->allowDelete) {
             $this->logger->log('Deleting disabled');
         }
         // Deploy
         $deployment->deploy();
     }
     // Show elapsed time
     $time = time() - $time;
     $this->logger->log("\nFinished at " . date('[Y/m/d H:i]') . " (in {$time} seconds)", 'lime');
 }
 /**
  * @param Config $config
  * @param Section $section
  * @param Server $server
  * @param Logger $logger
  * @param Deployer $deployer
  * @return bool
  */
 private function load(Config $config, Section $section, Server $server, Logger $logger, Deployer $deployer)
 {
     $this->server = $server;
     $this->logger = $logger;
     $plugins = $config->getPlugins();
     $this->plugin = isset($plugins[self::PLUGIN]) ? $plugins[self::PLUGIN] : NULL;
     $this->pluginName = ucfirst(self::PLUGIN);
     // Has plugin filled config?
     if (!$this->plugin) {
         $logger->log("{$this->pluginName}: please fill config", 'red');
         return FALSE;
     }
     try {
         // Validate plugin config
         Helpers::validateConfig($this->defaults, $this->plugin, self::PLUGIN);
     } catch (InvalidStateException $ex) {
         $logger->log(sprintf("%s: bad configuration (%s)", $this->pluginName, $ex->getMessage()), 'red');
         return FALSE;
     }
     return TRUE;
 }