13
13
namespace chillerlan \BBCode ;
14
14
15
15
use chillerlan \BBCode \Output \BBCodeOutputInterface ;
16
- use chillerlan \Traits \{
17
- ClassLoader , ContainerInterface
18
- };
16
+ use chillerlan \Settings \SettingsContainerInterface ;
19
17
use Psr \Log \{
20
18
LoggerAwareInterface , LoggerAwareTrait , LoggerInterface , NullLogger
21
19
};
22
20
use Psr \SimpleCache \CacheInterface ;
23
21
24
22
class BBCode implements LoggerAwareInterface{
25
- use ClassLoader, LoggerAwareTrait;
23
+ use LoggerAwareTrait;
26
24
27
25
/**
28
- * @var \chillerlan\BBCode\BBCodeOptions|\chillerlan\Traits\ContainerInterface
26
+ * @var \chillerlan\BBCode\BBCodeOptions|\chillerlan\Settings\SettingsContainerInterface
29
27
*/
30
28
protected $ options ;
31
29
@@ -67,11 +65,11 @@ class BBCode implements LoggerAwareInterface{
67
65
/**
68
66
* BBCode constructor.
69
67
*
70
- * @param \chillerlan\Traits\ContainerInterface |null $options
71
- * @param \Psr\SimpleCache\CacheInterface|null $cache
72
- * @param \Psr\Log\LoggerInterface|null $logger
68
+ * @param \chillerlan\Settings\SettingsContainerInterface |null $options
69
+ * @param \Psr\SimpleCache\CacheInterface|null $cache
70
+ * @param \Psr\Log\LoggerInterface|null $logger
73
71
*/
74
- public function __construct (ContainerInterface $ options = null , CacheInterface $ cache = null , LoggerInterface $ logger = null ){
72
+ public function __construct (SettingsContainerInterface $ options = null , CacheInterface $ cache = null , LoggerInterface $ logger = null ){
75
73
$ this
76
74
->setCache ($ cache ?? new BBCache )
77
75
->setLogger ($ logger ?? new NullLogger );
@@ -112,12 +110,12 @@ public function setCache(CacheInterface $cache):BBCode{
112
110
/**
113
111
* @todo
114
112
*
115
- * @param \chillerlan\Traits\ContainerInterface $options
113
+ * @param \chillerlan\Settings\SettingsContainerInterface $options
116
114
*
117
115
* @throws \chillerlan\BBCode\BBCodeException
118
116
* @return \chillerlan\BBCode\BBCode
119
117
*/
120
- public function setOptions (ContainerInterface $ options ):BBCode {
118
+ public function setOptions (SettingsContainerInterface $ options ):BBCode {
121
119
$ this ->options = $ options ;
122
120
123
121
mb_internal_encoding ('UTF-8 ' );
@@ -138,16 +136,28 @@ public function setOptions(ContainerInterface $options):BBCode{
138
136
}
139
137
140
138
if ($ this ->options ->sanitizeInput || $ this ->options ->sanitizeOutput ){
141
- $ this ->sanitizerInterface = $ this ->loadClass ($ this ->options ->sanitizerInterface , SanitizerInterface::class, $ this ->options );
139
+ $ this ->sanitizerInterface = new $ this ->options ->sanitizerInterface ($ this ->options );
140
+
141
+ if (!$ this ->sanitizerInterface instanceof SanitizerInterface){
142
+ throw new BBcodeException ('invalid SanitizerInterface ' );
143
+ }
142
144
}
143
145
144
146
145
147
146
148
if ($ this ->options ->preParse || $ this ->options ->postParse ){
147
- $ this ->parserMiddleware = $ this ->loadClass ($ this ->options ->parserMiddlewareInterface , ParserMiddlewareInterface::class, $ this ->options , $ this ->cache , $ this ->logger );
149
+ $ this ->parserMiddleware = new $ this ->options ->parserMiddlewareInterface ($ this ->options , $ this ->cache , $ this ->logger );
150
+
151
+ if (!$ this ->parserMiddleware instanceof ParserMiddlewareInterface){
152
+ throw new BBcodeException ('invalid ParserMiddlewareInterface ' );
153
+ }
148
154
}
149
155
150
- $ this ->outputInterface = $ this ->loadClass ($ this ->options ->outputInterface , BBCodeOutputInterface::class, $ this ->options , $ this ->cache , $ this ->logger );
156
+ $ this ->outputInterface = new $ this ->options ->outputInterface ($ this ->options , $ this ->cache , $ this ->logger );
157
+
158
+ if (!$ this ->outputInterface instanceof BBCodeOutputInterface){
159
+ throw new BBcodeException ('invalid BBCodeOutputInterface ' );
160
+ }
151
161
152
162
$ this ->tags = $ this ->outputInterface ->getTags ();
153
163
$ this ->noparse = $ this ->outputInterface ->getNoparse ();
0 commit comments