Exemple #1
0
 /**
  * Decrypt the given output.
  *
  * @param OutputContract     $input
  * @param OutputContract     $output
  * @param SyncOutputContract $console
  */
 public function decrypt(OutputContract $input, OutputContract $output, SyncOutputContract $console = null)
 {
     $files = $input->listContents('', true);
     if ($console) {
         $console->setTotal(count($files));
     }
     foreach ($files as $file) {
         if ($file['type'] == 'dir') {
             if ($console) {
                 $console->out(SyncOutput::ENC_ENCRYPT_FILE, ['file' => $file['path']]);
             }
             continue;
         }
         try {
             $fileContents = $this->crypto->decrypt($input->read($file['path']), $this->key);
             if ($output->has($file['path'])) {
                 $output->update($file['path'], $fileContents);
             } else {
                 $output->write($file['path'], $fileContents);
             }
             unset($fileContents);
             if ($console) {
                 $console->out(SyncOutput::ENC_DECRYPT_FILE, ['file' => $file['path']]);
             }
         } catch (GeneralSecurityException $e) {
             if ($console) {
                 $console->out(SyncOutput::ENC_DECRYPT_FILE, ['file' => $file['path'], 'output' => $e]);
             }
         }
     }
 }
Exemple #2
0
 /**
  * Outputs something to the console.
  *
  * @param string $name
  * @param array  $data
  *
  * @return string
  */
 protected function out($name, $data = [])
 {
     return $this->outputHelper->out($name, $data);
 }
Exemple #3
0
 /**
  * Commit.
  *
  * @param $output
  */
 protected function commit(SyncOutputContract $output)
 {
     if ($this->git->hasChanges()) {
         $commit = $this->git->commit();
         // Display the output
         if (isset($commit['name']) && isset($commit['data'])) {
             $output->out($commit['name'], $commit['data']);
         }
     }
     // Free some RAM
     unset($commit);
 }