Exemplo n.º 1
0
 /**
  * Parse an array of DOMElement to array of Resource models
  *
  * @param [DOMElement]  $resourcesListElements
  * @return array
  */
 public function map(array $resourcesListElements)
 {
     $resources = [];
     foreach ($resourcesListElements as $resourceElement) {
         $resource = new Resource();
         $resource->setHref(Marshaller::getDOMElementAttributeAs($resourceElement, 'href'));
         $resource->setIdentifier(Marshaller::getDOMElementAttributeAs($resourceElement, 'identifier'));
         $resource->setType(Marshaller::getDOMElementAttributeAs($resourceElement, 'type'));
         // Mapping to File models
         $fileListElements = Marshaller::getChildElementsByTagName($resourceElement, 'file');
         $resource->setFiles($this->mapFileElements($fileListElements));
         // Mapping to Dependency models
         $dependencyListElements = Marshaller::getChildElementsByTagName($resourceElement, 'dependency');
         $resource->setDependencies($this->mapDependencyElements($dependencyListElements));
         // Mapping its metadata
         $metadataListElements = Marshaller::getChildElementsByTagName($resourceElement, 'metadata');
         if (count($metadataListElements) > 0) {
             $metadataMapper = new MetadataMapper();
             $flattenedMetadatas = $metadataMapper->map($metadataListElements[0]);
             $resource->setMetadata($flattenedMetadatas);
         }
         // Resource must have unique id ??
         $resources[$resource->getIdentifier()] = $resource;
     }
     return $resources;
 }
Exemplo n.º 2
0
 public function parseManifestElement(\DOMElement $rootElement)
 {
     // Manifest mapping start!
     $manifest = new Manifest();
     $manifest->setIdentifier(Marshaller::getDOMElementAttributeAs($rootElement, 'identifier'));
     // Mapping <resource>(s) to Resource model
     $resourcesElement = Marshaller::getChildElementsByTagName($rootElement, 'resources');
     if (!empty($resourcesElement)) {
         if (count($resourcesElement) !== 1) {
             throw new MappingException('Resources tag must occur once');
         }
         $resourceMapper = new ResourcesMapper();
         $resourcesListElements = Marshaller::getChildElementsByTagName($resourcesElement[0], 'resource');
         $resources = $resourceMapper->map($resourcesListElements);
         $manifest->setResources($resources);
     }
     // Mapping <organisation>(s) to Organisation model
     $organizationElements = Marshaller::getChildElementsByTagName($rootElement, 'organizations');
     if (!empty($organizationElements)) {
         if (count($organizationElements) !== 1) {
             throw new MappingException('Organisations tag must occur once');
         }
         $organisationsMapper = new OrganizationsMapper();
         $organisationListElements = Marshaller::getChildElementsByTagName($organizationElements[0], 'organization');
         $organisations = $organisationsMapper->map($organisationListElements);
         $manifest->setOrganizations($organisations);
     }
     // Mapping package Metadata
     $metadataElement = Marshaller::getChildElementsByTagName($rootElement, 'metadata');
     if (!empty($metadataElement)) {
         if (count($metadataElement) !== 1) {
             throw new MappingException('Metadata tag must occur once');
         }
         $metadataMapper = new MetadataMapper();
         $manifest->setMetadata($metadataMapper->map($metadataElement[0]));
     }
     // Mapping sub-manifest
     $subManifestElement = Marshaller::getChildElementsByTagName($rootElement, 'manifest');
     if (!empty($subManifestElement)) {
         if (count($subManifestElement) !== 1) {
             throw new MappingException('Manifest tag must occur once');
         }
         $manifest->setManifest($this->parseManifestElement($subManifestElement[0]));
     }
     return $manifest;
 }