• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/file.php
  • Класс: BitrixTranslateFile
  • Вызов: File::lint
public function lint(
	string $content = '',
	array $validTokens = [T_OPEN_TAG, T_CLOSE_TAG, T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING, T_VARIABLE, T_COMMENT, T_DOC_COMMENT],
	array $validChars = ['[', ']', ';', '=']
): bool
{
	$isValid = false;

	if (empty($content))
	{
		if ($this->isExists())
		{
			$content = $this->getContents();
		}
	}
	if (empty($content) || !is_string($content))
	{
		$this->addError(new MainError("Parse Error: Empty content"));
		return $isValid;
	}

	$tokens = token_get_all($content);

	$line = $tokens[0][2] || 1;
	if (!is_array($tokens[0]) || $tokens[0][0] !== T_OPEN_TAG)
	{
		$this->addError(new MainError("Parse Error: Wrong open tag ".token_name($tokens[0][0])." '{$tokens[0][1]}' at line {$line}"));
	}
	else
	{
		$isValid = true;
		foreach ($tokens as $token)
		{
			if (is_array($token))
			{
				$line = $token[2];
				if (
					!in_array($token[0], $validTokens) ||
					($token[0] === T_VARIABLE && $token[1] != '$MESS')
				)
				{
					$this->addError(new MainError("Parse Error: Wrong token ". token_name($token[0]). " '{$token[1]}' at line {$line}"));
					$isValid = false;
					break;
				}
			}
			elseif (is_string($token))
			{
				if (!in_array($token, $validChars))
				{
					$line ++;
					$this->addError(new MainError("Parse Error: Expected character '{$token}' at line {$line}"));
					$isValid = false;
					break;
				}
			}
		}
	}

	return $isValid;
}