Ejemplo n.º 1
0
 /**
  * Factory method to create context tree from config array.
  * @param $name
  * @param array $data
  * @param $parent
  * @param int $type
  * @param null|Pixie $pixie
  * @return Context
  */
 public static function createFromData($name, array $data = [], $parent = null, $type = self::TYPE_DEFAULT, $pixie = null)
 {
     $context = new Context($name, [], $type, $pixie);
     $context->setParent($parent);
     if ($parent) {
         $context->setParams($parent->getParams());
     }
     $context->setFields(array_key_exists('fields', $data) ? $data['fields'] : array());
     $context->setVulnerabilities(array_key_exists('vulnerabilities', $data) ? $data['vulnerabilities'] : array());
     // Add contexts forms contexts
     if (array_key_exists('forms', $data) && is_array($data['forms'])) {
         foreach ($data['forms'] as $formName => $formData) {
             self::checkValidName($formName);
             $formContext = self::createFromData($formName, $formData, $context, self::TYPE_FORM, $pixie);
             $context->addContext($formContext);
         }
     }
     // Add contexts sub-contexts
     $blocks = ['contexts', 'actions'];
     foreach ($blocks as $block) {
         if (array_key_exists($block, $data) && is_array($data[$block])) {
             foreach ($data[$block] as $subContextName => $subContextData) {
                 self::checkValidName($subContextName);
                 $subContext = self::createFromData($subContextName, $subContextData, $context, self::TYPE_DEFAULT, $pixie);
                 $context->addContext($subContext);
             }
         }
     }
     return $context;
 }