/** * * @return SimpleXmlElement */ protected function loadMountpointsFile() { try { if (!is_file($this->filePath)) { throw new EyeFileNotFoundException($this->filePath); } $xmlReader = new XmlStreamReader(new FileInputStream($this->filePath)); $xml = null; $xmlReader->read($xml); $xmlReader->close(); return $xml; } catch (Exception $e) { throw new EyeIOException('Unable to load mountpoints configuration at ' . $this->filePath . '.', 0, $e); } }
/** * TODO * * @param string $id The identifier used to find the right data to read. * @param array $params Additional params implementation-dependant. * @return IMetaData */ public function retrieveMeta($id, $params = null) { $metaDataCacheCell = null; if (isset(self::$Cache[$this->filePath])) { $metaDataCacheCell = self::$Cache[$this->filePath]; } else { $xml = null; try { $xmlReader = new XmlStreamReader(new FileInputStream($this->filePath)); $xmlReader->read($xml); } catch (EyeFileNotFoundException $e) { // file not found: no big deal, it means there's no metadata so return null return null; } catch (Exception $e) { // other type of exception: it might be a problem, log it $logger = Logger::getLogger('system.services.Meta.SimpleXMLMetaProvider'); $logger->warn('Error trying to read XML metadata file at ' . $this->filePath); if ($logger->isDebugEnabled()) { $logger->debug((string) $e); } //close stream try { if (is_object($xmlReader)) { $xmlReader->close(); } } catch (Exception $e) { } return null; } //close stream try { if (is_object($xmlReader)) { $xmlReader->close(); } } catch (Exception $e) { } // Create cache cell (simple associative array) $metaDataCacheCell = array(); foreach ($xml->children() as $key => $value) { // Ommited keys are not allowed here if ((string) $value['key'] === '') { throw new EyeXMLInvalidDocumentException('Missing "key" attribute on node: ' . $value->asXml()); } if (isset($value['type']) && $value['type'] == 'array') { $metaDataCacheCell[(string) $value['key']] = $this->readArray($value); } else { $metaDataCacheCell[(string) $value['key']] = (string) $value; } } } $metaDataClass = $this->metaDataClass; $metaData = new $metaDataClass(); $metaData->setAll($metaDataCacheCell); return $metaData; }