Exemplo n.º 1
0
 /**
  * Parses the XML from the legacy database.
  *
  * Returns only the data required by the FieldType, nothing more.
  *
  * @param string $xml
  *
  * @return array
  */
 protected function parseLegacyXml($xml)
 {
     $extractedData = array();
     $dom = new \DOMDocument();
     $dom->loadXml($xml);
     $ezimageTag = $dom->documentElement;
     if (!$ezimageTag->hasAttribute('url')) {
         throw new \RuntimeException('Missing attribute "url" in <ezimage/> tag.');
     }
     if (($legacyUrl = $ezimageTag->getAttribute('url')) === '') {
         // Detected XML considered "empty" by the legacy storage
         return null;
     }
     $url = $this->urlRedecorator->redecorateFromTarget($legacyUrl);
     $extractedData['id'] = $this->imageIoService->loadBinaryFileByUri($url)->id;
     if (!$ezimageTag->hasAttribute('filename')) {
         throw new \RuntimeException('Missing attribute "filename" in <ezimage/> tag.');
     }
     $extractedData['fileName'] = $ezimageTag->getAttribute('filename');
     $extractedData['width'] = $ezimageTag->getAttribute('width');
     $extractedData['height'] = $ezimageTag->getAttribute('height');
     $extractedData['mime'] = $ezimageTag->getAttribute('mime_type');
     if (!$ezimageTag->hasAttribute('alternative_text')) {
         throw new \RuntimeException('Missing attribute "alternative_text" in <ezimage/> tag.');
     }
     $extractedData['alternativeText'] = $ezimageTag->getAttribute('alternative_text');
     return $extractedData;
 }
Exemplo n.º 2
0
 public function extractFilesFromXml($xml)
 {
     if (empty($xml)) {
         // Empty image value
         return null;
     }
     $files = array();
     $dom = new \DOMDocument();
     $dom->loadXml($xml);
     if ($dom->documentElement->hasAttribute('dirpath')) {
         $url = $dom->documentElement->getAttribute('url');
         if (empty($url)) {
             return null;
         }
         $files['original'] = $this->redecorator->redecorateFromTarget($url);
         /** @var \DOMNode $childNode */
         foreach ($dom->documentElement->childNodes as $childNode) {
             if ($childNode->nodeName != 'alias') {
                 continue;
             }
             $files[$childNode->getAttribute('name')] = $this->redecorator->redecorateFromTarget($childNode->getAttribute('url'));
         }
         return $files;
     }
     return null;
 }
Exemplo n.º 3
0
 public function testRedecorateFromTarget()
 {
     $this->targetDecoratorMock->expects($this->once())->method('undecorate')->with('/var/test/storage/images/file.png')->will($this->returnValue('images/file.png'));
     $this->sourceDecoratorMock->expects($this->once())->method('decorate')->with('images/file.png')->will($this->returnValue('http://static.example.com/images/file.png'));
     self::assertEquals('http://static.example.com/images/file.png', $this->redecorator->redecorateFromTarget('/var/test/storage/images/file.png'));
 }