Пример #1
0
 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();
 }
Пример #2
0
 /**
  * Sets fields which are to be filtered on vulnerabilities.
  * @param array $fields
  * @return $this
  */
 public function setFields($fields = [])
 {
     $parentFields = $this->parent ? $this->parent->getFields() : [];
     $this->fields = ArraysHelper::arrayMergeRecursiveDistinct($parentFields, $fields);
     $repo = $this->pixie->modelInfoRepository;
     if (!$repo) {
         return $this;
     }
     if (!is_array($this->params['db_fields'])) {
         $this->params['db_fields'] = array();
     }
     foreach ($this->fields as $field => $data) {
         if ($data['db_field']) {
             $parts = preg_split('/\\./', $data['db_field'], -1, PREG_SPLIT_NO_EMPTY);
             if (count($parts) < 2) {
                 continue;
             }
             $info = $repo->getModelInfo($parts[0]);
             if ($info === false) {
                 continue;
             }
             $this->fields[$field]['db_table'] = $info['table'];
             $this->fields[$field]['db_field_name'] = $parts[1];
             $fieldName = $info['table'] . '.' . $parts[1];
             $this->params['db_fields'][$fieldName] = $field;
         }
     }
     return $this;
 }
Пример #3
0
 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;
 }
Пример #4
0
 /**
  * @return array
  */
 public function getFields()
 {
     return $this->currentContext->getFields() ?: [];
 }