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

Public Member Functions

 __construct (\Magento\Framework\App\DeploymentConfig\Writer $writer, \Magento\Framework\App\DeploymentConfig\Reader $reader, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, \Magento\Framework\Filesystem\Driver\File $driverFile, \Magento\Store\Model\Config\StoreView $storeView, \Magento\Framework\ShellInterface $shell, UserCollection $userCollection=null, Locale $locale=null)
 
 regenerateStatic (OutputInterface $output)
 
 cleanupFilesystem ($directoryCodeList)
 
 lockStaticResources ()
 

Data Fields

const PERMISSIONS_FILE = 0640
 
const PERMISSIONS_DIR = 0750
 
const DEFAULT_THEME = 'Magento/blank'
 

Protected Member Functions

 deployStaticContent (OutputInterface $output)
 
 compile (OutputInterface $output)
 
 changePermissions ($directoryCodeList, $dirPermissions, $filePermissions)
 

Detailed Description

Generate static files, compile

Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 23 of file Filesystem.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\App\DeploymentConfig\Writer$writer
\Magento\Framework\App\DeploymentConfig\Reader$reader
\Magento\Framework\ObjectManagerInterface$objectManager
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\App\Filesystem\DirectoryList$directoryList
\Magento\Framework\Filesystem\Driver\File$driverFile
\Magento\Store\Model\Config\StoreView$storeView
\Magento\Framework\ShellInterface$shell
UserCollection | null$userCollection
Locale | null$locale@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 122 of file Filesystem.php.

133  {
134  $this->writer = $writer;
135  $this->reader = $reader;
136  $this->objectManager = $objectManager;
137  $this->filesystem = $filesystem;
138  $this->directoryList = $directoryList;
139  $this->driverFile = $driverFile;
140  $this->storeView = $storeView;
141  $this->shell = $shell;
142  $this->userCollection = $userCollection ?: $this->objectManager->get(UserCollection::class);
143  $this->locale = $locale ?: $this->objectManager->get(Locale::class);
144  $this->functionCallPath =
145  PHP_BINARY . ' -f ' . BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento ';
146  }
$objectManager
Definition: bootstrap.php:17
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
Definition: bootstrap.php:46
const BP
Definition: autoload.php:14
$filesystem

Member Function Documentation

◆ changePermissions()

changePermissions (   $directoryCodeList,
  $dirPermissions,
  $filePermissions 
)
protected

Changes permissions for directories by their code.

Parameters
array$directoryCodeList
int$dirPermissions
int$filePermissions
Returns
void
Deprecated:
100.0.6 As magento2 doesn't control indirectly the access permissions to the files and directories anymore. Access permissions to the files and directories are set during deploy Magento 2, directly after uploading code of Magento. Also it is possible to specify the value of inverse mask for setting access permissions to files and directories generated by Magento. http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html

Definition at line 326 of file Filesystem.php.

327  {
328  foreach ($directoryCodeList as $code) {
329  $directoryPath = $this->directoryList->getPath($code);
330  if ($this->driverFile->isExists($directoryPath)) {
331  $this->filesystem->getDirectoryWrite($code)
332  ->changePermissionsRecursively('', $dirPermissions, $filePermissions);
333  } else {
334  $this->driverFile->createDirectory($directoryPath, $dirPermissions);
335  }
336  }
337  }
$code
Definition: info.phtml:12

◆ cleanupFilesystem()

cleanupFilesystem (   $directoryCodeList)

Deletes specified directories by code

Parameters
array$directoryCodeList
Returns
void

Definition at line 283 of file Filesystem.php.

284  {
285  $excludePatterns = ['#.htaccess#', '#deployed_version.txt#'];
286  foreach ($directoryCodeList as $code) {
288  $directoryPath = $this->directoryList->getPath(DirectoryList::STATIC_VIEW);
289  if ($this->driverFile->isExists($directoryPath)) {
290  $files = $this->driverFile->readDirectory($directoryPath);
291  foreach ($files as $file) {
292  foreach ($excludePatterns as $pattern) {
293  if (preg_match($pattern, $file)) {
294  continue 2;
295  }
296  }
297  if ($this->driverFile->isFile($file)) {
298  $this->driverFile->deleteFile($file);
299  } else {
300  $this->driverFile->deleteDirectory($file);
301  }
302  }
303  }
304  } else {
305  $this->filesystem->getDirectoryWrite($code)
306  ->delete();
307  }
308  }
309  }
$pattern
Definition: website.php:22
foreach($appDirs as $dir) $files
$code
Definition: info.phtml:12

◆ compile()

compile ( OutputInterface  $output)
protected

Runs compiler

Parameters
OutputInterface$output
Returns
void
Exceptions
LocalizedException

exec command is necessary for now to isolate the autoloaders in the compiler from the memory state of this process, which would prevent some classes from being generated

Todo:
eliminate exec

Definition at line 249 of file Filesystem.php.

250  {
251  $output->writeln('Starting compilation');
252  $this->cleanupFilesystem(
253  [
257  ]
258  );
259  $cmd = $this->functionCallPath . 'setup:di:compile';
260 
267  try {
268  $execOutput = $this->shell->execute($cmd);
269  } catch (LocalizedException $e) {
270  $output->writeln('Something went wrong while compiling generated code. See the error log for details.');
271  throw $e;
272  }
273  $output->writeln($execOutput);
274  $output->writeln('Compilation complete');
275  }
cleanupFilesystem($directoryCodeList)
Definition: Filesystem.php:283

◆ deployStaticContent()

deployStaticContent ( OutputInterface  $output)
protected

Deploy static content

Parameters
OutputInterface$output
Returns
void
Exceptions
Todo:
eliminate exec

Definition at line 181 of file Filesystem.php.

183  {
184  $output->writeln('Starting deployment of static content');
185  $cmd = $this->functionCallPath . 'setup:static-content:deploy -f '
186  . implode(' ', $this->getUsedLocales());
187 
191  try {
192  $execOutput = $this->shell->execute($cmd);
193  } catch (LocalizedException $e) {
194  $output->writeln('Something went wrong while deploying static content. See the error log for details.');
195  throw $e;
196  }
197  $output->writeln($execOutput);
198  $output->writeln('Deployment of static content complete');
199  }

◆ lockStaticResources()

lockStaticResources ( )

Change permissions on static resources

Returns
void
Deprecated:
100.0.6 As magento2 doesn't control indirectly the access permissions to the files and directories anymore. Access permissions to the files and directories are set during deploy Magento 2, directly after uploading code of Magento. Also it is possible to specify the value of inverse mask for setting access permissions to files and directories generated by Magento. http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html

Definition at line 351 of file Filesystem.php.

352  {
353  // Lock /generated/code, /generated/metadata/ and /var/view_preprocessed directories
354  $this->changePermissions(
355  [
359  ],
360  self::PERMISSIONS_DIR,
361  self::PERMISSIONS_FILE
362  );
363  }
changePermissions($directoryCodeList, $dirPermissions, $filePermissions)
Definition: Filesystem.php:326

◆ regenerateStatic()

regenerateStatic ( OutputInterface  $output)

Regenerate static

Parameters
OutputInterface$output
Returns
void

Definition at line 154 of file Filesystem.php.

156  {
157  // Сlear generated/code, generated/metadata/, var/view_preprocessed and pub/static directories
158  $this->cleanupFilesystem(
159  [
165  ]
166  );
167 
168  // Trigger code generation
169  $this->compile($output);
170  // Trigger static assets compilation and deployment
172  }
compile(OutputInterface $output)
Definition: Filesystem.php:249
cleanupFilesystem($directoryCodeList)
Definition: Filesystem.php:283
deployStaticContent(OutputInterface $output)
Definition: Filesystem.php:181

Field Documentation

◆ DEFAULT_THEME

const DEFAULT_THEME = 'Magento/blank'

Default theme when no theme is stored in configuration

Definition at line 52 of file Filesystem.php.

◆ PERMISSIONS_DIR

const PERMISSIONS_DIR = 0750

Directory access permissions

Deprecated:
As magento2 doesn't control indirectly the access permissions to the directories anymore. Access permissions to the directories are set during deploy Magento 2, directly after uploading code of Magento. Also it is possible to specify the value of inverse mask for setting access permissions to directories generated by Magento. http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html

Definition at line 47 of file Filesystem.php.

◆ PERMISSIONS_FILE

const PERMISSIONS_FILE = 0640

File access permissions

Deprecated:
As magento2 doesn't control indirectly the access permissions to the files anymore. Access permissions to the files are set during deploy Magento 2, directly after uploading code of Magento. Also it is possible to specify the value of inverse mask for setting access permissions to files generated by Magento. http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html

Definition at line 35 of file Filesystem.php.


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