Skip to content

Commit 6f00cc0

Browse files
author
Joan He
committed
Merge remote-tracking branch 'origin/MAGETWO-41954-st-compiler' into develop
2 parents 7661eae + 087e329 commit 6f00cc0

File tree

16 files changed

+677
-21
lines changed

16 files changed

+677
-21
lines changed

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
namespace Magento\Framework\Console;
88

9+
use Magento\Framework\Filesystem\Driver\File;
910
use Symfony\Component\Console\Application as SymfonyApplication;
1011
use Magento\Framework\App\Bootstrap;
1112
use Magento\Framework\Shell\ComplexParameter;
13+
use Symfony\Component\Console\Input\ArgvInput;
1214

1315
/**
1416
* Magento2 CLI Application. This is the hood for all command line tools supported by Magento.
@@ -22,6 +24,28 @@ class Cli extends SymfonyApplication
2224
*/
2325
const INPUT_KEY_BOOTSTRAP = 'bootstrap';
2426

27+
/** @var \Zend\ServiceManager\ServiceManager */
28+
private $serviceManager;
29+
30+
/**
31+
* @param string $name The name of the application
32+
* @param string $version The version of the application
33+
*/
34+
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
35+
{
36+
$this->serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')
37+
->getServiceManager();
38+
/**
39+
* Temporary workaround until the compiler is able to clear the generation directory. (MAGETWO-44493)
40+
*/
41+
if (class_exists('Magento\Setup\Console\CompilerPreparation')) {
42+
(new \Magento\Setup\Console\CompilerPreparation($this->serviceManager, new ArgvInput(), new File()))
43+
->handleCompilerEnvironment();
44+
}
45+
46+
parent::__construct($name, $version);
47+
}
48+
2549
/**
2650
* {@inheritdoc}
2751
*/
@@ -45,14 +69,12 @@ protected function getApplicationCommands()
4569
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
4670
$bootstrap = Bootstrap::create(BP, $params);
4771
$objectManager = $bootstrap->getObjectManager();
48-
$serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')
49-
->getServiceManager();
5072
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
51-
$omProvider = $serviceManager->get('Magento\Setup\Model\ObjectManagerProvider');
73+
$omProvider = $this->serviceManager->get('Magento\Setup\Model\ObjectManagerProvider');
5274
$omProvider->setObjectManager($objectManager);
5375

5476
if (class_exists('Magento\Setup\Console\CommandList')) {
55-
$setupCommandList = new \Magento\Setup\Console\CommandList($serviceManager);
77+
$setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager);
5678
$setupCommands = $setupCommandList->getCommands();
5779
}
5880

lib/internal/Magento/Framework/Interception/Config/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Config implements \Magento\Framework\Interception\ConfigInterface
6363
*
6464
* @var array
6565
*/
66-
protected $_serviceClassTypes = ['Proxy', 'Interceptor'];
66+
protected $_serviceClassTypes = ['Interceptor'];
6767

6868
/**
6969
* @var \Magento\Framework\Config\ScopeListInterface

lib/internal/Magento/Framework/Interception/Test/Unit/Config/ConfigTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public function testHasPluginsWhenDataIsNotCached($expectedResult, $type, $entit
102102
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Enhanced',
103103
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Enhanced',
104104
],
105+
[
106+
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Proxy',
107+
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Proxy',
108+
],
105109
[
106110
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemProxy',
107111
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemProxy',
@@ -151,6 +155,7 @@ public function testHasPluginsWhenDataIsCached($expectedResult, $type)
151155
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item' => true,
152156
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\Item\Enhanced' => true,
153157
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Enhanced' => true,
158+
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Proxy' => true,
154159
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemProxy' => false,
155160
'virtual_custom_item' => true,
156161
];
@@ -195,7 +200,13 @@ public function hasPluginsDataProvider()
195200
[
196201
// the following model has only inherited plugins
197202
true,
198-
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Enhanced',
203+
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Proxy',
204+
['Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer'],
205+
],
206+
[
207+
// the following model has only inherited plugins
208+
true,
209+
'Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer\Proxy',
199210
['Magento\Framework\Interception\Test\Unit\Custom\Module\Model\ItemContainer'],
200211
],
201212
[

setup/src/Magento/Setup/Console/Command/DiCompileCommand.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
*/
2929
class DiCompileCommand extends Command
3030
{
31+
/** Command name */
32+
const NAME = 'setup:di:compile';
33+
3134
/** @var DeploymentConfig */
3235
private $deploymentConfig;
3336

@@ -89,7 +92,7 @@ public function __construct(
8992
*/
9093
protected function configure()
9194
{
92-
$this->setName('setup:di:compile')
95+
$this->setName(self::NAME)
9396
->setDescription(
9497
'Generates DI configuration and all non-existing interceptors and factories'
9598
);
@@ -172,7 +175,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
172175
$this->cleanupFilesystem(
173176
[
174177
DirectoryList::CACHE,
175-
DirectoryList::GENERATION,
176178
DirectoryList::DI,
177179
]
178180
);
@@ -291,19 +293,34 @@ private function getOperationsConfiguration(
291293
array $compiledPathsList,
292294
array $dataAttributesIncludePattern
293295
) {
296+
$excludePatterns = [];
297+
foreach ($this->excludedPathsList as $excludedPaths) {
298+
$excludePatterns = array_merge($excludedPaths, $excludePatterns);
299+
}
300+
294301
$operations = [
302+
OperationFactory::PROXY_GENERATOR => [
303+
'paths' => $compiledPathsList['application'],
304+
'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'],
305+
'excludePatterns' => $excludePatterns,
306+
],
295307
OperationFactory::REPOSITORY_GENERATOR => [
296308
'paths' => $compiledPathsList['application'],
297-
'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/']
309+
'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'],
310+
'excludePatterns' => $excludePatterns,
298311
],
299312
OperationFactory::DATA_ATTRIBUTES_GENERATOR => [
300313
'paths' => $compiledPathsList['application'],
301314
'filePatterns' => $dataAttributesIncludePattern
302315
],
303316
OperationFactory::APPLICATION_CODE_GENERATOR => [
304-
$compiledPathsList['application'],
305-
$compiledPathsList['library'],
306-
$compiledPathsList['generated_helpers'],
317+
'paths' => [
318+
$compiledPathsList['application'],
319+
$compiledPathsList['library'],
320+
$compiledPathsList['generated_helpers'],
321+
],
322+
'filePatterns' => ['php' => '/\.php$/'],
323+
'excludePatterns' => $excludePatterns,
307324
],
308325
OperationFactory::INTERCEPTION => [
309326
'intercepted_paths' => [

setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class DiCompileMultiTenantCommand extends AbstractSetupCommand
5656
const SERIALIZER_VALUE_IGBINARY = 'igbinary';
5757
/**#@- */
5858

59+
/** Command name */
60+
const NAME = 'setup:di:compile-multi-tenant';
61+
5962
/**
6063
* Object Manager
6164
*
@@ -155,7 +158,7 @@ protected function configure()
155158
'Allows to exclude Paths from compilation (default is #[\\\\/]m1[\\\\/]#i)'
156159
),
157160
];
158-
$this->setName('setup:di:compile-multi-tenant')
161+
$this->setName(self::NAME)
159162
->setDescription(
160163
'Generates all non-existing proxies and factories, and pre-compile class definitions, '
161164
. 'inheritance information and plugin definitions'
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Console;
8+
9+
10+
use Magento\Framework\App\Bootstrap;
11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\Filesystem\Driver\File;
13+
use Magento\Setup\Console\Command\DiCompileCommand;
14+
use Magento\Setup\Console\Command\DiCompileMultiTenantCommand;
15+
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
16+
use Symfony\Component\Console\Input\ArgvInput;
17+
18+
class CompilerPreparation
19+
{
20+
/** @var \Zend\ServiceManager\ServiceManager */
21+
private $serviceManager;
22+
23+
/** @var ArgvInput */
24+
private $input;
25+
26+
/** @var File */
27+
private $filesystemDriver;
28+
29+
/**
30+
* @param \Zend\ServiceManager\ServiceManager $serviceManager
31+
* @param ArgvInput $input
32+
* @param File $filesystemDriver
33+
*/
34+
public function __construct(
35+
\Zend\ServiceManager\ServiceManager $serviceManager,
36+
\Symfony\Component\Console\Input\ArgvInput $input,
37+
\Magento\Framework\Filesystem\Driver\File $filesystemDriver
38+
) {
39+
$this->serviceManager = $serviceManager;
40+
$this->input = $input;
41+
$this->filesystemDriver = $filesystemDriver;
42+
}
43+
44+
/**
45+
* Determine whether a CLI command is for compilation, and if so, clear the directory
46+
*
47+
* @throws \Magento\Framework\Exception\FileSystemException
48+
* @return void
49+
*/
50+
public function handleCompilerEnvironment()
51+
{
52+
$compilationCommands = [DiCompileCommand::NAME, DiCompileMultiTenantCommand::NAME];
53+
$cmdName = $this->input->getFirstArgument();
54+
$isHelpOption = $this->input->hasParameterOption('--help') || $this->input->hasParameterOption('-h');
55+
56+
if (!in_array($cmdName, $compilationCommands) || $isHelpOption) {
57+
return;
58+
}
59+
60+
$generationDir = ($cmdName === DiCompileMultiTenantCommand::NAME)
61+
? $this->input->getParameterOption(DiCompileMultiTenantCommand::INPUT_KEY_GENERATION)
62+
: null;
63+
64+
if (!$generationDir) {
65+
$mageInitParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
66+
$mageDirs = isset($mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS])
67+
? $mageInitParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]
68+
: [];
69+
$generationDir = (new DirectoryList(BP, $mageDirs))->getPath(DirectoryList::GENERATION);
70+
}
71+
72+
if ($this->filesystemDriver->isExists($generationDir)) {
73+
$this->filesystemDriver->deleteDirectory($generationDir);
74+
}
75+
}
76+
}

setup/src/Magento/Setup/Module/Di/App/Task/Operation/ApplicationCodeGenerator.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
*/
66
namespace Magento\Setup\Module\Di\App\Task\Operation;
77

8+
use Magento\Framework\App\Bootstrap;
9+
use Magento\Framework\Exception\FileSystemException;
810
use Magento\Setup\Module\Di\App\Task\OperationInterface;
911
use Magento\Setup\Module\Di\Code\Reader\ClassesScanner;
12+
use Magento\Setup\Module\Di\Code\Scanner\DirectoryScanner;
13+
use Magento\Setup\Module\Di\Code\Scanner\PhpScanner;
1014

1115
class ApplicationCodeGenerator implements OperationInterface
1216
{
@@ -20,33 +24,59 @@ class ApplicationCodeGenerator implements OperationInterface
2024
*/
2125
private $classesScanner;
2226

27+
/**
28+
* @var PhpScanner
29+
*/
30+
private $phpScanner;
31+
32+
/**
33+
* @var DirectoryScanner
34+
*/
35+
private $directoryScanner;
36+
2337
/**
2438
* @param ClassesScanner $classesScanner
39+
* @param PhpScanner $phpScanner
40+
* @param DirectoryScanner $directoryScanner
2541
* @param array $data
2642
*/
2743
public function __construct(
2844
ClassesScanner $classesScanner,
45+
PhpScanner $phpScanner,
46+
DirectoryScanner $directoryScanner,
2947
$data = []
3048
) {
3149
$this->data = $data;
3250
$this->classesScanner = $classesScanner;
51+
$this->phpScanner = $phpScanner;
52+
$this->directoryScanner = $directoryScanner;
3353
}
3454

3555
/**
3656
* {@inheritdoc}
3757
*/
3858
public function doOperation()
3959
{
40-
if (empty($this->data)) {
60+
if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns'])
61+
!== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
4162
return;
4263
}
4364

44-
foreach ($this->data as $paths) {
65+
foreach ($this->data['paths'] as $paths) {
4566
if (!is_array($paths)) {
4667
$paths = (array)$paths;
4768
}
69+
$files = [];
4870
foreach ($paths as $path) {
4971
$this->classesScanner->getList($path);
72+
$files = array_merge_recursive(
73+
$files,
74+
$this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns'])
75+
);
76+
}
77+
$entities = $this->phpScanner->collectEntities($files['php']);
78+
foreach ($entities as $entityName) {
79+
class_exists($entityName);
5080
}
5181
}
5282
}

0 commit comments

Comments
 (0)