Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
File Class Reference
Inheritance diagram for File:
Value AbstractModel ValueInterface DataObject Image File Logo Favicon Logo Pdf Image Favicon Logo Logo

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, \Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface $requestData, Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 validateMaxSize ($filePath)
 
- Public Member Functions inherited from Value
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 isValueChanged ()
 
 getOldValue ()
 
 getFieldsetDataValue ($key)
 
 afterSave ()
 
 afterDelete ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 getFileData ()
 
 _addWhetherScopeInfo ()
 
 _getUploadDir ()
 
 getUploadDirPath ($uploadDir)
 
 _prependScopeInfo ($path)
 
 _appendScopeInfo ($path)
 
 _getAllowedExtensions ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_requestData
 
 $_maxFileSize = 0
 
 $_filesystem
 
 $_mediaDirectory
 
 $_uploaderFactory
 
- Protected Attributes inherited from Value
 $_eventPrefix = 'config_data'
 
 $_eventObject = 'config_data'
 
 $_config
 
 $cacheTypeList
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Data Fields inherited from ValueInterface
const ENTITY = 'config_data'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

System config file field backend model

@SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.ExcessiveParameterList) @api

Since
100.0.2

Definition at line 21 of file File.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\App\Config\ScopeConfigInterface  $config,
\Magento\Framework\App\Cache\TypeListInterface  $cacheTypeList,
\Magento\MediaStorage\Model\File\UploaderFactory  $uploaderFactory,
\Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface  $requestData,
Filesystem  $filesystem,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\App\Config\ScopeConfigInterface$config
\Magento\Framework\App\Cache\TypeListInterface$cacheTypeList
\Magento\MediaStorage\Model\File\UploaderFactory$uploaderFactory
\Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface$requestData
Filesystem$filesystem
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 62 of file File.php.

73  {
74  $this->_uploaderFactory = $uploaderFactory;
75  $this->_requestData = $requestData;
76  $this->_filesystem = $filesystem;
77  $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
78  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
79  }
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12
$filesystem

Member Function Documentation

◆ _addWhetherScopeInfo()

_addWhetherScopeInfo ( )
protected

Makes a decision about whether to add info about the scope.

Returns
boolean

Definition at line 171 of file File.php.

172  {
173  $fieldConfig = $this->getFieldConfig();
174  $dirParams = array_key_exists('upload_dir', $fieldConfig) ? $fieldConfig['upload_dir'] : [];
175  return is_array($dirParams) && array_key_exists('scope_info', $dirParams) && $dirParams['scope_info'];
176  }

◆ _appendScopeInfo()

_appendScopeInfo (   $path)
protected

Add scope info to path

E.g. 'path/stores/2' , 'path/websites/3', 'path/default'

Parameters
string$path
Returns
string

Definition at line 249 of file File.php.

250  {
251  $path .= '/' . $this->getScope();
252  if (ScopeConfigInterface::SCOPE_TYPE_DEFAULT != $this->getScope()) {
253  $path .= '/' . $this->getScopeId();
254  }
255  return $path;
256  }

◆ _getAllowedExtensions()

_getAllowedExtensions ( )
protected

Getter for allowed extensions of uploaded files

Returns
array

Definition at line 263 of file File.php.

264  {
265  return [];
266  }

◆ _getUploadDir()

_getUploadDir ( )
protected

Return path to directory for upload file

Returns
string
Exceptions

Definition at line 184 of file File.php.

185  {
186  $fieldConfig = $this->getFieldConfig();
187 
188  if (!array_key_exists('upload_dir', $fieldConfig)) {
189  throw new \Magento\Framework\Exception\LocalizedException(
190  __('The base directory to upload file is not specified.')
191  );
192  }
193 
194  if (is_array($fieldConfig['upload_dir'])) {
195  $uploadDir = $fieldConfig['upload_dir']['value'];
196  if (array_key_exists('scope_info', $fieldConfig['upload_dir'])
197  && $fieldConfig['upload_dir']['scope_info']
198  ) {
199  $uploadDir = $this->_appendScopeInfo($uploadDir);
200  }
201 
202  if (array_key_exists('config', $fieldConfig['upload_dir'])) {
203  $uploadDir = $this->getUploadDirPath($uploadDir);
204  }
205  } else {
206  $uploadDir = (string)$fieldConfig['upload_dir'];
207  }
208 
209  return $uploadDir;
210  }
__()
Definition: __.php:13

◆ _prependScopeInfo()

_prependScopeInfo (   $path)
protected

Prepend path with scope info

E.g. 'stores/2/path' , 'websites/3/path', 'default/path'

Parameters
string$path
Returns
string

Definition at line 232 of file File.php.

233  {
234  $scopeInfo = $this->getScope();
235  if (ScopeConfigInterface::SCOPE_TYPE_DEFAULT != $this->getScope()) {
236  $scopeInfo .= '/' . $this->getScopeId();
237  }
238  return $scopeInfo . '/' . $path;
239  }

◆ getFileData()

getFileData ( )
protected

Receiving uploaded file data

Returns
array
Since
100.1.0

Definition at line 130 of file File.php.

131  {
132  $file = [];
133  $value = $this->getValue();
134  $tmpName = $this->_requestData->getTmpName($this->getPath());
135  if ($tmpName) {
136  $file['tmp_name'] = $tmpName;
137  $file['name'] = $this->_requestData->getName($this->getPath());
138  } elseif (!empty($value['tmp_name'])) {
139  $file['tmp_name'] = $value['tmp_name'];
140  $file['name'] = isset($value['value']) ? $value['value'] : $value['name'];
141  }
142 
143  return $file;
144  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16

◆ getUploadDirPath()

getUploadDirPath (   $uploadDir)
protected

Retrieve upload directory path

Parameters
string$uploadDir
Returns
string
Since
100.1.0

Definition at line 219 of file File.php.

220  {
221  return $this->_mediaDirectory->getAbsolutePath($uploadDir);
222  }

◆ validateMaxSize()

validateMaxSize (   $filePath)

Validation callback for checking max file size

Parameters
string$filePathPath to temporary uploaded file
Returns
void
Exceptions

Definition at line 153 of file File.php.

154  {
155  $directory = $this->_filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
156  if ($this->_maxFileSize > 0 && $directory->stat(
157  $directory->getRelativePath($filePath)
158  )['size'] > $this->_maxFileSize * 1024
159  ) {
160  throw new \Magento\Framework\Exception\LocalizedException(
161  __('The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxFileSize)
162  );
163  }
164  }
__()
Definition: __.php:13

Field Documentation

◆ $_filesystem

$_filesystem
protected

Definition at line 38 of file File.php.

◆ $_maxFileSize

$_maxFileSize = 0
protected

Definition at line 33 of file File.php.

◆ $_mediaDirectory

$_mediaDirectory
protected

Definition at line 43 of file File.php.

◆ $_requestData

$_requestData
protected

Definition at line 26 of file File.php.

◆ $_uploaderFactory

$_uploaderFactory
protected

Definition at line 48 of file File.php.


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