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. |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 15 | */ |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 16 | private string $text; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Constructor. |
| 20 | * |
| 21 | * @param string $text optional text for the condition |
| 22 | */ |
| 23 | public function __construct(string $text) |
| 24 | { |
| 25 | $this->text = $text; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Converts the condition to a string that can be sent to the IMAP server. |
| 30 | */ |
| 31 | final public function toString(): string |
| 32 | { |
| 33 | return \sprintf('%s "%s"', $this->getKeyword(), $this->text); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the keyword that the condition represents. |
| 38 | */ |
| 39 | abstract protected function getKeyword(): string; |
| 40 | } |