Skip to content

Commit 71cd40d

Browse files
committed
Merge pull request #111 from magento-mpi/public-pulls
[Github] Merge public Github commits
2 parents 116d26d + 8f68565 commit 71cd40d

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

dev/tools/Magento/Tools/Di/Code/Reader/ClassesScanner.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@
1010

1111
class ClassesScanner
1212
{
13+
/**
14+
* @var array
15+
*/
16+
protected $excludePatterns = [];
17+
18+
/**
19+
* Adds exclude patterns
20+
*
21+
* @param array $excludePatterns
22+
* @return void
23+
*/
24+
public function addExcludePatterns(array $excludePatterns)
25+
{
26+
$this->excludePatterns = array_merge($this->excludePatterns, $excludePatterns);
27+
}
28+
1329
/**
1430
* Retrieves list of classes for given path
1531
*
1632
* @param string $path
17-
*
1833
* @return array
19-
*
2034
* @throws FilesystemException
2135
*/
2236
public function getList($path)
@@ -37,6 +51,11 @@ public function getList($path)
3751
if ($fileItem->getExtension() !== 'php') {
3852
continue;
3953
}
54+
foreach ($this->excludePatterns as $excludePattern) {
55+
if (preg_match($excludePattern, $fileItem->getRealPath())) {
56+
continue 2;
57+
}
58+
}
4059
$fileScanner = new FileScanner($fileItem->getRealPath());
4160
$classNames = $fileScanner->getClassNames();
4261
foreach ($classNames as $className) {

dev/tools/Magento/Tools/Di/Code/Scanner/DirectoryScanner.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class DirectoryScanner
1212
*
1313
* @param string $dir
1414
* @param array $patterns
15+
* @param string[] $excludePatterns
1516
* @return array
1617
*/
17-
public function scan($dir, array $patterns = [])
18+
public function scan($dir, array $patterns = [], array $excludePatterns = [])
1819
{
1920
$recursiveIterator = new \RecursiveIteratorIterator(
2021
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS)
@@ -26,8 +27,15 @@ public function scan($dir, array $patterns = [])
2627
continue;
2728
}
2829

30+
$filePath = str_replace('\\', '/', $file->getRealPath());
31+
if (!empty($excludePatterns)) {
32+
foreach ($excludePatterns as $excludePattern) {
33+
if (preg_match($excludePattern, $filePath)) {
34+
continue 2;
35+
}
36+
}
37+
}
2938
foreach ($patterns as $type => $pattern) {
30-
$filePath = str_replace('\\', '/', $file->getRealPath());
3139
if (preg_match($pattern, $filePath)) {
3240
$output[$type][] = $filePath;
3341
break;

dev/tools/Magento/Tools/Di/compiler.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
'extra-classes-file=s' => 'path to file with extra proxies and factories to generate',
3333
'generation=s' => 'absolute path to generated classes, <magento_root>/var/generation by default',
3434
'di=s' => 'absolute path to DI definitions directory, <magento_root>/var/di by default',
35+
'exclude-pattern=s' => 'allows to exclude Paths from compilation (default is #[\\\\/]m1[\\\\/]#i)',
3536
]
3637
);
3738
$opt->parse();
3839

3940
$generationDir = $opt->getOption('generation') ? $opt->getOption('generation') : $rootDir . '/var/generation';
4041
$diDir = $opt->getOption('di') ? $opt->getOption('di') : $rootDir . '/var/di';
42+
$fileExcludePatterns = $opt->getOption('exclude-pattern') ?
43+
[$opt->getOption('exclude-pattern')] : ['#[\\\\/]M1[\\\\/]#i'];
4144
$relationsFile = $diDir . '/relations.ser';
4245
$pluginDefFile = $diDir . '/plugins.ser';
4346

@@ -60,7 +63,7 @@
6063
$filePatterns = ['php' => '/.*\.php$/', 'di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'];
6164
$codeScanDir = realpath($rootDir . '/app');
6265
$directoryScanner = new Scanner\DirectoryScanner();
63-
$files = $directoryScanner->scan($codeScanDir, $filePatterns);
66+
$files = $directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns);
6467
$files['additional'] = [$opt->getOption('extra-classes-file')];
6568
$entities = [];
6669

@@ -144,11 +147,13 @@
144147
$validator = new \Magento\Framework\Code\Validator();
145148
$validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
146149
$validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
150+
$classesScanner = new \Magento\Tools\Di\Code\Reader\ClassesScanner();
151+
$classesScanner->addExcludePatterns($fileExcludePatterns);
147152

148153
$directoryInstancesNamesList = new \Magento\Tools\Di\Code\Reader\InstancesNamesList\Directory(
149154
$log,
150155
new \Magento\Framework\Code\Reader\ClassReader(),
151-
new \Magento\Tools\Di\Code\Reader\ClassesScanner(),
156+
$classesScanner,
152157
$validator,
153158
$generationDir
154159
);

nginx.conf.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# listen 80;
1414
# server_name mage.dev;
1515
# set $MAGE_ROOT /var/www/magento2;
16-
# set $MAGE_MODE develop;
16+
# set $MAGE_MODE developer;
1717
# include /vagrant/magento2/nginx.conf.sample;
1818
# }
1919

0 commit comments

Comments
 (0)