Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CompilerPreparation.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Setup\Console;
7 
17 use Symfony\Component\Console\Input\ArgvInput;
18 use Zend\ServiceManager\ServiceManager;
19 
24 {
28  private $serviceManager;
29 
33  private $input;
34 
38  private $filesystemDriver;
39 
43  private $generationDirectoryAccess;
44 
50  public function __construct(
51  ServiceManager $serviceManager,
52  ArgvInput $input,
53  File $filesystemDriver
54  ) {
55  $this->serviceManager = $serviceManager;
56  $this->input = $input;
57  $this->filesystemDriver = $filesystemDriver;
58  }
59 
66  public function handleCompilerEnvironment()
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()) {
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  }
95 
101  private function getCompilerInvalidationCommands()
102  {
103  return [
105  'module:disable',
106  'module:enable',
107  'module:uninstall',
108  ];
109  }
110 
116  private function getGenerationDirectoryAccess()
117  {
118  if (null === $this->generationDirectoryAccess) {
119  $this->generationDirectoryAccess = new GenerationDirectoryAccess($this->serviceManager);
120  }
121 
122  return $this->generationDirectoryAccess;
123  }
124 }
__construct(ServiceManager $serviceManager, ArgvInput $input, File $filesystemDriver)
const BP
Definition: autoload.php:14