|
1
|
|
|
<?php |
|
2
|
|
|
namespace Thunder\Shortcode\Shortcode; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @author Tomasz Kowalczyk <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
abstract class AbstractShortcode |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var string */ |
|
10
|
|
|
protected $name; |
|
11
|
|
|
/** @psalm-var array<string,string|null> */ |
|
12
|
|
|
protected $parameters = array(); |
|
13
|
|
|
/** @var string|null */ |
|
14
|
|
|
protected $content; |
|
15
|
|
|
/** @var string|null */ |
|
16
|
|
|
protected $bbCode; |
|
17
|
|
|
|
|
18
|
|
|
/** @return bool */ |
|
19
|
1 |
|
public function hasContent() |
|
20
|
|
|
{ |
|
21
|
1 |
|
return $this->content !== null; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** @return string */ |
|
25
|
223 |
|
public function getName() |
|
26
|
|
|
{ |
|
27
|
223 |
|
return $this->name; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** @psalm-return array<string,string|null> */ |
|
31
|
223 |
|
public function getParameters() |
|
32
|
|
|
{ |
|
33
|
223 |
|
return $this->parameters; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $name |
|
38
|
|
|
* |
|
39
|
|
|
* @return bool |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function hasParameter($name) |
|
42
|
|
|
{ |
|
43
|
3 |
|
return array_key_exists($name, $this->parameters); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** @return bool */ |
|
47
|
4 |
|
public function hasParameters() |
|
48
|
|
|
{ |
|
49
|
4 |
|
return (bool)$this->parameters; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $name |
|
54
|
|
|
* @param string|null $default |
|
55
|
|
|
* |
|
56
|
|
|
* @psalm-return string|null |
|
57
|
|
|
*/ |
|
58
|
3 |
|
public function getParameter($name, $default = null) |
|
59
|
|
|
{ |
|
60
|
3 |
|
return $this->hasParameter($name) ? $this->parameters[$name] : $default; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param int $index |
|
65
|
|
|
* |
|
66
|
|
|
* @return string|null |
|
67
|
|
|
*/ |
|
68
|
5 |
|
public function getParameterAt($index) |
|
69
|
|
|
{ |
|
70
|
5 |
|
$keys = array_keys($this->parameters); |
|
71
|
|
|
|
|
72
|
5 |
|
return array_key_exists($index, $keys) ? $keys[$index] : null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** @return string|null */ |
|
76
|
223 |
|
public function getContent() |
|
77
|
|
|
{ |
|
78
|
223 |
|
return $this->content; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** @return string|null */ |
|
82
|
223 |
|
public function getBbCode() |
|
83
|
|
|
{ |
|
84
|
223 |
|
return $this->bbCode; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|