1 | <?php |
||
30 | class ShortcodeManager implements ShortcodeManagerInterface { |
||
31 | |||
32 | use ConfigTrait; |
||
33 | |||
34 | /* |
||
35 | * The delimiter that is used to express key-subkey relations in the config. |
||
36 | */ |
||
37 | const CONFIG_SEPARATOR = '/'; |
||
38 | |||
39 | /* |
||
40 | * Default classes that are used when omitted from the config. |
||
41 | */ |
||
42 | const DEFAULT_SHORTCODE = 'BrightNucleus\Shortcode\Shortcode'; |
||
43 | const DEFAULT_SHORTCODE_ATTS_PARSER = 'BrightNucleus\Shortcode\ShortcodeAttsParser'; |
||
44 | const DEFAULT_SHORTCODE_UI = 'BrightNucleus\Shortcode\ShortcodeUI'; |
||
45 | |||
46 | /* |
||
47 | * The names of the configuration keys. |
||
48 | */ |
||
49 | const KEY_CUSTOM_ATTS_PARSER = 'custom_atts_parser'; |
||
50 | const KEY_CUSTOM_CLASS = 'custom_class'; |
||
51 | const KEY_CUSTOM_UI = 'custom_ui'; |
||
52 | const KEY_UI = 'ui'; |
||
53 | /** |
||
54 | * Collection of ShortcodeInterface objects. |
||
55 | * |
||
56 | * @since 0.1.0 |
||
57 | * |
||
58 | * @var ShortcodeInterface[] |
||
59 | */ |
||
60 | protected $shortcodes = [ ]; |
||
61 | |||
62 | /** |
||
63 | * DependencyManagerInterface implementation. |
||
64 | * |
||
65 | * @since 0.1.0 |
||
66 | * |
||
67 | * @var DependencyManagerInterface |
||
68 | */ |
||
69 | protected $dependencies; |
||
70 | |||
71 | /** |
||
72 | * Collection of ShortcodeUIInterface objects. |
||
73 | * |
||
74 | * @since 0.1.0 |
||
75 | * |
||
76 | * @var ShortcodeUIInterface[] |
||
77 | */ |
||
78 | protected $shortcode_uis = [ ]; |
||
79 | |||
80 | /** |
||
81 | * Instantiate a ShortcodeManager object. |
||
82 | * |
||
83 | * @since 0.1.0 |
||
84 | * |
||
85 | * @param ConfigInterface $config Configuration to set up the |
||
86 | * shortcodes. |
||
87 | * @param DependencyManager|null $dependencies Optional. Dependencies that |
||
88 | * are needed by the shortcodes. |
||
89 | * @throws RuntimeException If the config could not be processed. |
||
90 | */ |
||
91 | public function __construct( |
||
100 | |||
101 | /** |
||
102 | * Initialize the Shortcode Manager. |
||
103 | * |
||
104 | * @since 0.1.0 |
||
105 | */ |
||
106 | protected function init_shortcodes() { |
||
111 | |||
112 | /** |
||
113 | * Initialize a single shortcode. |
||
114 | * |
||
115 | * @since 0.1.0 |
||
116 | * |
||
117 | * @param string $tag The tag of the shortcode to register. |
||
118 | */ |
||
119 | protected function init_shortcode( $tag ) { |
||
137 | |||
138 | /** |
||
139 | * Get the class name of an implementation of the ShortcodeInterface. |
||
140 | * |
||
141 | * @since 0.1.0 |
||
142 | * |
||
143 | * @param string $tag Shortcode tag to get the class for. |
||
144 | * @return string Class name of the Shortcode. |
||
145 | */ |
||
146 | protected function get_shortcode_class( $tag ) { |
||
152 | |||
153 | /** |
||
154 | * Get the class name of an implementation of the |
||
155 | * ShortcodeAttsParsersInterface. |
||
156 | * |
||
157 | * @since 0.1.0 |
||
158 | * |
||
159 | * @param string $tag Shortcode tag to get the class for. |
||
160 | * @return string Class name of the ShortcodeAttsParser. |
||
161 | */ |
||
162 | protected function get_shortcode_atts_parser_class( $tag ) { |
||
168 | |||
169 | /** |
||
170 | * Initialize the Shortcode UI for a single shortcode. |
||
171 | * |
||
172 | * @since 0.1.0 |
||
173 | * |
||
174 | * @param string $tag The tag of the shortcode to register the UI for. |
||
175 | */ |
||
176 | protected function init_shortcode_ui( $tag ) { |
||
185 | |||
186 | /** |
||
187 | * Get the class name of an implementation of the ShortcodeUIInterface. |
||
188 | * |
||
189 | * @since 0.1.0 |
||
190 | * |
||
191 | * @param string $tag Configuration settings. |
||
192 | * @return string Class name of the ShortcodeUI. |
||
193 | */ |
||
194 | protected function get_shortcode_ui_class( $tag ) { |
||
200 | |||
201 | /** |
||
202 | * Register all of the shortcode handlers. |
||
203 | * |
||
204 | * @since 0.1.0 |
||
205 | * |
||
206 | * @param mixed $context Optional. Context information to pass to shortcode. |
||
207 | * @return void |
||
208 | */ |
||
209 | public function register( $context = null ) { |
||
225 | |||
226 | /** |
||
227 | * Validate the context to make sure it is an array. |
||
228 | * |
||
229 | * @since 0.2.3 |
||
230 | * |
||
231 | * @param mixed $context The context as passed in by WordPress. |
||
232 | * @return array Validated context. |
||
233 | */ |
||
234 | protected function validate_context( $context ) { |
||
240 | |||
241 | /** |
||
242 | * Get the name of the page template. |
||
243 | * |
||
244 | * @since 0.1.0 |
||
245 | * |
||
246 | * @return string Name of the page template. |
||
247 | */ |
||
248 | protected function get_page_template() { |
||
256 | |||
257 | /** |
||
258 | * Register the shortcode UI handlers. |
||
259 | * |
||
260 | * @since 0.1.0 |
||
261 | */ |
||
262 | public function register_shortcode_ui() { |
||
273 | |||
274 | /** |
||
275 | * Execute a specific shortcode directly from code. |
||
276 | * |
||
277 | * @since 0.2.4 |
||
278 | * |
||
279 | * @param string $tag Tag of the shortcode to execute. |
||
280 | * @param array $atts Array of attributes to pass to the shortcode. |
||
281 | * @param null $content Inner content to pass to the shortcode. |
||
282 | * @return string Rendered HTML. |
||
283 | */ |
||
284 | public function do_tag( $tag, array $atts = [ ], $content = null ) { |
||
287 | } |
||
288 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.