Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Ddeboer\Imap\Search; |
| 6 | |
| 7 | /** |
| 8 | * Represents a text based condition. Text based conditions use a contains |
| 9 | * restriction. |
| 10 | */ |
| 11 | abstract class AbstractText implements ConditionInterface |
| 12 | { |
| 13 | /** |
| 14 | * Text to be used for the condition. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | private $text; |
| 19 | |
| 20 | /** |
| 21 | * Constructor. |
| 22 | * |
| 23 | * @param string $text optional text for the condition |
| 24 | */ |
| 25 | public function __construct(string $text) |
| 26 | { |
| 27 | $this->text = $text; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Converts the condition to a string that can be sent to the IMAP server. |
| 32 | */ |
| 33 | final public function toString(): string |
| 34 | { |
| 35 | return \sprintf('%s "%s"', $this->getKeyword(), $this->text); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns the keyword that the condition represents. |
| 40 | */ |
| 41 | abstract protected function getKeyword(): string; |
| 42 | } |