- Модуль: perfmon
- Путь к файлу: ~/bitrix/modules/perfmon/lib/php/codetree.php
- Класс: BitrixPerfmonPhpCodeTree
- Вызов: CodeTree::makeCodeTree
protected function makeCodeTree(array $updaterSteps, &$result)
{
foreach ($updaterSteps as $i => $statement)
{
if (empty($statement->conditions))
{
$result[] = $statement->formatBodyLines(0);
unset($updaterSteps[$i]);
}
}
while ($updaterSteps)
{
$byPredicates = array();
foreach ($updaterSteps as $i => $statement)
{
/**
* @var Condition $condition
*/
foreach ($statement->conditions as $condition)
{
$predicate = $condition->getPredicate();
if (!isset($byPredicates[$predicate]))
{
$byPredicates[$predicate] = array(
"predicate" => $predicate,
"dep" => $statement->dependOn,
"sort" => $this->getPredicateSort($predicate),
"count" => 1,
);
}
else
{
$byPredicates[$predicate]["count"]++;
}
}
}
if ($byPredicates)
{
sortByColumn($byPredicates, array(
"dep" => SORT_ASC,
"count" => SORT_DESC,
"sort" => SORT_ASC,
));
$mostPopular = key($byPredicates);
$subSteps = array();
$ifStatement = array(
"if" => array($mostPopular),
"body" => array(),
);
foreach ($updaterSteps as $i => $statement)
{
foreach ($statement->conditions as $j => $condition)
{
if ($condition->getPredicate() == $mostPopular)
{
unset($statement->conditions[$j]);
$subSteps[] = $statement;
unset($updaterSteps[$i]);
}
}
}
$this->makeCodeTree($subSteps, $ifStatement["body"]);
if (
is_array($ifStatement["body"])
&& count($ifStatement["body"]) == 1
&& is_array($ifStatement["body"][0])
&& isset($ifStatement["body"][0]["if"])
&& isset($ifStatement["body"][0]["body"])
&& mb_strlen(implode(' && ', array_merge($ifStatement["if"], $ifStatement["body"][0]["if"]))) < 100
)
{
$ifStatement["if"] = array_merge($ifStatement["if"], $ifStatement["body"][0]["if"]);
$ifStatement["body"] = $ifStatement["body"][0]["body"];
}
$result[] = $ifStatement;
}
}
}