Skip to content

Commit

Permalink
Merge pull request #288 from magento-extensibility/MAGETWO-44270-fata…
Browse files Browse the repository at this point in the history
…l-memory-allocation

[Extensibility] Bug Fixes
  • Loading branch information
He, Joan(johe) committed Jan 13, 2016
2 parents 26a148a + fadfce0 commit 1db2d56
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 264 deletions.
7 changes: 7 additions & 0 deletions app/code/Magento/Cron/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\App\AreaList">
<arguments>
<argument name="areas" xsi:type="array">
<item name="crontab" xsi:type="null" />
</argument>
</arguments>
</type>
</config>
10 changes: 10 additions & 0 deletions lib/internal/Magento/Framework/Config/Reader/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface
*/
protected $validationState;

/**
* @var string
*/
protected $_defaultScope;

/**
* @var string
*/
protected $_schemaFile;

/**
* Constructor
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function testCreatePositive($type)
)->will(
$this->returnValue($elementMock)
);
$this->assertSame($elementMock, $this->_factory->create($type));
$element = $this->_factory->create($type);
$this->assertSame($elementMock, $element);
unset($elementMock, $element);
}

/**
Expand All @@ -73,7 +75,9 @@ public function testCreatePositiveWithNotEmptyConfig($type)
)->will(
$this->returnValue($elementMock)
);
$this->assertSame($elementMock, $this->_factory->create($type, $config));
$element = $this->_factory->create($type, $config);
$this->assertSame($elementMock, $element);
unset($elementMock, $element);
}

/**
Expand Down
25 changes: 4 additions & 21 deletions setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
'application' => $excludedModulePaths,
'framework' => $excludedLibraryPaths
];
$dataAttributesIncludePattern = [
'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/'
];
$this->configureObjectManager($output);

$operations = $this->getOperationsConfiguration(
$compiledPathsList,
$dataAttributesIncludePattern
);
$operations = $this->getOperationsConfiguration($compiledPathsList);

try {
$this->cleanupFilesystem(
Expand Down Expand Up @@ -286,33 +280,22 @@ private function configureObjectManager(OutputInterface $output)
* Returns operations configuration
*
* @param array $compiledPathsList
* @param array $dataAttributesIncludePattern
* @return array
*/
private function getOperationsConfiguration(
array $compiledPathsList,
array $dataAttributesIncludePattern
array $compiledPathsList
) {
$excludePatterns = [];
foreach ($this->excludedPathsList as $excludedPaths) {
$excludePatterns = array_merge($excludedPaths, $excludePatterns);
}

$operations = [
OperationFactory::PROXY_GENERATOR => [
'paths' => $compiledPathsList['application'],
'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'],
'excludePatterns' => $excludePatterns,
],
OperationFactory::PROXY_GENERATOR => [],
OperationFactory::REPOSITORY_GENERATOR => [
'paths' => $compiledPathsList['application'],
'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'],
'excludePatterns' => $excludePatterns,
],
OperationFactory::DATA_ATTRIBUTES_GENERATOR => [
'paths' => $compiledPathsList['application'],
'filePatterns' => $dataAttributesIncludePattern
],
OperationFactory::DATA_ATTRIBUTES_GENERATOR => [],
OperationFactory::APPLICATION_CODE_GENERATOR => [
'paths' => [
$compiledPathsList['application'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public function generateCode($generationDir, $fileExcludePatterns, $input)
$directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns)
);
}
$this->files['di'][] = $this->directoryList->getPath(
\Magento\Framework\App\Filesystem\DirectoryList::CONFIG
) . '/di.xml';
$this->files['additional'] = [$input->getOption(self::INPUT_KEY_EXTRA_CLASSES_FILE)];
$repositoryScanner = new Scanner\RepositoryScanner();
$repositories = $repositoryScanner->collectEntities($this->files['di']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

class ProxyGenerator implements OperationInterface
{
/**
* @var Scanner\DirectoryScanner
*/
private $directoryScanner;

/**
* @var Scanner\XmlScanner
*/
Expand All @@ -27,18 +22,23 @@ class ProxyGenerator implements OperationInterface
private $data;

/**
* @param Scanner\DirectoryScanner $directoryScanner
* @var Scanner\ConfigurationScanner
*/
private $configurationScanner;

/**
* @param Scanner\XmlScanner $proxyScanner
* @param Scanner\ConfigurationScanner $configurationScanner
* @param array $data
*/
public function __construct(
Scanner\DirectoryScanner $directoryScanner,
Scanner\XmlScanner $proxyScanner,
\Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner $configurationScanner,
$data = []
) {
$this->directoryScanner = $directoryScanner;
$this->proxyScanner = $proxyScanner;
$this->data = $data;
$this->configurationScanner = $configurationScanner;
}

/**
Expand All @@ -48,19 +48,8 @@ public function __construct(
*/
public function doOperation()
{
if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns'])
!== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
return;
}

$files = [];
foreach ($this->data['paths'] as $path) {
$files = array_merge_recursive(
$files,
$this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns'])
);
}
$proxies = $this->proxyScanner->collectEntities($files['di']);
$files = $this->configurationScanner->scan('di.xml');
$proxies = $this->proxyScanner->collectEntities($files);
foreach ($proxies as $entityName) {
class_exists($entityName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

class RepositoryGenerator implements OperationInterface
{
/**
* @var Scanner\DirectoryScanner
*/
private $directoryScanner;

/**
* @var Scanner\RepositoryScanner
*/
Expand All @@ -33,21 +28,26 @@ class RepositoryGenerator implements OperationInterface
private $classesScanner;

/**
* @param Scanner\DirectoryScanner $directoryScanner
* @var Scanner\ConfigurationScanner
*/
private $configurationScanner;

/**
* @param ClassesScanner $classesScanner
* @param Scanner\RepositoryScanner $repositoryScanner
* @param Scanner\ConfigurationScanner $configurationScanner
* @param array $data
*/
public function __construct(
Scanner\DirectoryScanner $directoryScanner,
ClassesScanner $classesScanner,
Scanner\RepositoryScanner $repositoryScanner,
\Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner $configurationScanner,
$data = []
) {
$this->directoryScanner = $directoryScanner;
$this->repositoryScanner = $repositoryScanner;
$this->data = $data;
$this->classesScanner = $classesScanner;
$this->configurationScanner = $configurationScanner;
}

/**
Expand All @@ -57,23 +57,12 @@ public function __construct(
*/
public function doOperation()
{
if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns'])
!== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
return;
}

foreach ($this->data['paths'] as $path) {
$this->classesScanner->getList($path);
}
$this->repositoryScanner->setUseAutoload(false);
$files = [];
foreach ($this->data['paths'] as $path) {
$files = array_merge_recursive(
$files,
$this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns'])
);
}
$repositories = $this->repositoryScanner->collectEntities($files['di']);
$files = $this->configurationScanner->scan('di.xml');
$repositories = $this->repositoryScanner->collectEntities($files);
foreach ($repositories as $entityName) {
class_exists($entityName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
class ServiceDataAttributesGenerator implements OperationInterface
{
/**
* @var Scanner\DirectoryScanner
*/
private $directoryScanner;

/**
* @var Scanner\ServiceDataAttributesScanner
*/
Expand All @@ -32,18 +27,23 @@ class ServiceDataAttributesGenerator implements OperationInterface
private $data;

/**
* @param Scanner\DirectoryScanner $directoryScanner
* @param Scanner\ServiceDataAttributesScanner $repositoryScanner
* @var Scanner\ConfigurationScanner
*/
private $configurationScanner;

/**
* @param Scanner\ServiceDataAttributesScanner $serviceDataAttributesScanner
* @param Scanner\ConfigurationScanner $configurationScanner
* @param array $data
*/
public function __construct(
Scanner\DirectoryScanner $directoryScanner,
Scanner\ServiceDataAttributesScanner $repositoryScanner,
Scanner\ServiceDataAttributesScanner $serviceDataAttributesScanner,
\Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner $configurationScanner,
$data = []
) {
$this->directoryScanner = $directoryScanner;
$this->serviceDataAttributesScanner = $repositoryScanner;
$this->serviceDataAttributesScanner = $serviceDataAttributesScanner;
$this->data = $data;
$this->configurationScanner = $configurationScanner;
}

/**
Expand All @@ -53,15 +53,8 @@ public function __construct(
*/
public function doOperation()
{
if (array_diff(array_keys($this->data), ['filePatterns', 'paths'])
!== array_diff(['filePatterns', 'paths'], array_keys($this->data))) {
return;
}
$files = [];
foreach ($this->data['paths'] as $path) {
$files = array_merge_recursive($files, $this->directoryScanner->scan($path, $this->data['filePatterns']));
}
$repositories = $this->serviceDataAttributesScanner->collectEntities($files['extension_attributes']);
$files = $this->configurationScanner->scan('extension_attributes.xml');
$repositories = $this->serviceDataAttributesScanner->collectEntities($files);
foreach ($repositories as $entityName) {
class_exists($entityName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Setup\Module\Di\Code\Scanner;

use Magento\Framework\App\Area;

class ConfigurationScanner
{
/**
* ConfigurationScanner constructor.
*
* @param \Magento\Framework\App\Config\FileResolver $fileResolver
* @param \Magento\Framework\App\AreaList $areaList
*/
public function __construct(
\Magento\Framework\App\Config\FileResolver $fileResolver,
\Magento\Framework\App\AreaList $areaList
) {
$this->fileResolver = $fileResolver;
$this->areaList = $areaList;
}

/**
* Scan configuration files
*
* @param string $fileName
*
* @return array array of paths to the configuration files
*/
public function scan($fileName)
{
$files = [];
$areaCodes = array_merge(
['primary', Area::AREA_GLOBAL],
$this->areaList->getCodes()
);
foreach ($areaCodes as $area) {
$files = array_merge_recursive(
$files,
$this->fileResolver->get($fileName, $area)->toArray()
);
}
return array_keys($files);
}
}
Loading

0 comments on commit 1db2d56

Please sign in to comment.