path = $path; if (!file_exists("$this->path/metadata/hosts")) { throw new Exception("Invalid hostinfo path: $this->path"); } $this->hosts = null; $this->_data = array(); } protected function load_hosts() { $hosts = Yaml::parse( file_get_contents("$this->path/metadata/hosts")); $this->hosts = $hosts['hosts']; } protected function load_host($host) { $this->_data[$host] = Yaml::parse( file_get_contents("$this->path/$host")); } public function get_hosts() { if ($this->hosts === null) { $this->load_hosts(); } return $this->hosts; } public function get_host($host) { if (!array_key_exists($host, $this->_data)) { $this->load_host($host); } return $this->_data[$host]; } public function get_data() { $data = array(); foreach ($this->get_hosts() as $host) { $data[$host] = $this->get_host($host); } return $data; } } // vim: set ts=4 sw=4 tw=0 et :