blob: 8b605ce2242418d8f6f82b3f5ee24c1124403c9d [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2
3declare(strict_types=1);
4
5namespace Ddeboer\Imap\Search;
6
7/**
8 * Represents a text based condition. Text based conditions use a contains
9 * restriction.
10 */
11abstract class AbstractText implements ConditionInterface
12{
13 /**
14 * Text to be used for the condition.
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010015 */
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020016 private string $text;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010017
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}