public function getStructureMetadata($type, $structureType = null)
{
$cacheKey = $type . $structureType;
if (isset($this->cache[$cacheKey])) {
return $this->cache[$cacheKey];
}
$this->assertExists($type);
if (!$structureType) {
$structureType = $this->getDefaultStructureType($type);
}
if (!$structureType) {
return;
}
$cachePath = sprintf('%s%s%s%s', $this->cachePath, DIRECTORY_SEPARATOR, Inflector::camelize($type), Inflector::camelize($structureType));
$cache = new ConfigCache($cachePath, $this->debug);
if ($this->debug || !$cache->isFresh()) {
$paths = $this->getPaths($type);
// reverse paths, so that the last path overrides previous ones
$fileLocator = new FileLocator(array_reverse($paths));
try {
$filePath = $fileLocator->locate(sprintf('%s.xml', $structureType));
} catch (\InvalidArgumentException $e) {
throw new Exception\StructureTypeNotFoundException(sprintf('Could not load structure type "%s" for document type "%s", looked in "%s"', $structureType, $type, implode('", "', $paths)), null, $e);
}
$metadata = $this->loader->load($filePath, $type);
$resources = [new FileResource($filePath)];
$cache->write(serialize($metadata), $resources);
}
$structure = unserialize(file_get_contents($cachePath));
$this->cache[$cacheKey] = $structure;
return $structure;
}