ShortcodeParser
in package
Parses and renders shortcodes in content.
Supports WordPress-style shortcodes: [shortcode attr="value"] Allows registration of custom shortcode handlers.
Table of Contents
Properties
- $_customHandlers : array<string|int, mixed>
- $_widgetRenderer : WidgetRenderer|null
Methods
- __construct() : mixed
- hasShortcode() : bool
- Check if shortcode is registered
- parse() : string
- Parse shortcodes in content
- register() : void
- Register a custom shortcode handler
- unregister() : void
- Unregister a shortcode
- hasBuiltInShortcode() : bool
- Check if shortcode is a built-in widget
- parseAttributes() : array<string|int, mixed>
- Parse attribute string into array
- renderShortcode() : string
- Render a specific shortcode
Properties
$_customHandlers
private
array<string|int, mixed>
$_customHandlers
= []
$_widgetRenderer
private
WidgetRenderer|null
$_widgetRenderer
= null
Methods
__construct()
public
__construct([WidgetRenderer|null $widgetRenderer = null ]) : mixed
Parameters
- $widgetRenderer : WidgetRenderer|null = null
hasShortcode()
Check if shortcode is registered
public
hasShortcode(string $shortcode) : bool
Parameters
- $shortcode : string
-
The shortcode name
Return values
boolparse()
Parse shortcodes in content
public
parse(string $content) : string
Parameters
- $content : string
-
Content with shortcodes like [calendar id="main" max="10"]
Return values
string —Content with shortcodes replaced by rendered widgets
register()
Register a custom shortcode handler
public
register(string $shortcode, callable $handler) : void
Parameters
- $shortcode : string
-
The shortcode name
- $handler : callable
-
Function that receives attributes and returns HTML
unregister()
Unregister a shortcode
public
unregister(string $shortcode) : void
Parameters
- $shortcode : string
-
The shortcode name
hasBuiltInShortcode()
Check if shortcode is a built-in widget
private
hasBuiltInShortcode(string $shortcode) : bool
Parameters
- $shortcode : string
-
Shortcode name
Return values
boolparseAttributes()
Parse attribute string into array
private
parseAttributes(string $attrString) : array<string|int, mixed>
Parameters
- $attrString : string
-
String like: id="main" max="10"
Return values
array<string|int, mixed> —Associative array of attributes
renderShortcode()
Render a specific shortcode
private
renderShortcode(string $shortcode, array<string|int, mixed> $attrs) : string
Parameters
- $shortcode : string
-
Shortcode name
- $attrs : array<string|int, mixed>
-
Parsed attributes
Return values
string —Rendered HTML or error comment