Skip to content

Commit

Permalink
Merge pull request #111 from magento-mpi/public-pulls
Browse files Browse the repository at this point in the history
[Github] Merge public Github commits
  • Loading branch information
vpelipenko committed Feb 27, 2015
2 parents 116d26d + 8f68565 commit 71cd40d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
23 changes: 21 additions & 2 deletions dev/tools/Magento/Tools/Di/Code/Reader/ClassesScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@

class ClassesScanner
{
/**
* @var array
*/
protected $excludePatterns = [];

/**
* Adds exclude patterns
*
* @param array $excludePatterns
* @return void
*/
public function addExcludePatterns(array $excludePatterns)
{
$this->excludePatterns = array_merge($this->excludePatterns, $excludePatterns);
}

/**
* Retrieves list of classes for given path
*
* @param string $path
*
* @return array
*
* @throws FilesystemException
*/
public function getList($path)
Expand All @@ -37,6 +51,11 @@ public function getList($path)
if ($fileItem->getExtension() !== 'php') {
continue;
}
foreach ($this->excludePatterns as $excludePattern) {
if (preg_match($excludePattern, $fileItem->getRealPath())) {
continue 2;
}
}
$fileScanner = new FileScanner($fileItem->getRealPath());
$classNames = $fileScanner->getClassNames();
foreach ($classNames as $className) {
Expand Down
12 changes: 10 additions & 2 deletions dev/tools/Magento/Tools/Di/Code/Scanner/DirectoryScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class DirectoryScanner
*
* @param string $dir
* @param array $patterns
* @param string[] $excludePatterns
* @return array
*/
public function scan($dir, array $patterns = [])
public function scan($dir, array $patterns = [], array $excludePatterns = [])
{
$recursiveIterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS)
Expand All @@ -26,8 +27,15 @@ public function scan($dir, array $patterns = [])
continue;
}

$filePath = str_replace('\\', '/', $file->getRealPath());
if (!empty($excludePatterns)) {
foreach ($excludePatterns as $excludePattern) {
if (preg_match($excludePattern, $filePath)) {
continue 2;
}
}
}
foreach ($patterns as $type => $pattern) {
$filePath = str_replace('\\', '/', $file->getRealPath());
if (preg_match($pattern, $filePath)) {
$output[$type][] = $filePath;
break;
Expand Down
9 changes: 7 additions & 2 deletions dev/tools/Magento/Tools/Di/compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
'extra-classes-file=s' => 'path to file with extra proxies and factories to generate',
'generation=s' => 'absolute path to generated classes, <magento_root>/var/generation by default',
'di=s' => 'absolute path to DI definitions directory, <magento_root>/var/di by default',
'exclude-pattern=s' => 'allows to exclude Paths from compilation (default is #[\\\\/]m1[\\\\/]#i)',
]
);
$opt->parse();

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

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

Expand Down Expand Up @@ -144,11 +147,13 @@
$validator = new \Magento\Framework\Code\Validator();
$validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
$validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
$classesScanner = new \Magento\Tools\Di\Code\Reader\ClassesScanner();
$classesScanner->addExcludePatterns($fileExcludePatterns);

$directoryInstancesNamesList = new \Magento\Tools\Di\Code\Reader\InstancesNamesList\Directory(
$log,
new \Magento\Framework\Code\Reader\ClassReader(),
new \Magento\Tools\Di\Code\Reader\ClassesScanner(),
$classesScanner,
$validator,
$generationDir
);
Expand Down
2 changes: 1 addition & 1 deletion nginx.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# listen 80;
# server_name mage.dev;
# set $MAGE_ROOT /var/www/magento2;
# set $MAGE_MODE develop;
# set $MAGE_MODE developer;
# include /vagrant/magento2/nginx.conf.sample;
# }

Expand Down

0 comments on commit 71cd40d

Please sign in to comment.