AbstractVault.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Secrets;
  11. /**
  12. * @author Nicolas Grekas <p@tchwork.com>
  13. *
  14. * @internal
  15. */
  16. abstract class AbstractVault
  17. {
  18. protected $lastMessage;
  19. public function getLastMessage(): ?string
  20. {
  21. return $this->lastMessage;
  22. }
  23. abstract public function generateKeys(bool $override = false): bool;
  24. abstract public function seal(string $name, string $value): void;
  25. abstract public function reveal(string $name): ?string;
  26. abstract public function remove(string $name): bool;
  27. abstract public function list(bool $reveal = false): array;
  28. protected function validateName(string $name): void
  29. {
  30. if (!preg_match('/^\w++$/D', $name)) {
  31. throw new \LogicException(sprintf('Invalid secret name "%s": only "word" characters are allowed.', $name));
  32. }
  33. }
  34. protected function getPrettyPath(string $path)
  35. {
  36. return str_replace(getcwd().\DIRECTORY_SEPARATOR, '', $path);
  37. }
  38. }