Example #1
0
 /**
  * Loads a YAML module descriptor file
  * @param URL The URL of the file to load
  * @param clear default: false / Clear all the modules and then load the file
  * 
  * @throws IOException
  * @throws FileNotFoundException
  * @throws ParseException
  */
 public function load($URL, $clear = false)
 {
     // Parsing the YAML file
     try {
         $parsed = Yaml\Yaml::parse(FileLoader::load($URL));
     } catch (Yaml\Exception\ParseException $e) {
         throw new ParseException("The module descriptor file could not be parsed. There must be an error in the YAML syntax: " . $e->getMessage());
     }
     // Testing the structure of the file
     if (count($parsed) != 1 || !array_key_exists("modules", $parsed)) {
         throw new ParseException("The module descriptor file must contain only one parent node name \"modules\".");
     }
     foreach ($parsed["modules"] as $mod) {
         if (!is_array($mod)) {
             throw new ParseException("The \"modules\" root node must contain only array entries");
         }
         if (!array_key_exists("name", $mod) || !array_key_exists("description", $mod)) {
             throw new ParseException("Every module must have a \"name\" and \"description\" attribute");
         }
         if (strpos($mod["name"], " ") !== false) {
             throw new ParseException("Only Alpha-numerical values are allowed fot he module name");
         }
     }
     if ($clear) {
         $this->clear();
     }
     foreach ($parsed["modules"] as $mod) {
         $this->register(new Module($mod["name"], $mod["description"]));
     }
 }
Example #2
0
 public function load($URL, $clear = false)
 {
     // Parsing the YAML file
     try {
         $parsed = Yaml\Yaml::parse(FileLoader::load($URL));
     } catch (FileNotFoundException $e) {
         return false;
     } catch (Yaml\Exception\ParseException $e) {
         throw new ParseException("The configuration file could not be parsed. There must be an error in the YAML syntax: " . $e->getMessage());
     }
     if ($clear) {
         $this->clear();
     }
     $this->add($parsed);
     return true;
 }