/** * Load a spark spec file and tries to validate it * @param string $filepath * @throws SpecValidationException * @return Spark_spec */ public static function loadFromDirectory($filepath) { $spec = array(); $filepath = rtrim($filepath, '/') . '/'; $filename = 'spark.info'; $specfile = $filepath . $filename; /* Check that the spark file exists */ if (!file_exists($specfile)) { throw new SpecValidationException("The '{$filename}' does not exist in the spark's root: See http://getsparks.org/spec-format"); } /* Load it, it should have a $spec setup inside it */ $spec = Yaml::parse_file($specfile); if (!is_array($spec)) { throw new SpecValidationException("The '{$filename}' does not contain valid spec information: See http://getsparks.org/spec-format"); } /* Create a spec instance */ $spark = new self(); $spark->_specFile = $specfile; $spark->_sparkPath = $filepath; /* Check for each individual component and load it */ if (!array_key_exists('name', $spec)) { throw new SpecValidationException("The spec does not contain a spec name: {$filename}"); } $spark->name = $spec['name']; if (!array_key_exists('version', $spec)) { throw new SpecValidationException("The spec does not contain a spec version: {$filename}"); } $spark->version = $spec['version']; if (!array_key_exists('compatibility', $spec)) { throw new SpecValidationException("The spec does not contain a compatibility (tested up until): {$filename}"); } $spark->compatibility = $spec['compatibility']; if (!array_key_exists('dependencies', $spec)) { $spark->dependencies = array(); } else { $spark->dependencies = $spec['dependencies']; } if (!array_key_exists('tags', $spec)) { $spark->tags = array(); } else { $spark->tags = $spec['tags']; } $spark->validate(); return $spark; }