-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow modules to live outside of app/code directory #1206
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f7e881c
Allow modules to live outside of app/code directory
joshdifabio f6664a5
Use filesystem driver instead of dir reader to read module.xml files …
joshdifabio 0d31f71
Correct some doc block errors
joshdifabio a108dab
Fix Module\DirTest and add test for new Resolver functionality
joshdifabio 7929585
Fix Module\ModuleList\LoaderTest and add assertions for new Resolver …
joshdifabio 05d5cbb
Framework\Module: Rename Dir\Resolver to Registrar and Dir\ResolverIn…
joshdifabio 593b799
Update setup DI config to reflect new module registrar classes
joshdifabio f616564
Fix flakey integration tests
joshdifabio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Module\Declaration\Converter\Dom; | ||
use Magento\Framework\Xml\Parser; | ||
use Magento\Framework\Module\ModuleRegistryInterface; | ||
use Magento\Framework\Filesystem\DriverInterface; | ||
|
||
/** | ||
* Loader of module list information from the filesystem | ||
|
@@ -37,19 +39,42 @@ class Loader | |
*/ | ||
private $parser; | ||
|
||
/** | ||
* Module registry | ||
* | ||
* @var ModuleRegistryInterface | ||
*/ | ||
private $moduleRegistry; | ||
|
||
/** | ||
* Filesystem driver to allow reading of module.xml files which live outside of app/code | ||
* | ||
* @var DriverInterface | ||
*/ | ||
private $filesystemDriver; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Filesystem $filesystem | ||
* @param Dom $converter | ||
* @param Parser $parser | ||
* @param ModuleRegistryInterface $moduleRegistry | ||
* @param DriverInterface $filesystemDriver | ||
*/ | ||
public function __construct(Filesystem $filesystem, Dom $converter, Parser $parser) | ||
{ | ||
public function __construct( | ||
Filesystem $filesystem, | ||
Dom $converter, | ||
Parser $parser, | ||
ModuleRegistryInterface $moduleRegistry, | ||
DriverInterface $filesystemDriver | ||
) { | ||
$this->filesystem = $filesystem; | ||
$this->converter = $converter; | ||
$this->parser = $parser; | ||
$this->parser->initErrorHandler(); | ||
$this->moduleRegistry = $moduleRegistry; | ||
$this->filesystemDriver = $filesystemDriver; | ||
} | ||
|
||
/** | ||
|
@@ -61,10 +86,7 @@ public function __construct(Filesystem $filesystem, Dom $converter, Parser $pars | |
public function load() | ||
{ | ||
$result = []; | ||
$dir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES); | ||
foreach ($dir->search('*/*/etc/module.xml') as $file) { | ||
$contents = $dir->readFile($file); | ||
|
||
foreach ($this->getModuleConfigs() as $contents) { | ||
try { | ||
$this->parser->loadXML($contents); | ||
} catch (\Magento\Framework\Exception\LocalizedException $e) { | ||
|
@@ -84,6 +106,26 @@ public function load() | |
return $this->sortBySequence($result); | ||
} | ||
|
||
/** | ||
* Returns a traversable yielding content of all module.xml files | ||
* | ||
* @return \Traversable | ||
* | ||
* @author Josh Di Fabio <[email protected]> | ||
*/ | ||
private function getModuleConfigs() | ||
{ | ||
$modulesDir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES); | ||
foreach ($modulesDir->search('*/*/etc/module.xml') as $filePath) { | ||
yield $modulesDir->readFile($filePath); | ||
} | ||
|
||
foreach ($this->moduleRegistry->getModulePaths() as $modulePath) { | ||
$filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, "$modulePath/etc/module.xml"); | ||
yield $this->filesystemDriver->fileGetContents($filePath); | ||
} | ||
} | ||
|
||
/** | ||
* Sort the list of modules using "sequence" key in meta-information | ||
* | ||
|
27 changes: 27 additions & 0 deletions
27
lib/internal/Magento/Framework/Module/ModuleRegistryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\Module; | ||
|
||
/** | ||
* @author Josh Di Fabio <[email protected]> | ||
*/ | ||
interface ModuleRegistryInterface | ||
{ | ||
/** | ||
* Get list of Magento module paths | ||
* | ||
* Returns an array where key is fully-qualified module name and value is absolute path to module | ||
* | ||
* @return array | ||
*/ | ||
public function getModulePaths(); | ||
|
||
/** | ||
* @param string $moduleName | ||
* @return null|string | ||
*/ | ||
public function getModulePath($moduleName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\Framework\Module; | ||
|
||
/** | ||
* Provides ability to statically register modules which do not reside in the modules directory | ||
* | ||
* @author Josh Di Fabio <[email protected]> | ||
*/ | ||
class Registrar implements ModuleRegistryInterface | ||
{ | ||
/** | ||
* Paths to modules | ||
* | ||
* @var string[] | ||
*/ | ||
private static $modulePaths = []; | ||
|
||
/** | ||
* Sets the location of a module. Necessary for modules which do not reside in modules directory | ||
* | ||
* @param string $moduleName Fully-qualified module name | ||
* @param string $path Absolute file path to the module | ||
*/ | ||
public static function registerModule($moduleName, $path) | ||
{ | ||
self::$modulePaths[$moduleName] = $path; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getModulePaths() | ||
{ | ||
return self::$modulePaths; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getModulePath($moduleName) | ||
{ | ||
return isset(self::$modulePaths[$moduleName]) ? self::$modulePaths[$moduleName] : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's the first usage of generators in Magento 2 :)