aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/functions.php10
-rw-r--r--core/namespace/Application.php1
-rw-r--r--core/namespace/Parsers/FunctionParser.php19
3 files changed, 23 insertions, 7 deletions
diff --git a/core/functions.php b/core/functions.php
index d4337a4..9202bad 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -101,6 +101,10 @@ function generateItemTemplateData(EntityInterface $Entity): array {
$FunctionParser = new FunctionParser;
$MarkdownParser = new MarkdownParser;
+ $FunctionParser->registerFromArray(
+ Application::getContentFunctions()
+ );
+
$attribute = $Entity->getAll(['password']);
$attribute = array_change_key_case($attribute, CASE_UPPER);
@@ -159,7 +163,11 @@ function generateCategoryDataTree(array $category_data, $root = 0): array {
function parseEntityContent(EntityInterface $Entity): string {
$text = $Entity->get('body');
- $FunctionParser = new FunctionParser();
+ $FunctionParser = new FunctionParser;
+ $FunctionParser->registerFromArray(
+ Application::getContentFunctions()
+ );
+
$text = $FunctionParser->transform($text);
if(Application::get('WRAP_EMOTICONS')) {
diff --git a/core/namespace/Application.php b/core/namespace/Application.php
index 01c36ac..1f1e6f6 100644
--- a/core/namespace/Application.php
+++ b/core/namespace/Application.php
@@ -224,7 +224,6 @@ class Application {
contain only numbers, uppercase letters and underscores!');
}
- FunctionParser::register($name, $callback);
self::$contentFunctions[$name] = $callback;
}
diff --git a/core/namespace/Parsers/FunctionParser.php b/core/namespace/Parsers/FunctionParser.php
index 02570a0..94a4c92 100644
--- a/core/namespace/Parsers/FunctionParser.php
+++ b/core/namespace/Parsers/FunctionParser.php
@@ -3,7 +3,7 @@ namespace Parsers;
use ReflectionFunction;
class FunctionParser implements ParserInterface {
- private static $functions = [];
+ private $functions = [];
#===============================================================================
# Main regex for matching the whole function call
@@ -39,19 +39,28 @@ class FunctionParser implements ParserInterface {
#===============================================================================
# Register function
#===============================================================================
- public static function register(string $name, callable $callback): void {
+ public function register(string $name, callable $callback): void {
$Function = new ReflectionFunction($callback);
- self::$functions[$name] = [
+ $this->functions[$name] = [
'callback' => $callback,
'required' => $Function->getNumberOfRequiredParameters()
];
}
#===============================================================================
+ # Register multiple functions from array
+ #===============================================================================
+ public function registerFromArray(array $functions): void {
+ foreach($functions as $name => $callback) {
+ $this->register($name, $callback);
+ }
+ }
+
+ #===============================================================================
# Parse functions
#===============================================================================
public function parse(string $text): array {
- $functionNames = array_keys(self::$functions);
+ $functionNames = array_keys($this->functions);
$functionNames = implode('|', $functionNames);
$pattern = self::FUNCTION_PATTERN;
@@ -72,7 +81,7 @@ class FunctionParser implements ParserInterface {
# Transform functions
#===============================================================================
public function transform(string $text): string {
- $functionData = self::$functions;
+ $functionData = $this->functions;
$functionNames = array_keys($functionData);
$functionNames = implode('|', $functionNames);