示例#1
0
 /**
  * @param array $config
  * @param null $name
  * @param string $storageRole
  * @return Context
  * @throws \Exception
  */
 public function buildContextFromArray(array $config, $name = null, $storageRole = Context::STORAGE_ROLE_CHILD)
 {
     $type = in_array($config['type'], Context::getTypes()) ? $config['type'] : Context::TYPE_STANDARD;
     $technology = in_array($config['technology'], Context::getTechnologies()) ? $config['technology'] : Context::TECH_GENERIC;
     $context = new Context($name, null, $type, $storageRole);
     $context->setTechnology($technology);
     $context->setMappedTo($config['mapped_to'] ?: '');
     if (is_array($config['fields'])) {
         $fields = $config['fields'];
         // Iterate all fields and create a rule set
         foreach ($fields as $fieldData) {
             $vulnElement = $this->buildVulnerabilityElementFromArray($fieldData['vulnerabilities']);
             $source = $fieldData['source'] ?: FieldDescriptor::SOURCE_ANY;
             if (!in_array($source, FieldDescriptor::getSources())) {
                 throw new \InvalidArgumentException("Invalid source for field '{$fieldData['name']}': " . $source);
             }
             $field = new Field($fieldData['name'], $vulnElement, $source);
             $context->addField($field);
         }
     }
     if (is_array($config['children'])) {
         foreach ($config['children'] as $contextName => $contextData) {
             $child = $this->buildContextFromArray($contextData, $contextName);
             $context->addChild($child);
         }
     }
     if (is_array($config['vulnerabilities'])) {
         $vulnElement = $this->buildVulnerabilityElementFromArray($config['vulnerabilities']);
         $context->setVulnTree($vulnElement);
     }
     return $context;
 }
示例#2
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     parent::buildForm($builder, $options);
     $sourceOptions = ['attr' => ['class' => 'form-control input-miniature field-source js-field-source'], 'constraints' => [new Choice(['message' => "At least one method must be selected.", 'choices' => FieldDescriptor::getSources(), 'multiple' => false]), new NotBlank()]];
     if ($options['edit_mode_enabled']) {
         $sourceOptions['choices'] = ArraysHelper::arrayFillEqualPairs(FieldDescriptor::getSources());
         $sourceOptions['multiple'] = false;
     } else {
         $sourceOptions['label'] = false;
     }
     $builder->add('source', $options['edit_mode_enabled'] ? 'choice' : 'hidden', $sourceOptions);
     $vulnTree = $builder->get('vulnTree');
     $builder->remove('vulnTree');
     $builder->add($vulnTree);
 }
示例#3
0
 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     parent::loadValidatorMetadata($metadata);
     $metadata->addPropertyConstraints('source', [new Constraints\NotBlank(['message' => "Source cannot be empty."]), new Constraints\Choice(['choices' => FieldDescriptor::getSources()])]);
 }
示例#4
0
 public function getSource()
 {
     return $this->descriptor->getSource();
 }