Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
DeployStaticFile Class Reference

Public Member Functions

 __construct (Filesystem $filesystem, Repository $assetRepo, Publisher $assetPublisher, FileNameResolver $fileNameResolver, Minification $minification)
 
 deployFile ($fileName, array $params=[])
 
 deleteFile ($path)
 
 readFile ($fileName, $filePath)
 
 openFile ($fileName, $filePath)
 
 writeFile ($fileName, $filePath, $content)
 
 copyFile ($fileName, $sourcePath, $targetPath)
 
 readTmpFile ($fileName, $filePath)
 
 writeTmpFile ($fileName, $filePath, $content)
 

Detailed Description

Deploy static file service

Definition at line 20 of file DeployStaticFile.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Filesystem  $filesystem,
Repository  $assetRepo,
Publisher  $assetPublisher,
FileNameResolver  $fileNameResolver,
Minification  $minification 
)

DeployStaticFile constructor

Parameters
Filesystem$filesystem
Repository$assetRepo
Publisher$assetPublisher
FileNameResolver$fileNameResolver
Minification$minification

Definition at line 63 of file DeployStaticFile.php.

69  {
70  $this->filesystem = $filesystem;
71  $this->assetRepo = $assetRepo;
72  $this->assetPublisher = $assetPublisher;
73  $this->fileNameResolver = $fileNameResolver;
74  $this->pubStaticDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
75  $this->minification = $minification;
76  $this->tmpDir = $filesystem->getDirectoryWrite(DirectoryList::TMP_MATERIALIZATION_DIR);
77  }

Member Function Documentation

◆ copyFile()

copyFile (   $fileName,
  $sourcePath,
  $targetPath 
)

Copy resolved $fileName from $targetPath to $destinationPath

Parameters
string$fileName
string$sourcePath
string$targetPath
Returns
bool

Definition at line 165 of file DeployStaticFile.php.

166  {
167  $fileName = $this->minification->addMinifiedSign($fileName);
168  return $this->pubStaticDir->copyFile(
169  $sourcePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName),
170  $targetPath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName)
171  );
172  }
$fileName
Definition: translate.phtml:15

◆ deleteFile()

deleteFile (   $path)
Parameters
string$path
Returns
void

Definition at line 98 of file DeployStaticFile.php.

99  {
100  if ($this->pubStaticDir->isExist($path)) {
101  $absolutePath = $this->pubStaticDir->getAbsolutePath($path);
102  if (is_link($absolutePath)) {
103  $this->pubStaticDir->getDriver()->deleteFile($absolutePath);
104  } else {
105  if ($this->pubStaticDir->getDriver()->isFile($absolutePath)) {
106  $this->pubStaticDir->getDriver()->deleteFile($absolutePath);
107  } else {
108  $this->pubStaticDir->getDriver()->deleteDirectory($absolutePath);
109  }
110  }
111  }
112  }

◆ deployFile()

deployFile (   $fileName,
array  $params = [] 
)
Parameters
string$fileName
array$params['area' =>, 'theme' =>, 'locale' =>, 'module' =>]
Returns
string

Definition at line 84 of file DeployStaticFile.php.

85  {
86  $params['publish'] = true;
87  $asset = $this->assetRepo->createAsset($this->resolveFile($fileName), $params);
88 
89  $this->assetPublisher->publish($asset);
90 
91  return $asset->getPath();
92  }
$fileName
Definition: translate.phtml:15
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ openFile()

openFile (   $fileName,
  $filePath 
)
Parameters
string$fileName
string$filePath
Returns
WriteInterface

Definition at line 137 of file DeployStaticFile.php.

138  {
139  $relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
140  return $this->pubStaticDir->openFile($relativePath, 'w+');
141  }
$fileName
Definition: translate.phtml:15
$relativePath
Definition: get.php:35

◆ readFile()

readFile (   $fileName,
  $filePath 
)

Read resolved file from pub static directory

Parameters
string$fileName
string$filePath
Returns
string|false

Definition at line 121 of file DeployStaticFile.php.

122  {
123  $fileName = $this->minification->addMinifiedSign($fileName);
124  $relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
125  if ($this->pubStaticDir->isFile($relativePath)) {
126  return $this->pubStaticDir->readFile($relativePath);
127  } else {
128  return false;
129  }
130  }
$fileName
Definition: translate.phtml:15
$relativePath
Definition: get.php:35

◆ readTmpFile()

readTmpFile (   $fileName,
  $filePath 
)

Read file from tmp directory

Parameters
string$fileName
string$filePath
Returns
string

Definition at line 181 of file DeployStaticFile.php.

182  {
183  $relativePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
184  return $this->tmpDir->isFile($relativePath) ? $this->tmpDir->readFile($relativePath) : false;
185  }
$fileName
Definition: translate.phtml:15
$relativePath
Definition: get.php:35

◆ writeFile()

writeFile (   $fileName,
  $filePath,
  $content 
)

Write resolved file to pub static directory

Parameters
string$fileName
string$filePath
string$content
Returns
int The number of bytes that were written.

Definition at line 151 of file DeployStaticFile.php.

152  {
153  $relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
154  return $this->pubStaticDir->writeFile($relativePath, $content);
155  }
$fileName
Definition: translate.phtml:15
$relativePath
Definition: get.php:35

◆ writeTmpFile()

writeTmpFile (   $fileName,
  $filePath,
  $content 
)

Write file to tmp directory

Parameters
string$fileName
string$filePath
string$content
Returns
int The number of bytes that were written.

Definition at line 195 of file DeployStaticFile.php.

196  {
197  $relativePath = $filePath . DIRECTORY_SEPARATOR . $this->resolveFile($fileName);
198  return $this->tmpDir->writeFile($relativePath, $content);
199  }
$fileName
Definition: translate.phtml:15
$relativePath
Definition: get.php:35

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