Downloadable Products Download Helper @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Definition at line 17 of file Download.php.
◆ __construct()
- Parameters
-
\Magento\Framework\App\Helper\Context | $context | |
File | $downloadableFile | |
\Magento\MediaStorage\Helper\File\Storage\Database | $coreFileStorageDb | |
Filesystem | $filesystem | |
\Magento\Framework\Session\SessionManagerInterface | $session | |
Filesystem\File\ReadFactory | $fileReadFactory | |
Definition at line 119 of file Download.php.
127 parent::__construct($context);
128 $this->_downloadableFile = $downloadableFile;
129 $this->_coreFileStorageDb = $coreFileStorageDb;
◆ _getHandle()
Retrieve Resource file handle (socket, file pointer etc)
- Returns
- \Magento\Framework\Filesystem\File\ReadInterface
- Exceptions
-
Definition at line 141 of file Download.php.
143 if (!$this->_resourceFile) {
144 throw new CoreException(
__(
'Please set resource file and link type.'));
147 if ($this->_handle ===
null) {
148 if ($this->_linkType == self::LINK_TYPE_URL) {
150 $protocol = strtolower(parse_url(
$path, PHP_URL_SCHEME));
155 $this->_handle = $this->fileReadFactory->create(
$path, $protocol);
156 }
elseif ($this->_linkType == self::LINK_TYPE_FILE) {
158 $fileExists = $this->_downloadableFile->ensureFileInFilesystem($this->_resourceFile);
160 $this->_handle = $this->_workingDirectory->openFile($this->_resourceFile);
162 throw new CoreException(
__(
'Invalid download link type.'));
165 throw new CoreException(
__(
'Invalid download link type.'));
elseif(isset( $params[ 'redirect_parent']))
◆ getContentDisposition()
getContentDisposition |
( |
|
$store = null | ) |
|
Use Content-Disposition: attachment
- Parameters
-
- Returns
- bool @SuppressWarnings(PHPMD.BooleanGetMethodName)
Definition at line 283 of file Download.php.
285 return $this->scopeConfig->getValue(
286 self::XML_PATH_CONTENT_DISPOSITION,
287 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
◆ getContentType()
Return MIME type of a file.
- Returns
- string
Definition at line 186 of file Download.php.
189 if ($this->_linkType == self::LINK_TYPE_FILE) {
193 $this->_workingDirectory->getAbsolutePath($this->_resourceFile)
198 return $this->_downloadableFile->getFileType($this->_resourceFile);
200 }
elseif ($this->_linkType == self::LINK_TYPE_URL) {
201 return $this->_handle->stat($this->_resourceFile)[
'type'];
elseif(isset( $params[ 'redirect_parent']))
◆ getFilename()
Return name of the file
- Returns
- string
Definition at line 211 of file Download.php.
214 if ($this->_linkType == self::LINK_TYPE_FILE) {
215 return pathinfo($this->_resourceFile, PATHINFO_BASENAME);
216 }
elseif ($this->_linkType == self::LINK_TYPE_URL) {
217 $stat = $this->_handle->stat($this->_resourceFile);
218 if (isset($stat[
'disposition'])) {
219 $contentDisposition = explode(
'; ', $stat[
'disposition']);
220 if (!empty($contentDisposition[1]) && preg_match(
221 '/filename=([^ ]+)/',
222 $contentDisposition[1],
229 $fileName = @pathinfo($this->_resourceFile, PATHINFO_BASENAME);
elseif(isset( $params[ 'redirect_parent']))
◆ getFileSize()
Retrieve file size in bytes
- Returns
- int
Definition at line 176 of file Download.php.
178 return $this->
_getHandle()->stat($this->_resourceFile)[
'size'];
◆ output()
Output file contents
- Returns
- void
Definition at line 267 of file Download.php.
270 $this->_session->writeClose();
271 while (
true == ($buffer =
$handle->read(1024))) {
◆ setResource()
setResource |
( |
|
$resourceFile, |
|
|
|
$linkType = self::LINK_TYPE_FILE |
|
) |
| |
Set resource file for download
- Parameters
-
string | $resourceFile | |
string | $linkType | |
- Returns
- $this
- Exceptions
-
Definition at line 245 of file Download.php.
247 if (self::LINK_TYPE_FILE == $linkType) {
249 if (preg_match(
'#\.\.[\\\/]#', $resourceFile)) {
250 throw new \InvalidArgumentException(
251 'Requested file may not include parent directory traversal ("../", "..\\" notation)' 256 $this->_resourceFile = $resourceFile;
257 $this->_linkType = $linkType;
◆ $_contentType
$_contentType = 'application/octet-stream' |
|
protected |
◆ $_coreFileStorageDb
◆ $_downloadableFile
◆ $_fileName
◆ $_filesystem
◆ $_handle
◆ $_linkType
$_linkType = self::LINK_TYPE_FILE |
|
protected |
◆ $_resourceFile
◆ $_session
◆ $_urlHeaders
◆ $_workingDirectory
◆ $fileReadFactory
◆ LINK_TYPE_FILE
const LINK_TYPE_FILE = 'file' |
◆ LINK_TYPE_URL
const LINK_TYPE_URL = 'url' |
◆ XML_PATH_CONTENT_DISPOSITION
const XML_PATH_CONTENT_DISPOSITION = 'catalog/downloadable/content_disposition' |
The documentation for this class was generated from the following file: