![]() 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-analytics/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Analytics\Model; use Magento\Analytics\Api\Data\LinkInterfaceFactory; use Magento\Analytics\Api\LinkProviderInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\UrlInterface; use Magento\Store\Model\StoreManagerInterface; /** * Provides link to file with collected report data. */ class LinkProvider implements LinkProviderInterface { /** * @var LinkInterfaceFactory */ private $linkFactory; /** * @var FileInfoManager */ private $fileInfoManager; /** * @var StoreManagerInterface */ private $storeManager; /** * @param LinkInterfaceFactory $linkInterfaceFactory * @param FileInfoManager $fileInfoManager * @param StoreManagerInterface $storeManager */ public function __construct( LinkInterfaceFactory $linkFactory, FileInfoManager $fileInfoManager, StoreManagerInterface $storeManager ) { $this->linkFactory = $linkFactory; $this->fileInfoManager = $fileInfoManager; $this->storeManager = $storeManager; } /** * Returns base url to file according to store configuration * * @param FileInfo $fileInfo * @return string */ private function getBaseUrl(FileInfo $fileInfo) { return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . $fileInfo->getPath(); } /** * Verify is requested file ready * * @param FileInfo $fileInfo * @return bool */ private function isFileReady(FileInfo $fileInfo) { return $fileInfo->getPath() && $fileInfo->getInitializationVector(); } /** * @inheritdoc */ public function get() { $fileInfo = $this->fileInfoManager->load(); if (!$this->isFileReady($fileInfo)) { throw new NoSuchEntityException(__('File is not ready yet.')); } return $this->linkFactory->create( [ 'url' => $this->getBaseUrl($fileInfo), 'initializationVector' => base64_encode($fileInfo->getInitializationVector()) ] ); } }