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

Public Member Functions

 __construct (ServiceManager $serviceManager, ArgvInput $input, File $filesystemDriver)
 
 handleCompilerEnvironment ()
 

Detailed Description

Class prepares folders for code generation

Definition at line 23 of file CompilerPreparation.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ServiceManager  $serviceManager,
ArgvInput  $input,
File  $filesystemDriver 
)
Parameters
ServiceManager$serviceManager
ArgvInput$input
File$filesystemDriver

Definition at line 50 of file CompilerPreparation.php.

54  {
55  $this->serviceManager = $serviceManager;
56  $this->input = $input;
57  $this->filesystemDriver = $filesystemDriver;
58  }

Member Function Documentation

◆ handleCompilerEnvironment()

handleCompilerEnvironment ( )

Determine whether a CLI command is for compilation, and if so, clear the directory.

Exceptions
GenerationDirectoryAccessExceptionIf generation directory is read-only
Returns
void

Definition at line 66 of file CompilerPreparation.php.

67  {
68  $compilationCommands = $this->getCompilerInvalidationCommands();
69  $cmdName = $this->input->getFirstArgument();
70  $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h');
71  if (!in_array($cmdName, $compilationCommands) || $isHelpOption) {
72  return;
73  }
74 
75  if (!$this->getGenerationDirectoryAccess()->check()) {
76  throw new GenerationDirectoryAccessException();
77  }
78 
79  $mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
80  $mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS])
82  : [];
83  $directoryList = new DirectoryList(BP, $mageDirs);
84  $compileDirList = [
85  $directoryList->getPath(DirectoryList::GENERATED_CODE),
86  $directoryList->getPath(DirectoryList::GENERATED_METADATA),
87  ];
88 
89  foreach ($compileDirList as $compileDir) {
90  if ($this->filesystemDriver->isExists($compileDir)) {
91  $this->filesystemDriver->deleteDirectory($compileDir);
92  }
93  }
94  }
const BP
Definition: autoload.php:14

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