- Full name:
\App\Shared\Services\Parsecode - This class is marked as final and can't be subclassed
- This class is a Final class
Properties
parsecodeTags
Container for storing parsecode tags and their hook to call for the parsecode
- This property is static.
Methods
cleanPre
Clean
blocks to prevent unwanted paragraph/line-break insertion.Parameters:
Parameter Type Description $matchesarray|string
add
Add hook for parsecode tag.
There can only be one hook for each parsecode. Which means that if another plugin has a similar parsecode, it will override yours or yours will override theirs depending on which order the plugins are included and/or ran.
Simplest example of a parsecode tag using the API:
<code> // [footag foo="bar"] function footag_func($atts) { return "foo = {$atts[foo]}"; } Parsecode::add('footag', 'footag_func'); </code>Example with nice attribute defaults:
<code> // [bartag foo="bar"] function bartag_func($atts) { $args = Parsecode::atts([ 'foo' => 'no foo', 'baz' => 'default baz', ], $atts); return "foo = {$args['foo']}"; } Parsecode::add('bartag', 'bartag_func'); </code>Example with enclosed content:
<code> // [baztag]content[/baztag] function baztag_func($atts, $content='') { return "content = $content"; } Parsecode::add('baztag', 'baztag_func'); </code>Parameters:
Parameter Type Description $tagstring Parsecode tag to be searched in content content.
$funccallable Hook to run when parsecode is found.
Throws:
remove
Removes hook for parsecode.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$tag |
string | parsecode tag to remove hook for. |
Throws:
removeAll
Clear all parsecodes.
This function is simple, it clears all the parsecode tags by replacing the parsecodes global by a empty array. This is actually a very efficient method for removing all parsecodes.
exists
Whether a registered parsecode exists named $tag
Parameters:
| Parameter | Type | Description |
|---|---|---|
$tag |
string |
has
Whether the passed content contains the specified parsecode.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$content |
string | |
$tag |
string |
doParsecode
Search content for parsecodes and filter parsecodes through their hooks.
If there are no parsecode tags defined, then the content will be returned without any filtering. This might cause issues when plugins are disabled but the parsecode will still show up in the content or content.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$content |
string | Content to search for parsecodes |
Return Value:
Content with parsecodes filtered out.
getRegex
Retrieve the parsecode regular expression for searching.
The regular expression combines the parsecode tags in the regular expression in a regex class.
The regular expression contains 6 different sub matches to help with parsing.
1 - An extra [ to allow for escaping parsecodes with double [[]] 2 - The parsecode name 3 - The parsecode argument list 4 - The self-closing / 5 - The content of a parsecode when it wraps some content. 6 - An extra ] to allow for escaping parsecodes with double [[]]
Parameters:
| Parameter | Type | Description |
|---|---|---|
$tagnames |
array|null | Optional. List of parsecodes to find. Defaults to all registered parsecodes. |
Return Value:
The parsecode search regular expression
doTag
Regular Expression callable for $this->doParsecode() for calling parsecode hook.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$m |
array | Regular expression match array |
Return Value:
False on failure.
parseAtts
Retrieve all attributes from the parsecodes tag.
The attributes list has the attribute name as the key and the value of the attribute as the value in the key/value pair. This allows for easier retrieval of the attributes, since all attributes have to be known.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$text |
string |
Return Value:
List of attributes and their value.
atts
Combine user attributes with known attributes and fill in defaults when needed.
The pairs should be considered to be all the attributes which are supported by the caller and given as a list. The returned attributes will only contain the attributes in the $pairs list.
If the $atts list has unsupported attributes, then they will be ignored and removed from the final returned list.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$pairs |
array | Entire list of supported attributes and their defaults. |
$atts |
array | User defined attributes in parsecode tag. |
$parsecode |
string | Optional. The name of the parsecode, provided for context to enable filtering |
Return Value:
Combined and filtered attribute list.
Throws:
stripParsecodes
Remove all parsecode tags from the given content.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$content |
string | Content to remove parsecode tags. |
Return Value:
Content without parsecode tags.
stripParsecodeTag
Parameters:
| Parameter | Type | Description |
|---|---|---|
$m |
mixed |
autop
Parameters:
| Parameter | Type | Description |
|---|---|---|
$pee |
string | |
$br |
bool |
autopNewlinePreservationHelper
Parameters:
| Parameter | Type | Description |
|---|---|---|
$matches |
mixed |
unAutop
Parameters:
| Parameter | Type | Description |
|---|---|---|
$pee |
mixed |