Beispiel #1
0
 /**
  * Runns a Magallanes Command
  * @throws Exception
  */
 public function run($arguments)
 {
     $exitCode = 10;
     // Declare a Shutdown Closure
     register_shutdown_function(function () {
         // Only Unlock if there was an error
         if (error_get_last() !== null) {
             if (file_exists(getcwd() . '/.mage/~working.lock')) {
                 unlink(getcwd() . '/.mage/~working.lock');
             }
         }
     });
     $config = self::$config = new Config();
     $configError = false;
     try {
         // Load configuration
         $config->load($arguments);
     } catch (Exception $exception) {
         $configError = $exception->getMessage();
     }
     // Command Option
     $commandName = $config->getArgument(0);
     // Logging
     $showGreetings = true;
     if (in_array($commandName, self::$paramsNotRequiringEnvironment)) {
         self::$logEnabled = false;
         $showGreetings = false;
     } else {
         self::$logEnabled = $config->general('logging', false);
     }
     self::$verboseLogEnabled = self::isVerboseLoggingEnabled();
     // Greetings
     if ($showGreetings) {
         if (!self::$logEnabled) {
             self::output('Starting <blue>Magallanes</blue>', 0, 2);
         } else {
             self::output('Starting <blue>Magallanes</blue>', 0, 1);
             self::log("Logging enabled");
             self::output('<bold>Logging enabled:</bold> <purple>' . self::getLogFile() . '</purple>', 1, 2);
         }
     }
     $error = false;
     // Run Command - Check if there is a Configuration Error
     if ($configError !== false) {
         self::output('<red>' . $configError . '</red>', 1, 2);
     } else {
         // Run Command and check for Command Requirements
         try {
             $command = Factory::get($commandName, $config);
             if ($command instanceof RequiresEnvironment) {
                 if ($config->getEnvironment() === false) {
                     throw new Exception('You must specify an environment for this command.');
                 }
             }
             // Run the Command
             $exitCode = $command->run();
             // Check for errors
             if (is_int($exitCode) && $exitCode !== 0) {
                 throw new Exception('Command execution failed with following exit code: ' . $exitCode, $exitCode);
             } elseif (is_bool($exitCode) && !$exitCode) {
                 $exitCode = 1;
                 throw new Exception('Command execution failed.', $exitCode);
             }
         } catch (Exception $exception) {
             $error = true;
             self::output('<red>' . $exception->getMessage() . '</red>', 1, 2);
         }
     }
     if ($showGreetings) {
         self::output('Finished <blue>Magallanes</blue>', 0, 2);
         if ($error && $config->general('outputLogOnError', false)) {
             self::$logEnabled = false;
             //disabling log to avoid loop
             self::output('Full log:', 0, 2);
             $file = new \SplFileObject(self::$logFile, 'r');
             while (!$file->eof()) {
                 self::output($file->fgets(), 1, 0);
             }
             $file = null;
         }
         if (file_exists(getcwd() . '/.mage/~working.lock')) {
             unlink(getcwd() . '/.mage/~working.lock');
         }
     }
     // Check if logs need to be deleted
     self::checkLogs($config);
     return $exitCode;
 }
Beispiel #2
0
 /**
  * Runns a Magallanes Command
  * @throws Exception
  */
 public function run($arguments)
 {
     $exitCode = 10;
     // Declare a Shutdown Closure
     register_shutdown_function(function () {
         // Only Unlock if there was an error
         if (error_get_last() !== null) {
             if (file_exists(getcwd() . '/.mage/~working.lock')) {
                 unlink(getcwd() . '/.mage/~working.lock');
             }
         }
     });
     $config = self::$config = new Config();
     $configError = false;
     try {
         // Load configuration
         $config->load($arguments);
     } catch (Exception $exception) {
         $configError = $exception->getMessage();
     }
     // Command Option
     $commandName = $config->getArgument(0);
     // Logging
     $showGreetings = true;
     if (in_array($commandName, self::$paramsNotRequiringEnvironment)) {
         self::$logEnabled = false;
         $showGreetings = false;
     } else {
         self::$logEnabled = $config->general('logging', false);
     }
     // Greetings
     if ($showGreetings) {
         if (!self::$logEnabled) {
             self::output('Starting <blue>Magallanes</blue>', 0, 2);
         } else {
             self::output('Starting <blue>Magallanes</blue>', 0, 1);
             self::log("Logging enabled");
             self::output('<dark_gray>Logging enabled:</dark_gray> <purple>' . self::getLogFile() . '</purple>', 1, 2);
         }
     }
     // Run Command - Check if there is a Configuration Error
     if ($configError !== false) {
         self::output('<red>' . $configError . '</red>', 1, 2);
     } else {
         // Run Command and check for Command Requirements
         try {
             $command = Factory::get($commandName, $config);
             if ($command instanceof RequiresEnvironment) {
                 if ($config->getEnvironment() == false) {
                     throw new Exception('You must specify an environment for this command.');
                 }
             }
             $exitCode = $command->run();
         } catch (Exception $exception) {
             self::output('<red>' . $exception->getMessage() . '</red>', 1, 2);
         }
     }
     if ($showGreetings) {
         self::output('Finished <blue>Magallanes</blue>', 0, 2);
         if (file_exists(getcwd() . '/.mage/~working.lock')) {
             unlink(getcwd() . '/.mage/~working.lock');
         }
     }
     // Check if logs need to be deleted
     self::checkLogs($config);
     return $exitCode;
 }
Beispiel #3
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage The command MyInconsistentCommand must be an instance of Mage\Command\AbstractCommand.
  */
 public function testGetInconsistencyException()
 {
     $this->getMock('Command\\MyInconsistentCommand');
     $command = Factory::get('my-inconsistent-command', $this->config);
 }