Sulu\Component\Content\Metadata\Factory\StructureMetadataFactory::getStructureMetadata PHP Method

getStructureMetadata() public method

public getStructureMetadata ( $type, $structureType = null )
    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;
    }

Usage Example

コード例 #1
0
 /**
  * It should get a legacy structure bridge.
  */
 public function testGetStructure()
 {
     $structureType = 'content';
     $documentType = 'page';
     $this->factory->getStructureMetadata($documentType, $structureType)->willReturn($this->structure->reveal());
     $bridge = $this->structureManager->getStructure($structureType, $documentType);
     $this->assertInstanceOf(StructureBridge::class, $bridge);
 }
All Usage Examples Of Sulu\Component\Content\Metadata\Factory\StructureMetadataFactory::getStructureMetadata