SimpleStringCache.php
32 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Pelago\Emogrifier\Caching; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | class SimpleStringCache |
| 6 | { |
| 7 | private $values = []; |
| 8 | public function has(string $key) : bool |
| 9 | { |
| 10 | $this->assertNotEmptyKey($key); |
| 11 | return isset($this->values[$key]); |
| 12 | } |
| 13 | public function get(string $key) : string |
| 14 | { |
| 15 | if (!$this->has($key)) { |
| 16 | throw new \BadMethodCallException('You can only call `get` with a key for an existing value.', 1625996246); |
| 17 | } |
| 18 | return $this->values[$key]; |
| 19 | } |
| 20 | public function set(string $key, string $value) : void |
| 21 | { |
| 22 | $this->assertNotEmptyKey($key); |
| 23 | $this->values[$key] = $value; |
| 24 | } |
| 25 | private function assertNotEmptyKey(string $key) : void |
| 26 | { |
| 27 | if ($key === '') { |
| 28 | throw new \InvalidArgumentException('Please provide a non-empty key.', 1625995840); |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 |