Sulu\Component\Content\Metadata\Loader\XmlLegacyLoader::load PHP Method

load() public method

public load ( $resource, $type = 'page' )
    public function load($resource, $type = 'page')
    {
        // init running vars
        $tags = [];
        $schemaPath = __DIR__ . static::SCHEME_PATH;
        // read file
        $xmlDocument = XmlUtils::loadFile($resource, function (\DOMDocument $dom) use($resource, $schemaPath) {
            $dom->documentURI = $resource;
            $dom->xinclude();
            return @$dom->schemaValidate($schemaPath);
        });
        // generate xpath for file
        $xpath = new \DOMXPath($xmlDocument);
        $xpath->registerNamespace('x', 'http://schemas.sulu.io/template/template');
        // init result
        $result = $this->loadTemplateAttributes($resource, $xpath, $type);
        // load properties
        $result['properties'] = $this->loadProperties($result['key'], '/x:template/x:properties/x:*', $tags, $xpath);
        // check if required properties are existing
        foreach ($this->requiredPropertyNames as $requiredPropertyName) {
            $requiredPropertyNameFound = false;
            if (array_key_exists($requiredPropertyName, $result['properties'])) {
                $requiredPropertyNameFound = true;
            }
            // check all section properties as well
            foreach ($result['properties'] as $property) {
                if (!$requiredPropertyNameFound && $property['type'] == 'section' && array_key_exists($requiredPropertyName, $property['properties'])) {
                    $requiredPropertyNameFound = true;
                }
            }
            if (!$requiredPropertyNameFound) {
                throw new RequiredPropertyNameNotFoundException($result['key'], $requiredPropertyName);
            }
        }
        // FIXME until excerpt-template is no page template anymore
        // - https://github.com/sulu-io/sulu/issues/1220#issuecomment-110704259
        if (!array_key_exists('internal', $result) || !$result['internal']) {
            if (isset($this->requiredTagNames[$type])) {
                foreach ($this->requiredTagNames[$type] as $requiredTagName) {
                    if (!array_key_exists($requiredTagName, $tags)) {
                        throw new RequiredTagNotFoundException($result['key'], $requiredTagName);
                    }
                }
            }
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = 'page')
 {
     $data = parent::load($resource, $type);
     $data = $this->normalizeStructureData($data);
     $structure = new StructureMetadata();
     $structure->name = $data['key'];
     $structure->cacheLifetime = $data['cacheLifetime'];
     $structure->controller = $data['controller'];
     $structure->internal = $data['internal'] === 'true';
     $structure->view = $data['view'];
     $structure->tags = $data['tags'];
     $structure->parameters = $data['params'];
     $structure->resource = $resource;
     $this->mapMeta($structure, $data['meta']);
     foreach ($data['properties'] as $propertyName => $dataProperty) {
         $structure->children[$propertyName] = $this->createProperty($propertyName, $dataProperty);
     }
     $structure->burnProperties();
     return $structure;
 }
All Usage Examples Of Sulu\Component\Content\Metadata\Loader\XmlLegacyLoader::load