public static function loadFromFile($filepath)
  {
    $info = Yaml::parseFile($filepath);
    $name = str_replace('.profile.yml', '', pathinfo($filepath, PATHINFO_BASENAME));

    $profile = new static();
    $profile->setTitle($info['title'])
            ->setName($name)
            ->setFilepath($filepath);

    if (isset($info['description'])) {
      $profile->setDescription($info['description']);
    }

    if (isset($info['policies'])) {
      $v21_keys = ['parameters', 'severity'];
      foreach ($info['policies'] as $name => $metadata) {
        // Check for v2.0.x style profiles.
        if (!empty($metadata) && !count(array_intersect($v21_keys, array_keys($metadata)))) {
          throw new \Exception("{$info['title']} is a v2.0.x profile. Please upgrade $filepath to v2.2.x schema.");
        }
        $weight = array_search($name, array_keys($info['policies']));
        $profile->addPolicyDefinition(PolicyDefinition::createFromProfile($name, $weight, $metadata));
      }
    }

    if (isset($info['excluded_policies']) && is_array($info['excluded_policies'])) {
      $profile->addExcludedPolicies($info['excluded_policies']);
    }

    if (isset($info['include'])) {
      foreach ($info['include'] as $name) {
        $include = ProfileSource::loadProfileByName($name);
        $profile->addInclude($include);
      }
    }

    if (isset($info['format'])) {
      foreach ($info['format'] as $format => $options) {
        $profile->addFormatOptions(Format::create($format, $options));
      }
    }

    return $profile;
  }
public static function loadFromFile($filepath)
  {
    $info = Yaml::parseFile($filepath);
    $name = str_replace('.profile.yml', '', pathinfo($filepath, PATHINFO_BASENAME));

    $profile = new static();
    $profile->setTitle($info['title'])
            ->setName($name)
            ->setFilepath($filepath);

    if (isset($info['description'])) {
      $profile->setDescription($info['description']);
    }

    if (isset($info['policies'])) {
      $v21_keys = ['parameters', 'severity'];
      foreach ($info['policies'] as $name => $metadata) {
        // Check for v2.0.x style profiles.
        if (!empty($metadata) && !count(array_intersect($v21_keys, array_keys($metadata)))) {
          throw new \Exception("{$info['title']} is a v2.0.x profile. Please upgrade $filepath to v2.2.x schema.");
        }
        $weight = array_search($name, array_keys($info['policies']));
        $profile->addPolicyDefinition(PolicyDefinition::createFromProfile($name, $weight, $metadata));
      }
    }

    if (isset($info['excluded_policies']) && is_array($info['excluded_policies'])) {
      $profile->addExcludedPolicies($info['excluded_policies']);
    }

    if (isset($info['include'])) {
      foreach ($info['include'] as $name) {
        $include = ProfileSource::loadProfileByName($name);
        $profile->addInclude($include);
      }
    }

    if (isset($info['format'])) {
      foreach ($info['format'] as $format => $options) {
        $profile->addFormatOptions(Format::create($format, $options));
      }
    }

    return $profile;
  }
public static function loadFromFile ( $ filepath ) { $ info = Yaml :: parseFile ( $ filepath ) ; $ name = str_replace ( '.profile.yml' , '' , pathinfo ( $ filepath , PATHINFO_BASENAME ) ) ; $ profile = new static ( ) ; $ profile -> setTitle ( $ info [ 'title' ] ) -> setName ( $ name ) -> setFilepath ( $ filepath ) ; if ( isset ( $ info [ 'description' ] ) ) { $ profile -> setDescription ( $ info [ 'description' ] ) ; } if ( isset ( $ info [ 'policies' ] ) ) { $ v21_keys = [ 'parameters' , 'severity' ] ; foreach ( $ info [ 'policies' ] as $ name => $ metadata ) { // Check for v2.0.x style profiles. if ( ! empty ( $ metadata ) && ! count ( array_intersect ( $ v21_keys , array_keys ( $ metadata ) ) ) ) { throw new \ Exception ( "{$info['title']} is a v2.0.x profile. Please upgrade $filepath to v2.2.x schema." ) ; } $ weight = array_search ( $ name , array_keys ( $ info [ 'policies' ] ) ) ; $ profile -> addPolicyDefinition ( PolicyDefinition :: createFromProfile ( $ name , $ weight , $ metadata ) ) ; } } if ( isset ( $ info [ 'excluded_policies' ] ) && is_array ( $ info [ 'excluded_policies' ] ) ) { $ profile -> addExcludedPolicies ( $ info [ 'excluded_policies' ] ) ; } if ( isset ( $ info [ 'include' ] ) ) { foreach ( $ info [ 'include' ] as $ name ) { $ include = ProfileSource :: loadProfileByName ( $ name ) ; $ profile -> addInclude ( $ include ) ; } } if ( isset ( $ info [ 'format' ] ) ) { foreach ( $ info [ 'format' ] as $ format => $ options ) { $ profile -> addFormatOptions ( Format :: create ( $ format , $ options ) ) ; } } return $ profile ; }
Load a profile from file.

@var $filepath string
Load a profile from file .