Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Service Class Reference

Public Member Functions

 __construct (\Magento\Framework\Filesystem $filesystem, \Magento\Framework\File\Size $fileSize, \Magento\Framework\Convert\DataSize $dataSize, \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, array $uploadLimits=[])
 
 getFileContent ($filePath)
 
 getCssUploadMaxSize ()
 
 getJsUploadMaxSize ()
 
 getCssUploadMaxSizeInMb ()
 
 getJsUploadMaxSizeInMb ()
 

Protected Member Functions

 _validateFileSize ($fileSize, $maxFileSize)
 

Protected Attributes

 $_filePath
 
 $_tmpDirectory
 
 $_fileSize
 
 $dataSize
 
 $_uploader
 
 $_uploaderFactory
 
 $_cssUploadLimit
 
 $_jsUploadLimit
 

Detailed Description

Definition at line 14 of file Service.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Filesystem  $filesystem,
\Magento\Framework\File\Size  $fileSize,
\Magento\Framework\Convert\DataSize  $dataSize,
\Magento\MediaStorage\Model\File\UploaderFactory  $uploaderFactory,
array  $uploadLimits = [] 
)

Constructor

Parameters
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\File\Size$fileSize
\Magento\Framework\Convert\DataSize$dataSize
\Magento\MediaStorage\Model\File\UploaderFactory$uploaderFactory
array$uploadLimitskeys are 'css' and 'js' for file type, values defines maximum file size, example: 2M

Definition at line 73 of file Service.php.

79  {
80  $this->_tmpDirectory = $filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
81  $this->_fileSize = $fileSize;
82  $this->_uploaderFactory = $uploaderFactory;
83  $this->dataSize = $dataSize;
84  if (isset($uploadLimits['css'])) {
85  $this->_cssUploadLimit = $uploadLimits['css'];
86  }
87  if (isset($uploadLimits['js'])) {
88  $this->_jsUploadLimit = $uploadLimits['js'];
89  }
90  }
$filesystem

Member Function Documentation

◆ _validateFileSize()

_validateFileSize (   $fileSize,
  $maxFileSize 
)
protected

Validate max file size

Parameters
int$fileSize
int$maxFileSize
Returns
bool

Definition at line 218 of file Service.php.

219  {
220  if ($fileSize > $maxFileSize) {
221  return false;
222  }
223  return true;
224  }

◆ getCssUploadMaxSize()

getCssUploadMaxSize ( )

Get css upload max size

Returns
int

Definition at line 160 of file Service.php.

161  {
162  return $this->_getMaxUploadSize($this->_cssUploadLimit);
163  }

◆ getCssUploadMaxSizeInMb()

getCssUploadMaxSizeInMb ( )

Get css upload max size in megabytes

Returns
float

Definition at line 196 of file Service.php.

197  {
198  return $this->_fileSize->getFileSizeInMb($this->getCssUploadMaxSize());
199  }

◆ getFileContent()

getFileContent (   $filePath)

Get uploaded file content

Parameters
string$filePath
Returns
string

Definition at line 150 of file Service.php.

151  {
152  return $this->_tmpDirectory->readFile($this->_tmpDirectory->getRelativePath($filePath));
153  }

◆ getJsUploadMaxSize()

getJsUploadMaxSize ( )

Get js upload max size

Returns
int

Definition at line 170 of file Service.php.

171  {
172  return $this->_getMaxUploadSize($this->_jsUploadLimit);
173  }

◆ getJsUploadMaxSizeInMb()

getJsUploadMaxSizeInMb ( )

Get js upload max size in megabytes

Returns
float

Definition at line 206 of file Service.php.

207  {
208  return $this->_fileSize->getFileSizeInMb($this->getJsUploadMaxSize());
209  }

Field Documentation

◆ $_cssUploadLimit

$_cssUploadLimit
protected

Definition at line 57 of file Service.php.

◆ $_filePath

$_filePath
protected

Definition at line 21 of file Service.php.

◆ $_fileSize

$_fileSize
protected

Definition at line 33 of file Service.php.

◆ $_jsUploadLimit

$_jsUploadLimit
protected

Definition at line 62 of file Service.php.

◆ $_tmpDirectory

$_tmpDirectory
protected

Definition at line 26 of file Service.php.

◆ $_uploader

$_uploader
protected

Definition at line 47 of file Service.php.

◆ $_uploaderFactory

$_uploaderFactory
protected

Definition at line 52 of file Service.php.

◆ $dataSize

$dataSize
protected

Definition at line 40 of file Service.php.


The documentation for this class was generated from the following file: