Пример #1
0
 /**
  * @param VulnerableElement $element
  * @return string
  */
 public function vulnerabilityTreeAsArray(VulnerableElement $element)
 {
     $result = [];
     $vulnerabilities = [];
     $children = [];
     $conditions = [];
     if ($element->hasChildren()) {
         $childrenArr = [];
         foreach ($element->getChildrenArray() as $child) {
             $childrenArr[] = $this->vulnerabilityTreeAsArray($child);
         }
         $children = $childrenArr;
     }
     if ($element instanceof ConditionalVulnerableElement) {
         /** @var ICondition $condition */
         foreach ($element->getConditions()->getConditions() as $condition) {
             $conditions[$condition->getName()] = $condition->toArray();
         }
     }
     /** @var Vulnerability $vuln */
     foreach ($element->getVulnerabilitySet()->getVulnerabilities() as $vuln) {
         $vulnerabilities[$vuln->getName()] = $vuln->asArray();
         unset($vulnerabilities[$vuln->getName()]['name']);
     }
     ksort($vulnerabilities);
     if ($element->getName()) {
         $result['name'] = $element->getName();
     }
     if (count($conditions)) {
         $result['conditions'] = $conditions;
     }
     if (count($vulnerabilities)) {
         $result['vuln_list'] = $vulnerabilities;
     }
     if (count($children)) {
         $result['children'] = $children;
     }
     return $result;
 }