/** * @param string $tag * @return string */ public function convert($tag) { $name = "Expression"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPTemplate::ECHO_BEGIN . PHPConverter::getExpressionRegex(true) . PHPTemplate::ECHO_OPTIONAL_END . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $from = 1; return "{{ " . PHPConverter::convertExpression($matches, $from) . " }}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Ternary operator call"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPTemplate::ECHO_BEGIN . PHPConverter::getTernaryOperatorExpressionRegex(true) . PHPTemplate::ECHO_OPTIONAL_END . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $from = 1; return "{{ " . PHPConverter::convertTernaryOperatorExpression($matches, $from) . " }}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Printf"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPConverter::getFunctionCallRegex(true) . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $from = 1; return "{{ " . PHPConverter::convertFunctionCall($matches, $from) . " }}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } return $tag; }
/** * @param string $tag * @return string */ public function convert($tag) { $name = "Expression"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPConverter::getVariableRegex(true) . '\\s*=\\s*' . PHPConverter::getExpressionRegex(true) . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $variable = PHPConverter::convertVariable($matches[1]); $from = 2; return "{% set " . $variable . " = " . PHPConverter::convertExpression($matches, $from) . " %}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Ternary operator expression"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPConverter::getVariableRegex(true) . '\\s*=\\s*' . PHPConverter::getTernaryOperatorExpressionRegex(true) . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $variable = PHPConverter::convertVariable($matches[1]); $from = 2; return "{% set " . $variable . " = " . PHPConverter::convertTernaryOperatorExpression($matches, $from) . " %}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Postfix increase"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPConverter::getVariableRegex(true) . '\\s*\\+\\+\\s*' . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $variable = PHPConverter::convertVariable($matches[1]); return "{% set {$variable} = {$variable} + 1 %}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Prefix increase"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . '\\s*\\+\\+\\s*' . PHPConverter::getVariableRegex(true) . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $from = 1; $variable = PHPConverter::convertVariableCall($matches, $from); return "{% set {$variable} = {$variable} + 1 %}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Postfix decrease"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPConverter::getVariableRegex(true) . '\\s*\\-\\-\\s*' . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $variable = PHPConverter::convertVariable($matches[1]); return "{% set {$variable} = {$variable} - 1 %}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } $name = "Prefix decrease"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . '\\s*\\-\\-\\s*' . PHPConverter::getVariableRegex(true) . PHPTemplate::OPTIONAL_STATEMENT_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $variable = PHPConverter::convertVariable($matches[1]); return "{% set {$variable} = {$variable} - 1 %}"; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } return $tag; }