Exemplo n.º 1
0
 /**
  * Create an instance of pmJSCookMenu from a yaml file.
  * 
  * @param string $yaml_file The yaml file path
  * @return pmJSCookMenu
  */
 public static function createFromYaml($yaml_file)
 {
     $yaml = sfYaml::load($yaml_file);
     $yaml = array_pop($yaml);
     $root = new pmJSCookMenu();
     $root_attrs = array("credentials", "description", "icon", "orientation", "target", "theme", "title", "url");
     foreach ($root_attrs as $attr) {
         if (isset($yaml[$attr])) {
             $method = "set" . ucfirst($attr);
             call_user_func(array($root, $method), $yaml[$attr]);
             unset($yaml[$attr]);
         }
     }
     if (isset($yaml["root"]) && $yaml["root"] == true) {
         $root->setRoot();
         unset($yaml["root"]);
     }
     $separator_count = 0;
     foreach ($yaml as $name => $arr_menu) {
         if ($name == "separator") {
             $item = new pmJSCookMenuSeparator();
             $root->addChild("{$name}{$separator_count}", $item);
             $separator_count++;
         } else {
             $item = self::createMenu($arr_menu);
             $root->addChild($name, $item);
         }
     }
     return $root;
 }