/** * @param string $tag * @return string */ public function convert($tag) { /* Lecseréli a <?php foreach($a as $v) ?> típusú template-eket */ $name = "Value"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPTemplate::FOREACH_HEAD_BEGIN . PHPConverter::getExpressionRegex(true) . "\\s*as\\s*" . PHPConverter::getVariableRegex(true) . PHPTemplate::FOREACH_HEAD_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $from = 2; $result = "{% for " . PHPConverter::convertVariable($matches[$from]) . " in "; $from = 1; $result .= PHPConverter::convertExpression($matches, $from) . " %}"; return $result; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } /* Lecseréli a <?php foreach($a as $k => $v) ?> típusú template-eket */ $name = "Key and value"; $tag = preg_replace_callback("/" . PHPTemplate::TEMPLATE_START . PHPTemplate::FOREACH_HEAD_BEGIN . PHPConverter::getExpressionRegex(true) . "\\s*as\\s*" . PHPConverter::getVariableRegex(true) . "\\s*=>\\s*" . PHPConverter::getVariableRegex(true) . PHPTemplate::FOREACH_HEAD_END . PHPTemplate::TEMPLATE_END . "/s", function ($matches) { $from = 2; $result = "{% for " . PHPConverter::convertVariable($matches[$from]) . ", "; $from = 3; $result .= PHPConverter::convertVariable($matches[$from]) . " in "; $from = 1; $result .= PHPConverter::convertExpression($matches, $from) . " %}"; return $result; }, $tag, -1, $count); if (isset($this->conversionInfo[$name])) { $this->conversionInfo[$name] += $count; } else { $this->conversionInfo[$name] = 0; } if ($count !== 0) { return $tag; } /* Lecseréli a <?php endforeach; ?> típusú template-eket */ $name = "Key and value"; $tag = preg_replace("/" . PHPTemplate::TEMPLATE_START . PHPTemplate::ENDFOREACH_STATEMENT . PHPTemplate::TEMPLATE_END . "/s", "{% endfor %}", $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; }