Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ImageExtractor.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Model;
7 
11 
13 {
21  public function process(\DOMElement $mediaNode, $mediaParentTag)
22  {
23  $result = [];
25  $moduleNameImage = $mediaNode->getAttribute('module');
26  foreach ($mediaNode->getElementsByTagName(ImageEntryConverter::MEDIA_TYPE_CODE) as $node) {
27  $imageId = $node->getAttribute('id');
28  $result[$mediaParentTag][$moduleNameImage][Image::MEDIA_TYPE_CONFIG_NODE][$imageId]['type']
29  = $node->getAttribute('type');
30  foreach ($node->childNodes as $attribute) {
31  if ($attribute->nodeType != XML_ELEMENT_NODE) {
32  continue;
33  }
34  $attributeTagName = $attribute->tagName;
35  if ((bool)$attribute->getAttribute('xsi:nil') !== true) {
36  if ($attributeTagName === 'background') {
37  $nodeValue = $this->processImageBackground($attribute->nodeValue);
38  } elseif ($attributeTagName === 'width' || $attributeTagName === 'height') {
39  $nodeValue = intval($attribute->nodeValue);
40  } else {
41  $nodeValue = $attribute->nodeValue;
42  }
43  } else {
44  $nodeValue = null;
45  }
46  $result[$mediaParentTag][$moduleNameImage][Image::MEDIA_TYPE_CONFIG_NODE][$imageId][$attribute->tagName]
47  = $nodeValue;
48  }
49  }
50 
51  return $result;
52  }
53 
60  private function processImageBackground($backgroundString)
61  {
62  $pattern = '#\[(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\]#';
63  $backgroundArray = [];
64  if (preg_match($pattern, $backgroundString, $backgroundArray)) {
65  array_shift($backgroundArray);
66  $backgroundArray = array_map('intval', $backgroundArray);
67  }
68  return $backgroundArray;
69  }
70 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$pattern
Definition: website.php:22
process(\DOMElement $childNode, $mediaParentTag)
const MEDIA_TYPE_CODE