vendor/symfony/framework-bundle/Command/SecretsEncryptFromLocalCommand.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\Command;
  11. use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. use Symfony\Component\Console\Style\SymfonyStyle;
  17. /**
  18.  * @author Nicolas Grekas <p@tchwork.com>
  19.  *
  20.  * @internal
  21.  */
  22. final class SecretsEncryptFromLocalCommand extends Command
  23. {
  24.     protected static $defaultName 'secrets:encrypt-from-local';
  25.     protected static $defaultDescription 'Encrypt all local secrets to the vault';
  26.     private $vault;
  27.     private $localVault;
  28.     public function __construct(AbstractVault $vaultAbstractVault $localVault null)
  29.     {
  30.         $this->vault $vault;
  31.         $this->localVault $localVault;
  32.         parent::__construct();
  33.     }
  34.     protected function configure()
  35.     {
  36.         $this
  37.             ->setDescription(self::$defaultDescription)
  38.             ->setHelp(<<<'EOF'
  39. The <info>%command.name%</info> command encrypts all locally overridden secrets to the vault.
  40.     <info>%command.full_name%</info>
  41. EOF
  42.             )
  43.         ;
  44.     }
  45.     protected function execute(InputInterface $inputOutputInterface $output): int
  46.     {
  47.         $io = new SymfonyStyle($input$output instanceof ConsoleOutputInterface $output->getErrorOutput() : $output);
  48.         if (null === $this->localVault) {
  49.             $io->error('The local vault is disabled.');
  50.             return 1;
  51.         }
  52.         foreach ($this->vault->list(true) as $name => $value) {
  53.             $localValue $this->localVault->reveal($name);
  54.             if (null !== $localValue && $value !== $localValue) {
  55.                 $this->vault->seal($name$localValue);
  56.             } elseif (null !== $message $this->localVault->getLastMessage()) {
  57.                 $io->error($message);
  58.                 return 1;
  59.             }
  60.         }
  61.         return 0;
  62.     }
  63. }