|
3 | 3 | * Copyright © Magento, Inc. All rights reserved. |
4 | 4 | * See COPYING.txt for license details. |
5 | 5 | */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Setup\Console; |
7 | 9 |
|
8 | 10 | use Magento\Framework\App\Bootstrap; |
@@ -65,13 +67,9 @@ public function __construct( |
65 | 67 | */ |
66 | 68 | public function handleCompilerEnvironment() |
67 | 69 | { |
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) { |
| 70 | + if (!$this->shouldInvalidateCompiledDI()) { |
72 | 71 | return; |
73 | 72 | } |
74 | | - |
75 | 73 | if (!$this->getGenerationDirectoryAccess()->check()) { |
76 | 74 | throw new GenerationDirectoryAccessException(); |
77 | 75 | } |
@@ -121,4 +119,39 @@ private function getGenerationDirectoryAccess() |
121 | 119 |
|
122 | 120 | return $this->generationDirectoryAccess; |
123 | 121 | } |
| 122 | + |
| 123 | + /** |
| 124 | + * Checks if the command being executed should invalidate compiled DI. |
| 125 | + * |
| 126 | + * @return bool |
| 127 | + */ |
| 128 | + private function shouldInvalidateCompiledDI(): bool |
| 129 | + { |
| 130 | + $compilationCommands = $this->getCompilerInvalidationCommands(); |
| 131 | + $cmdName = $this->input->getFirstArgument(); |
| 132 | + $isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h'); |
| 133 | + $invalidate = false; |
| 134 | + if (!$isHelpOption) { |
| 135 | + $invalidate = in_array($cmdName, $compilationCommands); |
| 136 | + if (!$invalidate) { |
| 137 | + // Check if it's an abbreviation of compilation commands. |
| 138 | + $expr = preg_replace_callback( |
| 139 | + '{([^:]+|)}', |
| 140 | + function ($matches) { |
| 141 | + return preg_quote($matches[1]) . '[^:]*'; |
| 142 | + }, |
| 143 | + $cmdName |
| 144 | + ); |
| 145 | + $commands = preg_grep('{^' . $expr . '$}', $compilationCommands); |
| 146 | + if (empty($commands)) { |
| 147 | + $commands = preg_grep('{^' . $expr . '$}i', $compilationCommands); |
| 148 | + } |
| 149 | + if (count($commands) === 1) { |
| 150 | + $invalidate = true; |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + return $invalidate; |
| 156 | + } |
124 | 157 | } |
0 commit comments