/** * Run application * * @return \Magento\Framework\App\ResponseInterface * @throws \LogicException */ public function launch() { if (!$this->_mediaDirectory) { $config = $this->_objectManager->create('Magento\\MediaStorage\\Model\\File\\Storage\\Config', ['cacheFile' => $this->_configCacheFile]); $config->save(); $this->_mediaDirectory = str_replace($this->_workingDirectory, '', $config->getMediaDirectory()); $allowedResources = $config->getAllowedResources(); $this->_relativeFileName = str_replace($this->_mediaDirectory . '/', '', $this->_request->getPathInfo()); $isAllowed = $this->_isAllowed; if (!$isAllowed($this->_relativeFileName, $allowedResources)) { throw new \LogicException('The specified path is not allowed.'); } } if (0 !== stripos($this->_request->getPathInfo(), $this->_mediaDirectory . '/')) { throw new \LogicException('The specified path is not within media directory.'); } $sync = $this->_objectManager->get('Magento\\MediaStorage\\Model\\File\\Storage\\Synchronization'); $sync->synchronize($this->_relativeFileName, $this->_request->getFilePath()); if ($this->directory->isReadable($this->directory->getRelativePath($this->_request->getFilePath()))) { $this->_response->setFilePath($this->_request->getFilePath()); } else { $this->_response->setHttpResponseCode(404); } return $this->_response; }
/** * {@inheritdoc} */ public function setFilePath($path) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setFilePath'); if (!$pluginInfo) { return parent::setFilePath($path); } else { return $this->___callPlugins('setFilePath', func_get_args(), $pluginInfo); } }
/** * Run application * * @return Response * @throws \LogicException */ public function launch() { if ($this->mediaDirectoryPath !== $this->directory->getAbsolutePath()) { // Path to media directory changed or absent - update the config /** @var \Magento\MediaStorage\Model\File\Storage\Config $config */ $config = $this->configFactory->create(['cacheFile' => $this->configCacheFile]); $config->save(); $this->mediaDirectoryPath = $config->getMediaDirectory(); $allowedResources = $config->getAllowedResources(); $isAllowed = $this->isAllowed; if (!$isAllowed($this->relativeFileName, $allowedResources)) { throw new \LogicException('The specified path is not allowed.'); } } /** @var \Magento\MediaStorage\Model\File\Storage\Synchronization $sync */ $sync = $this->syncFactory->create(['directory' => $this->directory]); $sync->synchronize($this->relativeFileName); if ($this->directory->isReadable($this->relativeFileName)) { $this->response->setFilePath($this->directory->getAbsolutePath($this->relativeFileName)); } else { $this->response->setHttpResponseCode(404); } return $this->response; }