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

Public Member Functions

 __construct (\Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem\Driver\File $driverFile, \Magento\Translation\Model\Inline\File $translationFile=null)
 
 createTranslateConfigAsset ()
 
 getTranslationFileTimestamp ()
 
 getTranslationFilePath ()
 
 updateTranslationFileContent ($content)
 
 getTranslationFileVersion ()
 

Data Fields

const TRANSLATION_CONFIG_FILE_NAME = 'Magento_Translation/js/i18n-config.js'
 

Protected Member Functions

 getTranslationFileFullPath ()
 

Detailed Description

A service for handling Translation config files

Definition at line 15 of file FileManager.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\View\Asset\Repository$assetRepo
\Magento\Framework\App\Filesystem\DirectoryList$directoryList
\Magento\Framework\Filesystem\Driver\File$driverFile
TranslationFile$translationFile

Definition at line 48 of file FileManager.php.

53  {
54  $this->assetRepo = $assetRepo;
55  $this->directoryList = $directoryList;
56  $this->driverFile = $driverFile;
57  $this->translationFile = $translationFile ?: ObjectManager::getInstance()->get(TranslationFile::class);
58  }

Member Function Documentation

◆ createTranslateConfigAsset()

createTranslateConfigAsset ( )

Create a view asset representing the requirejs config.config property for inline translation

Returns
\Magento\Framework\View\Asset\File

Definition at line 65 of file FileManager.php.

66  {
67  return $this->assetRepo->createArbitrary(
68  $this->assetRepo->getStaticViewFileContext()->getPath() . '/' . self::TRANSLATION_CONFIG_FILE_NAME,
69  ''
70  );
71  }

◆ getTranslationFileFullPath()

getTranslationFileFullPath ( )
protected
Returns
string

Definition at line 92 of file FileManager.php.

93  {
94  return $this->directoryList->getPath(DirectoryList::STATIC_VIEW) .
95  \DIRECTORY_SEPARATOR .
96  $this->assetRepo->getStaticViewFileContext()->getPath() .
97  \DIRECTORY_SEPARATOR .
99  }

◆ getTranslationFilePath()

getTranslationFilePath ( )
Returns
string

Definition at line 104 of file FileManager.php.

105  {
106  return $this->assetRepo->getStaticViewFileContext()->getPath();
107  }

◆ getTranslationFileTimestamp()

getTranslationFileTimestamp ( )

gets current js-translation.json timestamp

Returns
string|void

Definition at line 78 of file FileManager.php.

79  {
80  $translationFilePath = $this->getTranslationFileFullPath();
81  if ($this->driverFile->isExists($translationFilePath)) {
82  $statArray = $this->driverFile->stat($translationFilePath);
83  if (array_key_exists('mtime', $statArray)) {
84  return $statArray['mtime'];
85  }
86  }
87  }

◆ getTranslationFileVersion()

getTranslationFileVersion ( )

Calculate translation file version hash.

Returns
string

Definition at line 129 of file FileManager.php.

130  {
131  $translationFile = $this->getTranslationFileFullPath();
132  $translationFileHash = '';
133 
134  if ($this->driverFile->isExists($translationFile)) {
135  $translationFileHash = sha1_file($translationFile);
136  }
137 
138  return sha1($translationFileHash . $this->getTranslationFilePath());
139  }

◆ updateTranslationFileContent()

updateTranslationFileContent (   $content)
Parameters
string$content
Returns
void

Definition at line 113 of file FileManager.php.

114  {
115  $translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) .
116  \DIRECTORY_SEPARATOR .
117  $this->assetRepo->getStaticViewFileContext()->getPath();
118  if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) {
119  $this->driverFile->createDirectory($translationDir);
120  }
121  $this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content);
122  }

Field Documentation

◆ TRANSLATION_CONFIG_FILE_NAME

const TRANSLATION_CONFIG_FILE_NAME = 'Magento_Translation/js/i18n-config.js'

File name of RequireJs inline translation config

Definition at line 20 of file FileManager.php.


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