- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/php_parser.php
- Класс: PHPParser
- Вызов: PHPParser::CheckForComponent2
static function CheckForComponent2($str)
{
if (mb_substr($str, 0, 5) == ""."php")
$str = mb_substr($str, 5);
else
$str = mb_substr($str, 2);
$str = mb_substr($str, 0, -2);
$bSlashed = false;
$bInString = false;
$arAllStr = array();
$new_str = "";
$string_tmp = "";
$quote_ch = "";
$i = -1;
$length = mb_strlen($str);
while ($i < $length - 1)
{
$i++;
$ch = mb_substr($str, $i, 1);
if (!$bInString)
{
if ($string_tmp != "")
{
$arAllStr[] = $string_tmp;
$string_tmp = "";
$new_str .= chr(1).(count($arAllStr) - 1).chr(2);
}
//comment
if ($ch == "/" && $i+1 < $length)
{
$ti = 0;
if (mb_substr($str, $i + 1, 1) == "*" && ($ti = mb_strpos($str, "*/", $i + 2)) !== false)
$ti += 1;
elseif (mb_substr($str, $i + 1, 1) == "/" && ($ti = mb_strpos($str, "n", $i + 2)) !== false)
$ti += 0;
if ($ti)
$i = $ti;
continue;
}
if ($ch == " " || $ch == "r" || $ch == "n" || $ch == "t")
continue;
}
if ($bInString && $ch == "\" && !$bSlashed)
{
$bSlashed = true;
continue;
}
if ($ch == """ || $ch == "'")
{
if ($bInString)
{
if (!$bSlashed && $quote_ch == $ch)
{
$bInString = false;
continue;
}
}
else
{
$bInString = true;
$quote_ch = $ch;
continue;
}
}
$bSlashed = false;
if ($bInString)
{
$string_tmp .= $ch;
continue;
}
$new_str .= $ch;
}
if ($pos = mb_strpos($new_str, "("))
{
$func_name = mb_substr($new_str, 0, $pos + 1);
if (preg_match("/^(\$[A-Z_][A-Z0-9_]*)(\s*=\s*)/i", $func_name, $arMatch))
{
$var_name = $arMatch[1];
$func_name = mb_substr($func_name, mb_strlen($arMatch[0]));
}
else
{
$var_name = "";
}
self::$arAllStr = $arAllStr;
$func_name = preg_replace_callback("'x01([0-9]+)x02's", "PHPParser::getString", $func_name);
$isComponent2Begin = false;
$arIncludeComponentFunctionStrings = self::getComponentFunctionStrings();
foreach($arIncludeComponentFunctionStrings as $functionName)
{
$component2Begin = mb_strtoupper($functionName).'(';
if(mb_strtoupper($func_name) == $component2Begin)
{
$isComponent2Begin = true;
break;
}
}
if($isComponent2Begin)
{
$params = mb_substr($new_str, $pos + 1);
$arParams = PHPParser::GetParams($params);
$arIncludeParams = array();
$arFuncParams = array();
PHPParser::GetParamsRec($arParams[2], $arAllStr, $arIncludeParams);
PHPParser::GetParamsRec($arParams[4], $arAllStr, $arFuncParams);
return array(
"COMPONENT_NAME" => PHPParser::ReplString($arParams[0], $arAllStr),
"TEMPLATE_NAME" => PHPParser::ReplString($arParams[1], $arAllStr),
"PARAMS" => $arIncludeParams,
"PARENT_COMP" => $arParams[3],
"VARIABLE" => $var_name,
"FUNCTION_PARAMS" => $arFuncParams,
);
}
}
return false;
}