Parsecode

App\Shared\Services\Parsecode

Method Description Type Parameters Return
cleanPre public
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 andor ran






Simplest example of a parsecode tag using the API:


[footag foo="bar"]
function footag_func($atts) {
}
Parsecode::add('footag', 'footag_func');


Example with nice attribute defaults:


[bartag foo="bar"]
function bartag_func($atts) {
$args = Parsecode::atts([
'foo' => 'no foo',
'baz' => 'default baz',
], $atts);

}
Parsecode::add('bartag', 'bartag_func');


Example with enclosed content:


[baztag]content[baztag]
function baztag_func($atts, $content='') {
}
Parsecode::add('baztag', 'baztag_func');


throws Exception

public string $tag

Parsecode tag to be searched in content content


callable $func

Hook to run when parsecode is found

bool
remove Removes hook for parsecode

throws Exception
public string $tag parsecode tag to remove hook for
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
public
exists Whether a registered parsecode exists named $tag
public string $tag bool
has Whether the passed content contains the specified parsecode
public string $content
string $tag
bool
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
public string $content Content to search for parsecodes string 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 [[]]
public array|null $tagnames Optional List of parsecodes to find Defaults to all registered parsecodes string The parsecode search regular expression
doTag Regular Expression callable for $this->doParsecode() for calling parsecode hook

see $this->getRegex for details of the match array contents
access private
private array $m Regular expression match array mixed 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 keyvalue pair This allows for easier
retrieval of the attributes, since all attributes have to be known
public string $text string
array 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

throws \Qubus\Exception\Exception
throws ReflectionException
public array $pairs Entire list of supported attributes and their defaults
array $atts User defined attributes in parsecode tag
string $parsecode Optional The name of the parsecode, provided for context to enable filtering
array Combined and filtered attribute list