1<?php
2
3namespace ComboStrap;
4
5
6use syntax_plugin_combo_variable;
7
8class PipelineTag
9{
10
11
12    public const CANONICAL = PipelineTag::TAG;
13    public const TAG = "pipeline";
14
15    public static function processExit(\Doku_Handler $handler)
16    {
17        $callstack = CallStack::createFromHandler($handler);
18        $openingCall = $callstack->moveToPreviousCorrespondingOpeningCall();
19        $script = "";
20        while ($actual = $callstack->next()) {
21            /**
22             * Pipeline is the only inline tag that
23             * should be protected
24             * As it's deprecated we don't create a special
25             * syntax plugin for it
26             * We just do this hack where we capture the double quote opening
27             */
28            $actualName = $actual->getTagName();
29            switch ($actualName) {
30                case "doublequoteopening":
31                case "doublequoteclosing":
32                    $script .= '"';
33                    continue 2;
34                case "xmlinlinetag":
35                    $script .= $actual->getCapturedContent();
36                    continue 2;
37                default:
38                    LogUtility::warning("The content tag with the name ($actualName) is unknown, the captured content may be not good.",self::CANONICAL);
39                    $script .= $actual->getCapturedContent();
40
41            }
42
43        }
44        $openingCall->addAttribute(PluginUtility::PAYLOAD, $script);
45        $callstack->deleteAllCallsAfter($openingCall);
46
47    }
48
49    public static function renderEnterXhtml(TagAttributes $tagAttributes): string
50    {
51        $pipelineWithPossibleVariableExpression = $tagAttributes->getValue(PluginUtility::PAYLOAD);
52        $pipelineExpression = syntax_plugin_combo_variable::replaceVariablesWithValuesFromContext($pipelineWithPossibleVariableExpression);
53        try {
54            return PipelineUtility::execute($pipelineExpression);
55        } catch (ExceptionBadSyntax $e) {
56            return LogUtility::wrapInRedForHtml($e->getMessage());
57        }
58
59
60    }
61}
62