-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBaseTemplate.php
105 lines (91 loc) · 2.19 KB
/
BaseTemplate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Tamtamchik\SimpleFlash;
use Tamtamchik\SimpleFlash\Exceptions\FlashTemplateException;
/**
* Class BaseTemplate.
*
* @property string prefix - line prefix
* @property string postfix - line postfix
* @property string wrapper - flash wrapper
*/
abstract class BaseTemplate implements TemplateInterface
{
/**
* @param string $messages - message text
* @param string $type - message type: success, info, warning, error
*
* @return string
*/
abstract public function wrapMessages(string $messages, string $type): string;
/**
* @param string $message - message text
*
* @return string
*/
public function wrapMessage(string $message): string
{
return $this->getPrefix() . $message . $this->getPostfix();
}
/**
* @return string
*/
public function getPrefix(): string
{
return $this->prefix;
}
/**
* @return string
*/
public function getPostfix(): string
{
return $this->postfix;
}
/**
* @param string $prefix
*
* @return TemplateInterface $this
*/
public function setPrefix(string $prefix): TemplateInterface
{
$this->prefix = $prefix;
return $this;
}
/**
* @param string $postfix
*
* @return TemplateInterface $this
*/
public function setPostfix(string $postfix): TemplateInterface
{
$this->postfix = $postfix;
return $this;
}
/**
* @return string
*/
public function getWrapper(): string
{
return $this->wrapper;
}
/**
* @param string $wrapper
*
* @return TemplateInterface $this
*/
public function setWrapper(string $wrapper): TemplateInterface
{
$this->wrapper = $wrapper;
return $this;
}
/**
* Check that you have all fields defined in template and throw an exception if not.
*
* @param string $name
*
* @throws FlashTemplateException
*/
public function __get(string $name): void
{
throw new FlashTemplateException("No \"$name\" defined in template! Please, make sure you have prefix, postfix and wrapper defined!");
}
}