public function renderContext(Context $context) { $children = ''; $fields = ''; $vulnerabilities = $this->renderVulnerabilityTree($context->getVulnerabilityElement()); if ($context->hasFields()) { $fieldsHtml = []; foreach ($context->getFields() as $field) { $fieldsHtml[] = $this->renderField($field); } $fields = implode('', $fieldsHtml); } if ($context->hasChildren()) { $childrenHtml = []; foreach ($context->getChildrenArray() as $child) { $childrenHtml[] = $this->renderContext($child); } $children = implode('', $childrenHtml); } $view = $this->pixie->view('admin/context/context'); $view->vulnerabilities = $vulnerabilities; $view->children = $children; $view->fields = $fields; $view->contextName = $context->getName(); $view->type = $context->getType(); return $view->render(); }
public function asArray(Context $context) { $children = []; $fields = []; $vulnerabilities = $this->vulnerabilityTreeAsArray($context->getVulnerabilityElement()); if ($context->hasFields()) { $fieldsArr = []; foreach ($context->getFields() as $field) { $fieldsArr[] = $this->renderField($field); } $fields = $fieldsArr; } if ($context->hasChildren()) { $childrenArr = []; foreach ($context->getChildrenArray() as $child) { $childrenArr[$child->getName()] = $this->asArray($child); } $children = $childrenArr; } $result = ['name' => $context->getName(), 'type' => $context->getType(), 'technology' => $context->getTechnology()]; if ($context->getMappedTo()) { $result['mapped_to'] = $context->getMappedTo(); } if ($context->getStorageRole() != Context::STORAGE_ROLE_CHILD) { $result['storage_role'] = $context->getStorageRole(); } if (count($fields)) { $result['fields'] = $fields; } if (count($vulnerabilities)) { $result['vulnerabilities'] = $vulnerabilities; } if (count($children)) { $result['children'] = $children; } return $result; }