Skip to content

Commit d860890

Browse files
committed
MAGETWO-38031: [GITHUB] Allow modules to live outside of app/code directory #1206
Code cleanup
1 parent b9049a0 commit d860890

File tree

4 files changed

+93
-86
lines changed

4 files changed

+93
-86
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct(
8686
public function load()
8787
{
8888
$result = [];
89-
foreach ($this->getModuleConfigs() as $contents) {
89+
foreach ($this->getModuleConfigs() as list($file, $contents)) {
9090
try {
9191
$this->parser->loadXML($contents);
9292
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -107,7 +107,12 @@ public function load()
107107
}
108108

109109
/**
110-
* Returns a traversable yielding content of all module.xml files
110+
* Returns module config data and a path to the module.xml file.
111+
*
112+
* Example of data returned by generator:
113+
* <code>
114+
* [ 'vendor/module/etc/module.xml', '<xml>contents</xml>' ]
115+
* </code>
111116
*
112117
* @return \Traversable
113118
*
@@ -117,12 +122,12 @@ private function getModuleConfigs()
117122
{
118123
$modulesDir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
119124
foreach ($modulesDir->search('*/*/etc/module.xml') as $filePath) {
120-
yield $modulesDir->readFile($filePath);
125+
yield [$filePath, $modulesDir->readFile($filePath)];
121126
}
122127

123128
foreach ($this->moduleRegistry->getModulePaths() as $modulePath) {
124129
$filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, "$modulePath/etc/module.xml");
125-
yield $this->filesystemDriver->fileGetContents($filePath);
130+
yield [$filePath, $this->filesystemDriver->fileGetContents($filePath)];
126131
}
127132
}
128133

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +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-
}
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: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
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-
}
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+
* @return void
28+
*/
29+
public static function registerModule($moduleName, $path)
30+
{
31+
self::$modulePaths[$moduleName] = $path;
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getModulePaths()
38+
{
39+
return self::$modulePaths;
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function getModulePath($moduleName)
46+
{
47+
return isset(self::$modulePaths[$moduleName]) ? self::$modulePaths[$moduleName] : null;
48+
}
49+
}

lib/internal/Magento/Framework/Module/Test/Unit/ModuleList/LoaderTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ class LoaderTest extends \PHPUnit_Framework_TestCase
3535
*/
3636
private $converter;
3737

38-
/*
38+
/**
3939
* @var \PHPUnit_Framework_MockObject_MockObject
4040
*/
4141
private $parser;
4242

43-
/*
43+
/**
4444
* @var \PHPUnit_Framework_MockObject_MockObject
4545
*/
4646
private $registry;
4747

48-
/*
48+
/**
4949
* @var \PHPUnit_Framework_MockObject_MockObject
5050
*/
5151
private $driver;
@@ -75,7 +75,7 @@ public function testLoad()
7575
{
7676
$fixtures = [
7777
'a' => ['name' => 'a', 'sequence' => []], // a is on its own
78-
'b' => ['name' => 'b', 'sequence' => ['d']], // b is after c
78+
'b' => ['name' => 'b', 'sequence' => ['d']], // b is after d
7979
'c' => ['name' => 'c', 'sequence' => ['e']], // c is after e
8080
'd' => ['name' => 'd', 'sequence' => ['c']], // d is after c
8181
'e' => ['name' => 'e', 'sequence' => ['a']], // e is after a
@@ -89,14 +89,15 @@ public function testLoad()
8989
['c', null, null, self::$sampleXml],
9090
]));
9191
$this->driver->expects($this->exactly(2))->method('fileGetContents')->will($this->returnValueMap([
92-
['/path/to/d', null, null, self::$sampleXml],
93-
['/path/to/e', null, null, self::$sampleXml],
92+
['/path/to/d/etc/module.xml', null, null, self::$sampleXml],
93+
['/path/to/e/etc/module.xml', null, null, self::$sampleXml],
9494
]));
9595
$index = 0;
9696
foreach ($fixtures as $name => $fixture) {
9797
$this->converter->expects($this->at($index++))->method('convert')->willReturn([$name => $fixture]);
9898
}
99-
$this->parser->expects($this->atLeastOnce())->method('loadXML');
99+
$this->parser->expects($this->atLeastOnce())->method('loadXML')
100+
->with(self::$sampleXml);
100101
$this->parser->expects($this->atLeastOnce())->method('getDom');
101102
$result = $this->loader->load();
102103
$this->assertSame(['a', 'e', 'c', 'd', 'b'], array_keys($result));

0 commit comments

Comments
 (0)