Skip to content

Commit b9049a0

Browse files
committed
Merge branch 'modules-in-vendor2' of https://github.com/joshdifabio/magento2 into MAGETWO-38031-vendor
2 parents ea7b254 + f616564 commit b9049a0

File tree

11 files changed

+256
-42
lines changed

11 files changed

+256
-42
lines changed

app/etc/di.xml

100755100644
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<preference for="Magento\Framework\Config\CacheInterface" type="Magento\Framework\App\Cache\Type\Config" />
4545
<preference for="Magento\Framework\Config\ValidationStateInterface" type="Magento\Framework\App\Arguments\ValidationState" />
4646
<preference for="Magento\Framework\Module\ModuleListInterface" type="Magento\Framework\Module\ModuleList" />
47+
<preference for="Magento\Framework\Module\ModuleRegistryInterface" type="Magento\Framework\Module\Registrar" />
4748
<preference for="Magento\Framework\Event\ConfigInterface" type="Magento\Framework\Event\Config" />
4849
<preference for="Magento\Framework\Event\InvokerInterface" type="Magento\Framework\Event\Invoker\InvokerDefault" />
4950
<preference for="Magento\Framework\Interception\PluginListInterface" type="Magento\Framework\Interception\PluginList\PluginList" />
@@ -1075,6 +1076,11 @@
10751076
<argument name="overriddenBaseFiles" xsi:type="object">lessFileOverriddenBase</argument>
10761077
</arguments>
10771078
</type>
1079+
<type name="Magento\Framework\Module\ModuleList\Loader">
1080+
<arguments>
1081+
<argument name="filesystemDriver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
1082+
</arguments>
1083+
</type>
10781084
<type name="Magento\Framework\Module\Setup\MigrationData">
10791085
<arguments>
10801086
<argument name="data" xsi:type="array">

dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expected/circular.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"","2"
33

44
"Circular dependencies for each module:",""
5-
"magento/module-a","1"
6-
"magento/module-a->magento/module-b->magento/module-a"
7-
85
"magento/module-b","1"
96
"magento/module-b->magento/module-a->magento/module-b"
7+
8+
"magento/module-a","1"
9+
"magento/module-a->magento/module-b->magento/module-a"

dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expected/framework.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"","2"
33

44
"Dependencies for each module:",""
5-
"Magento\A","1"
5+
"Magento\B","1"
66
" -- Magento\Framework","1"
77

8-
"Magento\B","1"
8+
"Magento\A","1"
99
" -- Magento\Framework","1"

dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expected/modules.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Total number of dependencies","2","2","0"
33

44
"Dependencies for each module:","All","Hard","Soft"
5-
"magento/module-a","1","1","0"
6-
" -- magento/module-b","","1","0"
7-
85
"magento/module-b","1","1","0"
96
" -- magento/module-a","","1","0"
7+
8+
"magento/module-a","1","1","0"
9+
" -- magento/module-b","","1","0"

lib/internal/Magento/Framework/Module/Dir.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Filesystem;
1212
use Magento\Framework\Filesystem\Directory\ReadInterface;
13+
use Magento\Framework\Stdlib\String as StringHelper;
14+
use Magento\Framework\Module\ModuleRegistryInterface;
1315

1416
class Dir
1517
{
@@ -25,14 +27,26 @@ class Dir
2527
*/
2628
protected $_string;
2729

30+
/**
31+
* Module registry
32+
*
33+
* @var ModuleRegistryInterface
34+
*/
35+
private $moduleRegistry;
36+
2837
/**
2938
* @param Filesystem $filesystem
30-
* @param \Magento\Framework\Stdlib\String $string
39+
* @param StringHelper $string
40+
* @param ModuleRegistryInterface $moduleRegistry
3141
*/
32-
public function __construct(Filesystem $filesystem, \Magento\Framework\Stdlib\String $string)
33-
{
42+
public function __construct(
43+
Filesystem $filesystem,
44+
StringHelper $string,
45+
ModuleRegistryInterface $moduleRegistry
46+
) {
3447
$this->_modulesDirectory = $filesystem->getDirectoryRead(DirectoryList::MODULES);
3548
$this->_string = $string;
49+
$this->moduleRegistry = $moduleRegistry;
3650
}
3751

3852
/**
@@ -45,16 +59,18 @@ public function __construct(Filesystem $filesystem, \Magento\Framework\Stdlib\St
4559
*/
4660
public function getDir($moduleName, $type = '')
4761
{
48-
$path = $this->_string->upperCaseWords($moduleName, '_', '/');
62+
if (null === $path = $this->moduleRegistry->getModulePath($moduleName)) {
63+
$relativePath = $this->_string->upperCaseWords($moduleName, '_', '/');
64+
$path = $this->_modulesDirectory->getAbsolutePath($relativePath);
65+
}
66+
4967
if ($type) {
5068
if (!in_array($type, ['etc', 'i18n', 'view', 'Controller'])) {
5169
throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
5270
}
5371
$path .= '/' . $type;
5472
}
5573

56-
$result = $this->_modulesDirectory->getAbsolutePath($path);
57-
58-
return $result;
74+
return $path;
5975
}
6076
}

lib/internal/Magento/Framework/Module/ModuleList/Loader.php

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\Filesystem;
1111
use Magento\Framework\Module\Declaration\Converter\Dom;
1212
use Magento\Framework\Xml\Parser;
13+
use Magento\Framework\Module\ModuleRegistryInterface;
14+
use Magento\Framework\Filesystem\DriverInterface;
1315

1416
/**
1517
* Loader of module list information from the filesystem
@@ -37,19 +39,42 @@ class Loader
3739
*/
3840
private $parser;
3941

42+
/**
43+
* Module registry
44+
*
45+
* @var ModuleRegistryInterface
46+
*/
47+
private $moduleRegistry;
48+
49+
/**
50+
* Filesystem driver to allow reading of module.xml files which live outside of app/code
51+
*
52+
* @var DriverInterface
53+
*/
54+
private $filesystemDriver;
55+
4056
/**
4157
* Constructor
4258
*
4359
* @param Filesystem $filesystem
4460
* @param Dom $converter
4561
* @param Parser $parser
62+
* @param ModuleRegistryInterface $moduleRegistry
63+
* @param DriverInterface $filesystemDriver
4664
*/
47-
public function __construct(Filesystem $filesystem, Dom $converter, Parser $parser)
48-
{
65+
public function __construct(
66+
Filesystem $filesystem,
67+
Dom $converter,
68+
Parser $parser,
69+
ModuleRegistryInterface $moduleRegistry,
70+
DriverInterface $filesystemDriver
71+
) {
4972
$this->filesystem = $filesystem;
5073
$this->converter = $converter;
5174
$this->parser = $parser;
5275
$this->parser->initErrorHandler();
76+
$this->moduleRegistry = $moduleRegistry;
77+
$this->filesystemDriver = $filesystemDriver;
5378
}
5479

5580
/**
@@ -61,10 +86,7 @@ public function __construct(Filesystem $filesystem, Dom $converter, Parser $pars
6186
public function load()
6287
{
6388
$result = [];
64-
$dir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
65-
foreach ($dir->search('*/*/etc/module.xml') as $file) {
66-
$contents = $dir->readFile($file);
67-
89+
foreach ($this->getModuleConfigs() as $contents) {
6890
try {
6991
$this->parser->loadXML($contents);
7092
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -84,6 +106,26 @@ public function load()
84106
return $this->sortBySequence($result);
85107
}
86108

109+
/**
110+
* Returns a traversable yielding content of all module.xml files
111+
*
112+
* @return \Traversable
113+
*
114+
* @author Josh Di Fabio <joshdifabio@gmail.com>
115+
*/
116+
private function getModuleConfigs()
117+
{
118+
$modulesDir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
119+
foreach ($modulesDir->search('*/*/etc/module.xml') as $filePath) {
120+
yield $modulesDir->readFile($filePath);
121+
}
122+
123+
foreach ($this->moduleRegistry->getModulePaths() as $modulePath) {
124+
$filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, "$modulePath/etc/module.xml");
125+
yield $this->filesystemDriver->fileGetContents($filePath);
126+
}
127+
}
128+
87129
/**
88130
* Sort the list of modules using "sequence" key in meta-information
89131
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Module;
7+
8+
/**
9+
* @author Josh Di Fabio <joshdifabio@gmail.com>
10+
*/
11+
interface ModuleRegistryInterface
12+
{
13+
/**
14+
* Get list of Magento module paths
15+
*
16+
* Returns an array where key is fully-qualified module name and value is absolute path to module
17+
*
18+
* @return array
19+
*/
20+
public function getModulePaths();
21+
22+
/**
23+
* @param string $moduleName
24+
* @return null|string
25+
*/
26+
public function getModulePath($moduleName);
27+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Module;
7+
8+
/**
9+
* Provides ability to statically register modules which do not reside in the modules directory
10+
*
11+
* @author Josh Di Fabio <joshdifabio@gmail.com>
12+
*/
13+
class Registrar implements ModuleRegistryInterface
14+
{
15+
/**
16+
* Paths to modules
17+
*
18+
* @var string[]
19+
*/
20+
private static $modulePaths = [];
21+
22+
/**
23+
* Sets the location of a module. Necessary for modules which do not reside in modules directory
24+
*
25+
* @param string $moduleName Fully-qualified module name
26+
* @param string $path Absolute file path to the module
27+
*/
28+
public static function registerModule($moduleName, $path)
29+
{
30+
self::$modulePaths[$moduleName] = $path;
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function getModulePaths()
37+
{
38+
return self::$modulePaths;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function getModulePath($moduleName)
45+
{
46+
return isset(self::$modulePaths[$moduleName]) ? self::$modulePaths[$moduleName] : null;
47+
}
48+
}

lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class DirTest extends \PHPUnit_Framework_TestCase
2727
*/
2828
protected $directoryMock;
2929

30+
/**
31+
* @var \Magento\Framework\Module\ModuleRegistryInterface|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $moduleRegistryMock;
34+
3035
protected function setUp()
3136
{
3237
$this->filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false, false);
@@ -39,8 +44,14 @@ protected function setUp()
3944
false
4045
);
4146
$this->_stringMock = $this->getMock('Magento\Framework\Stdlib\String', [], [], '', false, false);
42-
43-
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
47+
$this->moduleRegistryMock = $this->getMock(
48+
'Magento\Framework\Module\ModuleRegistryInterface',
49+
[],
50+
[],
51+
'',
52+
false,
53+
false
54+
);
4455

4556
$this->filesystemMock->expects(
4657
$this->once()
@@ -50,11 +61,27 @@ protected function setUp()
5061
$this->returnValue($this->directoryMock)
5162
);
5263

53-
$this->_model = new \Magento\Framework\Module\Dir($this->filesystemMock, $this->_stringMock);
64+
$this->_model = new \Magento\Framework\Module\Dir(
65+
$this->filesystemMock,
66+
$this->_stringMock,
67+
$this->moduleRegistryMock
68+
);
5469
}
5570

5671
public function testGetDirModuleRoot()
5772
{
73+
$this->moduleRegistryMock->expects(
74+
$this->once()
75+
)->method(
76+
'getModulePath'
77+
)->with(
78+
'Test_Module'
79+
)->will(
80+
$this->returnValue(null)
81+
);
82+
83+
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
84+
5885
$this->directoryMock->expects(
5986
$this->once()
6087
)->method(
@@ -64,20 +91,39 @@ public function testGetDirModuleRoot()
6491
)->will(
6592
$this->returnValue('/Test/Module')
6693
);
94+
6795
$this->assertEquals('/Test/Module', $this->_model->getDir('Test_Module'));
6896
}
6997

98+
public function testGetDirModuleRootFromResolver()
99+
{
100+
$this->moduleRegistryMock->expects(
101+
$this->once()
102+
)->method(
103+
'getModulePath'
104+
)->with(
105+
'Test_Module2'
106+
)->will(
107+
$this->returnValue('/path/to/module')
108+
);
109+
110+
$this->assertEquals('/path/to/module', $this->_model->getDir('Test_Module2'));
111+
}
112+
70113
public function testGetDirModuleSubDir()
71114
{
115+
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
116+
72117
$this->directoryMock->expects(
73118
$this->once()
74119
)->method(
75120
'getAbsolutePath'
76121
)->with(
77-
'Test/Module/etc'
122+
'Test/Module'
78123
)->will(
79-
$this->returnValue('/Test/Module/etc')
124+
$this->returnValue('/Test/Module')
80125
);
126+
81127
$this->assertEquals('/Test/Module/etc', $this->_model->getDir('Test_Module', 'etc'));
82128
}
83129

@@ -87,6 +133,8 @@ public function testGetDirModuleSubDir()
87133
*/
88134
public function testGetDirModuleSubDirUnknown()
89135
{
136+
$this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
137+
90138
$this->_model->getDir('Test_Module', 'unknown');
91139
}
92140
}

0 commit comments

Comments
 (0)