LockedCommandConfig.php 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\CLI\Command\Util;
  4. final class LockedCommandConfig
  5. {
  6. public const DEFAULT_TTL = 600.0; // 10 minutes
  7. private string $lockName;
  8. private bool $isBlocking;
  9. private float $ttl;
  10. private function __construct(string $lockName, bool $isBlocking, float $ttl = self::DEFAULT_TTL)
  11. {
  12. $this->lockName = $lockName;
  13. $this->isBlocking = $isBlocking;
  14. $this->ttl = $ttl;
  15. }
  16. public static function blocking(string $lockName): self
  17. {
  18. return new self($lockName, true);
  19. }
  20. public static function nonBlocking(string $lockName): self
  21. {
  22. return new self($lockName, false);
  23. }
  24. public function lockName(): string
  25. {
  26. return $this->lockName;
  27. }
  28. public function isBlocking(): bool
  29. {
  30. return $this->isBlocking;
  31. }
  32. public function ttl(): float
  33. {
  34. return $this->ttl;
  35. }
  36. }