![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-adobe-stock-image/Model/Extract/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\AdobeStockImage\Model\Extract; use Magento\Framework\Api\Search\Document; use Magento\MediaGalleryApi\Api\Data\KeywordInterface; use Magento\MediaGalleryApi\Api\Data\KeywordInterfaceFactory; /** * Keywords extractor */ class Keywords { private const DOCUMENT_FIELD_KEYWORDS = 'keywords'; private const DOCUMENT_FIELD_KEYWORD_NAME = 'name'; private const KEYWORD_FIELD_KEYWORD_NAME = 'keyword'; /** * @var KeywordInterfaceFactory */ private $keywordFactory; /** * @param KeywordInterfaceFactory $keywordFactory */ public function __construct( KeywordInterfaceFactory $keywordFactory ) { $this->keywordFactory = $keywordFactory; } /** * Convert search document to the asset object * * @param Document $document * @return KeywordInterface[] */ public function convert(Document $document): array { $attribute = $document->getCustomAttribute(self::DOCUMENT_FIELD_KEYWORDS); if (!$attribute || !is_array($attribute->getValue())) { return []; } $keywords = []; foreach ($attribute->getValue() as $keywordData) { $keywords[] = $this->keywordFactory->create( [ self::KEYWORD_FIELD_KEYWORD_NAME => $keywordData[self::DOCUMENT_FIELD_KEYWORD_NAME] ] ); } return $keywords; } }