Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LinkProvider.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Analytics\Api\Data\LinkInterfaceFactory;
13 
18 {
22  private $linkFactory;
23 
27  private $fileInfoManager;
28 
32  private $storeManager;
33 
39  public function __construct(
40  LinkInterfaceFactory $linkFactory,
41  FileInfoManager $fileInfoManager,
42  StoreManagerInterface $storeManager
43  ) {
44  $this->linkFactory = $linkFactory;
45  $this->fileInfoManager = $fileInfoManager;
46  $this->storeManager = $storeManager;
47  }
48 
55  private function getBaseUrl(FileInfo $fileInfo)
56  {
57  return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . $fileInfo->getPath();
58  }
59 
66  private function isFileReady(FileInfo $fileInfo)
67  {
68  return $fileInfo->getPath() && $fileInfo->getInitializationVector();
69  }
70 
74  public function get()
75  {
76  $fileInfo = $this->fileInfoManager->load();
77  if (!$this->isFileReady($fileInfo)) {
78  throw new NoSuchEntityException(__('File is not ready yet.'));
79  }
80  return $this->linkFactory->create(
81  [
82  'url' => $this->getBaseUrl($fileInfo),
83  'initializationVector' => base64_encode($fileInfo->getInitializationVector())
84  ]
85  );
86  }
87 }
$storeManager
__()
Definition: __.php:13