blob: 69b251668a83ee1a7f643f9ed29f90fcc6f291e8 [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.
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}