Skip to content

Commit 20bfc1e

Browse files
committed
Merge remote-tracking branch 'origin/MC-33273' into 2.4-develop-pr36
2 parents fbbbe96 + 2d802c8 commit 20bfc1e

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

setup/src/Magento/Setup/Console/CompilerPreparation.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Setup\Console;
79

810
use Magento\Framework\App\Bootstrap;
@@ -65,13 +67,9 @@ public function __construct(
6567
*/
6668
public function handleCompilerEnvironment()
6769
{
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()) {
7271
return;
7372
}
74-
7573
if (!$this->getGenerationDirectoryAccess()->check()) {
7674
throw new GenerationDirectoryAccessException();
7775
}
@@ -121,4 +119,39 @@ private function getGenerationDirectoryAccess()
121119

122120
return $this->generationDirectoryAccess;
123121
}
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+
}
124157
}

setup/src/Magento/Setup/Test/Unit/Console/CompilerPreparationTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,25 @@ public function commandNameDataProvider()
139139
'commandName' => 'not:a:compiler',
140140
'isCompileCommand' => false,
141141
'isHelpOption' => false,
142-
]
142+
],
143+
'ST compiler, directory exists, abbreviation 1' => [
144+
'commandName' => 's:d:c',
145+
'isCompileCommand' => true,
146+
'isHelpOption' => false,
147+
'dirExists' => true
148+
],
149+
'ST compiler, directory exists, abbreviation 2' => [
150+
'commandName' => 'se:di:co',
151+
'isCompileCommand' => true,
152+
'isHelpOption' => false,
153+
'dirExists' => true
154+
],
155+
'ST compiler, directory exists, abbreviation ambiguous' => [
156+
'commandName' => 'se:di',
157+
'isCompileCommand' => false,
158+
'isHelpOption' => false,
159+
'dirExists' => true
160+
],
143161
];
144162
}
145163

0 commit comments

Comments
 (0)