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

Public Member Functions

 __construct (\Magento\Framework\View\Design\FileResolution\Fallback\File $fallbackFile, \Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile $fallbackTemplateFile, \Magento\Framework\View\Design\FileResolution\Fallback\LocaleFile $fallbackLocaleFile, \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $fallbackStaticFile, \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile $fallbackEmailTemplateFile, \Magento\Framework\View\Asset\Repository $assetRepo)
 
 getFilename ($fileId, array $params=[])
 
 getLocaleFileName ($file, array $params=[])
 
 getTemplateFileName ($fileId, array $params=[])
 
 getStaticFileName ($fileId, array $params=[])
 
 getEmailTemplateFileName ($fileId, array $params, $module)
 

Static Public Member Functions

static normalizePath ($path)
 
static offsetPath ($relatedPath, $path)
 
static getRelatedPath ($relativeTo, $path)
 

Protected Attributes

 $_fileResolution
 
 $_templateFileResolution
 
 $_localeFileResolution
 
 $_staticFileResolution
 
 $_emailTemplateFileResolution
 
 $_assetRepo
 

Detailed Description

Model that finds file paths by their fileId

@api

Since
100.0.2

Definition at line 14 of file FileSystem.php.

Constructor & Destructor Documentation

◆ __construct()

Constructor

Parameters
\Magento\Framework\View\Design\FileResolution\Fallback\File$fallbackFile
\Magento\Framework\View\Design\FileResolution\Fallback\TemplateFile$fallbackTemplateFile
\Magento\Framework\View\Design\FileResolution\Fallback\LocaleFile$fallbackLocaleFile
\Magento\Framework\View\Design\FileResolution\Fallback\StaticFile$fallbackStaticFile
\Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile$fallbackEmailTemplateFile
\Magento\Framework\View\Asset\Repository$assetRepo

Definition at line 58 of file FileSystem.php.

65  {
66  $this->_fileResolution = $fallbackFile;
67  $this->_templateFileResolution = $fallbackTemplateFile;
68  $this->_localeFileResolution = $fallbackLocaleFile;
69  $this->_staticFileResolution = $fallbackStaticFile;
70  $this->_emailTemplateFileResolution = $fallbackEmailTemplateFile;
71  $this->_assetRepo = $assetRepo;
72  }

Member Function Documentation

◆ getEmailTemplateFileName()

getEmailTemplateFileName (   $fileId,
array  $params,
  $module 
)

Get an email template file

Parameters
string$fileId
array$params
string$module
Returns
string|bool

Definition at line 157 of file FileSystem.php.

158  {
159  $this->_assetRepo->updateDesignParams($params);
160  return $this->_emailTemplateFileResolution
161  ->getFile($params['area'], $params['themeModel'], $params['locale'], $fileId, $module);
162  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getFilename()

getFilename (   $fileId,
array  $params = [] 
)

Get existing file name with fallback to default

Parameters
string$fileId
array$params
Returns
string

Definition at line 81 of file FileSystem.php.

82  {
83  list($module, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule(
84  $this->normalizePath($fileId)
85  );
86  if ($module) {
87  $params['module'] = $module;
88  }
89  $this->_assetRepo->updateDesignParams($params);
90  $file = $this->_fileResolution
91  ->getFile($params['area'], $params['themeModel'], $filePath, $params['module']);
92  return $file;
93  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getLocaleFileName()

getLocaleFileName (   $file,
array  $params = [] 
)

Get a locale file

Parameters
string$file
array$params
Returns
string

Definition at line 102 of file FileSystem.php.

103  {
104  $this->_assetRepo->updateDesignParams($params);
105  return $this->_localeFileResolution
106  ->getFile($params['area'], $params['themeModel'], $params['locale'], $file);
107  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getRelatedPath()

static getRelatedPath (   $relativeTo,
  $path 
)
static

Concatenate/normalize a path to another path as a relative, assuming it will be relative to its directory

Parameters
string$relativeTo
string$path
Returns
string

Definition at line 230 of file FileSystem.php.

231  {
232  return self::normalizePath(dirname($relativeTo) . '/' . $path);
233  }

◆ getStaticFileName()

getStaticFileName (   $fileId,
array  $params = [] 
)

Find a static view file using fallback mechanism

Parameters
string$fileId
array$params
Returns
string

Definition at line 136 of file FileSystem.php.

137  {
138  list($module, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule(
139  $this->normalizePath($fileId)
140  );
141  if ($module) {
142  $params['module'] = $module;
143  }
144  $this->_assetRepo->updateDesignParams($params);
145  return $this->_staticFileResolution
146  ->getFile($params['area'], $params['themeModel'], $params['locale'], $filePath, $params['module']);
147  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getTemplateFileName()

getTemplateFileName (   $fileId,
array  $params = [] 
)

Get a template file

Parameters
string$fileId
array$params
Returns
string|bool

Definition at line 116 of file FileSystem.php.

117  {
118  list($module, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule(
119  $this->normalizePath($fileId)
120  );
121  if ($module) {
122  $params['module'] = $module;
123  }
124  $this->_assetRepo->updateDesignParams($params);
125  return $this->_templateFileResolution
126  ->getFile($params['area'], $params['themeModel'], $filePath, $params['module']);
127  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ normalizePath()

static normalizePath (   $path)
static

Remove excessive "." and ".." parts from a path

For example foo/bar/../file.ext -> foo/file.ext

Parameters
string$path
Returns
string

Definition at line 172 of file FileSystem.php.

173  {
174  $parts = explode('/', $path);
175  $result = [];
176 
177  foreach ($parts as $part) {
178  if ('..' === $part) {
179  if (!count($result) || ($result[count($result) - 1] == '..')) {
180  $result[] = $part;
181  } else {
182  array_pop($result);
183  }
184  } elseif ('.' !== $part) {
185  $result[] = $part;
186  }
187  }
188  return implode('/', $result);
189  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ offsetPath()

static offsetPath (   $relatedPath,
  $path 
)
static

Get a relative path between $relatedPath and $path paths as if $path was to refer to $relatedPath relatively of itself

Returns new calculated relative path. Examples: $path: /some/directory/one/file.ext $relatedPath: /some/directory/two/another/file.ext Result: ../two/another

$path: http://example.com/themes/demo/css/styles.css $relatedPath: http://example.com/images/logo.gif Result: ../../../images

Parameters
string$relatedPath
string$path
Returns
string

Definition at line 209 of file FileSystem.php.

210  {
211  $relatedPath = self::normalizePath($relatedPath);
213  list($relatedPath, $path) = self::ltrimSamePart($relatedPath, $path);
214  $toDir = ltrim(dirname($path), '/');
215  if ($toDir == '.') {
216  $offset = '';
217  } else {
218  $offset = str_repeat('../', count(explode('/', $toDir)));
219  }
220  return rtrim($offset . dirname($relatedPath), '/');
221  }

Field Documentation

◆ $_assetRepo

$_assetRepo
protected

Definition at line 46 of file FileSystem.php.

◆ $_emailTemplateFileResolution

$_emailTemplateFileResolution
protected

Definition at line 39 of file FileSystem.php.

◆ $_fileResolution

$_fileResolution
protected

Definition at line 19 of file FileSystem.php.

◆ $_localeFileResolution

$_localeFileResolution
protected

Definition at line 29 of file FileSystem.php.

◆ $_staticFileResolution

$_staticFileResolution
protected

Definition at line 34 of file FileSystem.php.

◆ $_templateFileResolution

$_templateFileResolution
protected

Definition at line 24 of file FileSystem.php.


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