作者:vran
项目:magento2-from-vendo
/**
* Load the packages information
*
* @return void
*/
private function load()
{
if ($this->packageModuleMap === null) {
$jsonData = $this->reader->getComposerJsonFiles()->toArray();
foreach (array_keys($this->loader->load()) as $moduleName) {
$moduleDir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::ROOT);
$key = $moduleDir->getRelativePath($this->dirReader->getModuleDir('', $moduleName) . '/composer.json');
if (isset($jsonData[$key])) {
$packageData = \Zend_Json::decode($jsonData[$key]);
if (isset($packageData['name'])) {
$this->packageModuleMap[$packageData['name']] = $moduleName;
}
if (isset($packageData['version'])) {
$this->modulePackageVersionMap[$moduleName] = $packageData['version'];
}
if (!empty($packageData['require'])) {
$this->requireMap[$moduleName] = array_keys($packageData['require']);
}
if (!empty($packageData['conflict'])) {
$this->conflictMap[$moduleName] = $packageData['conflict'];
}
}
}
}
}
作者:pradeep-wagent
项目:magento
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
switch ($scope) {
case 'global':
$iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
$themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
if ($themeConfigFile && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))) {
$iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($themeConfigFile));
} else {
$designPath = $this->resolver->resolve(RulePool::TYPE_FILE, 'etc/view.xml', $this->area, $this->currentTheme);
if (file_exists($designPath)) {
try {
$designDom = new \DOMDocument();
$designDom->load($designPath);
$iterator[$designPath] = $designDom->saveXML();
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Could not read config file'));
}
}
}
break;
default:
$iterator = $this->iteratorFactory->create([]);
break;
}
return $iterator;
}
作者:ViniciusAugust
项目:magento
/**
* @param string $area
* @param bool $forceReload
* @param array $cachedData
* @dataProvider dataProviderForTestLoadData
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function testLoadData($area, $forceReload, $cachedData)
{
$this->expectsSetConfig('themeId');
$this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('load')->will($this->returnValue(serialize($cachedData)));
if (!$forceReload && $cachedData !== false) {
$this->translate->loadData($area, $forceReload);
$this->assertEquals($cachedData, $this->translate->getData());
return;
}
$this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true));
// _loadModuleTranslation()
$this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name']));
$moduleData = ['module original' => 'module translated', 'module theme' => 'module-theme original translated', 'module pack' => 'module-pack original translated', 'module db' => 'module-db original translated'];
$this->modulesReader->expects($this->any())->method('getModuleDir')->will($this->returnValue('/app/module'));
$themeData = ['theme original' => 'theme translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'theme-pack translated overwrite', 'module db' => 'theme-db translated overwrite'];
$this->csvParser->expects($this->any())->method('getDataPairs')->will($this->returnValueMap([['/app/module/en_US.csv', 0, 1, $moduleData], ['/app/module/en_GB.csv', 0, 1, $moduleData], ['/theme.csv', 0, 1, $themeData]]));
// _loadThemeTranslation()
$this->viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue('/theme.csv'));
// _loadPackTranslation
$packData = ['pack original' => 'pack translated', 'module pack' => 'pack translated overwrite', 'module db' => 'pack-db translated overwrite'];
$this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue($packData));
// _loadDbTranslation()
$dbData = ['db original' => 'db translated', 'module db' => 'db translated overwrite'];
$this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData));
$this->cache->expects($this->exactly(1))->method('save');
$this->translate->loadData($area, $forceReload);
$expected = ['module original' => 'module translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'pack translated overwrite', 'module db' => 'db translated overwrite', 'theme original' => 'theme translated', 'pack original' => 'pack translated', 'db original' => 'db translated'];
$this->assertEquals($expected, $this->translate->getData());
}
作者:wclabhina
项目:Magento
/**
* Read locales
* @param \Magento\Framework\Module\Dir\Reader $moduleReader
*/
public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader)
{
$file = $moduleReader->getModuleDir('etc', 'BelVG_FacebookFree') . '/' . 'locale.xml';
if (is_readable($file)) {
$this->locales = simplexml_load_file($file);
}
}
作者:IlyaGluschenk
项目:test00
protected function setUp()
{
$this->moduleDir = 'moduleDirectory';
$this->moduleReader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', [], [], '', false);
$this->moduleReader->expects($this->any())->method('getModuleDir')->willReturn($this->moduleDir);
$this->schemaLocator = new SchemaLocator($this->moduleReader);
}
作者:vran
项目:magento2-from-vendo
/**
* Build DOM with initial XML contents and specifying identifier attributes for merging
*
* Format of $schemaFileType: array('etc', 'sql', 'data', 'i18n', 'view', 'Controller')
* Format of $schemaFileModule: 'Magento_XXXXX'
* Format of $schemaFileName: 'schema.xsd'
* Format of $idAttributes: array('name', 'id')
* Format of $contextXPath: array('/config/ui')
* The path to ID attribute name should not include any attribute notations or modifiers -- only node names
*
* @param string $schemaFileType
* @param string $schemaFileModule
* @param string $schemaFileName
* @param DirectoryReader $directoryReader
* @param bool $isMergeSimpleXMLElement
* @param array $contextXPath
* @param array $idAttributes
*/
public function __construct(DirectoryReader $directoryReader, $schemaFileType, $schemaFileModule, $schemaFileName, $isMergeSimpleXMLElement = false, array $contextXPath = [], array $idAttributes = [])
{
$this->schemaFilePath = $directoryReader->getModuleDir($schemaFileType, $schemaFileModule) . '/' . trim($schemaFileName, '/');
$this->isMergeSimpleXMLElement = $isMergeSimpleXMLElement;
$this->contextXPath = $contextXPath;
$this->idAttributes = $idAttributes;
}
作者:aies
项目:magento
/**
* @param \Magento\Framework\Module\Dir\Reader $modulesReader
* @param \Magento\Framework\Config\DomFactory $domConfigFactory
*/
public function __construct(\Magento\Framework\Module\Dir\Reader $modulesReader, \Magento\Framework\Config\DomFactory $domConfigFactory)
{
$this->_modulesReader = $modulesReader;
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = array(self::LAYOUT_SCHEMA_SINGLE_HANDLE => $this->_modulesReader->getModuleDir('etc', 'Magento_Core') . '/layout_single.xsd', self::LAYOUT_SCHEMA_MERGED => $this->_modulesReader->getModuleDir('etc', 'Magento_Core') . '/layout_merged.xsd');
}
作者:kidaa3
项目:magento2-platforms
protected function setUp()
{
$this->_xsdFile = $this->_xsdDir . '/address_formats.xsd';
$this->_moduleReader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', ['getModuleDir'], [], '', false);
$this->_moduleReader->expects($this->once())->method('getModuleDir')->with('etc', 'Magento_Customer')->will($this->returnValue($this->_xsdDir));
$this->_model = new \Magento\Customer\Model\Address\Config\SchemaLocator($this->_moduleReader);
}
作者:artmous
项目:Umc_Bas
/**
* constructor
*
* @param \Magento\Framework\Module\Dir\Reader $moduleReader
* @param $fileSchema
* @param null $mergedSchema
*/
public function __construct(Reader $moduleReader, $fileSchema, $mergedSchema = null)
{
if (is_null($mergedSchema)) {
$mergedSchema = $fileSchema . '_merged';
}
$this->schema = $moduleReader->getModuleDir('etc', 'Umc_Base') . '/umc/' . $mergedSchema . '.xsd';
$this->perFileSchema = $moduleReader->getModuleDir('etc', 'Umc_Base') . '/umc/' . $fileSchema . '.xsd';
}
作者:aies
项目:magento
/**
* @return bool
*/
public function hasLocalCopy()
{
$path = $this->_moduleReader->getModuleDir('etc', 'Magento_Adminhtml');
$directory = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MODULES_DIR);
if ($path && $directory->isDirectory($directory->getRelativePath($path))) {
return true;
}
return false;
}
作者:BlackIkeEagl
项目:magento2-continuousph
/**
* Save default translator
*/
protected function setUp()
{
$this->_defaultTranslator = \Magento\Framework\Validator\AbstractValidator::getDefaultTranslator();
$this->_objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$this->_validatorConfig = $this->getMockBuilder(
'Magento\Framework\Validator\Config'
)->setMethods(
['createValidatorBuilder', 'createValidator']
)->disableOriginalConstructor()->getMock();
$this->_objectManager->expects(
$this->at(0)
)->method(
'create'
)->with(
'Magento\Framework\Translate\Adapter'
)->will(
$this->returnValue(new \Magento\Framework\Translate\Adapter())
);
$this->_objectManager->expects(
$this->at(1)
)->method(
'create'
)->with(
'Magento\Framework\Validator\Config',
['configFiles' => ['/tmp/moduleOne/etc/validation.xml']]
)->will(
$this->returnValue($this->_validatorConfig)
);
// Config mock
$this->_config = $this->getMockBuilder(
'Magento\Framework\Module\Dir\Reader'
)->setMethods(
['getConfigurationFiles']
)->disableOriginalConstructor()->getMock();
$this->_config->expects(
$this->once()
)->method(
'getConfigurationFiles'
)->with(
'validation.xml'
)->will(
$this->returnValue(['/tmp/moduleOne/etc/validation.xml'])
);
// Translate adapter mock
$this->_translateAdapter = $this->getMockBuilder(
'Magento\Framework\TranslateInterface'
)->disableOriginalConstructor()->getMock();
$this->cache = $this->getMockBuilder(\Magento\Framework\Cache\FrontendInterface::class)
->getMockForAbstractClass();
}
作者:pradeep-wagent
项目:magento
public function setUp()
{
$this->componentRegistrar = $this->getMock('Magento\\Framework\\Component\\ComponentRegistrar', [], [], '', false);
$this->reader = $this->getMock('Magento\\Framework\\Module\\Dir\\Reader', [], [], '', false);
$this->componentRegistrar->expects($this->once())->method('getPaths')->will($this->returnValue(['A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E']));
$composerData = ['A/composer.json' => '{"name":"a", "require":{"b":"0.1"}, "conflict":{"c":"0.1"}, "version":"0.1"}', 'B/composer.json' => '{"name":"b", "require":{"d":"0.3"}, "version":"0.2"}', 'C/composer.json' => '{"name":"c", "require":{"e":"0.1"}, "version":"0.1"}', 'D/composer.json' => '{"name":"d", "conflict":{"c":"0.1"}, "version":"0.3"}', 'E/composer.json' => '{"name":"e", "version":"0.4"}'];
$fileIteratorMock = $this->getMock('Magento\\Framework\\Config\\FileIterator', [], [], '', false);
$fileIteratorMock->expects($this->once())->method('toArray')->will($this->returnValue($composerData));
$this->reader->expects($this->once())->method('getComposerJsonFiles')->will($this->returnValue($fileIteratorMock));
$this->packageInfo = new PackageInfo($this->reader, $this->componentRegistrar);
}
作者:tingyee
项目:magento
/**
* @param \Magento\Framework\Config\CacheInterface $cache
* @param ModuleReader $moduleReader
* @param string $actionInterface
* @param string $cacheKey
* @param array $reservedWords
*/
public function __construct(\Magento\Framework\Config\CacheInterface $cache, ModuleReader $moduleReader, $actionInterface = '\\Magento\\Framework\\App\\ActionInterface', $cacheKey = 'app_action_list', $reservedWords = [])
{
$this->reservedWords = array_merge($reservedWords, $this->reservedWords);
$this->actionInterface = $actionInterface;
$data = $cache->load($cacheKey);
if (!$data) {
$this->actions = $moduleReader->getActionFiles();
$cache->save(serialize($this->actions), $cacheKey);
} else {
$this->actions = unserialize($data);
}
}
作者:Doabilit
项目:magento2de
/**
* Init cached list of validation files
*/
protected function _initializeConfigList()
{
if (!$this->_configFiles) {
$this->_configFiles = $this->cache->load(self::CACHE_KEY);
if (!$this->_configFiles) {
$this->_configFiles = $this->moduleReader->getConfigurationFiles('validation.xml');
$this->cache->save(serialize($this->_configFiles), self::CACHE_KEY);
} else {
$this->_configFiles = unserialize($this->_configFiles);
}
}
}
作者:pierredewi
项目:MagentoExtension
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Module\Dir\Reader $configReader, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Mehulchaudhari\Geoip\Helper\Data $geoipHelper, array $data = [])
{
$this->_geoipHelper = $geoipHelper;
$this->_logger = $context->getLogger();
$this->_scopeConfig = $scopeConfig;
$this->_storeManager = $storeManager;
$this->libpath = $configReader->getModuleDir('', 'Mehulchaudhari_Geoip');
if (!function_exists('geoip_country_code_by_name') && $this->_geoipHelper->getConfig('general/apache_or_file') == 1) {
define('GEOIP_LOCAL', 1);
$geoIpInc = $this->libpath . '/lib/geoip.inc';
include $geoIpInc;
}
}
作者:pradeep-wagent
项目:magento
/**
* @param bool $check
*/
protected function getContentStep($check = true)
{
$resultPath = 'adminhtml/path/to/file.xml';
$includeXmlContent = '<config><item id="1"><test/></item><item id="2"></item></config>';
$modulesDirectoryMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMockForAbstractClass();
$this->readFactoryMock->expects($this->once())->method('create')->willReturn($modulesDirectoryMock);
$this->moduleReaderMock->expects($this->once())->method('getModuleDir')->with('etc', 'Module_Name')->willReturn('path/in/application/module');
$modulesDirectoryMock->expects($this->once())->method('isExist')->with($resultPath)->willReturn($check);
if ($check) {
$modulesDirectoryMock->expects($this->once())->method('isFile')->with($resultPath)->willReturn($check);
$modulesDirectoryMock->expects($this->once())->method('readFile')->with($resultPath)->willReturn($includeXmlContent);
}
}
作者:aies
项目:magento
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
switch ($scope) {
case 'global':
$iterator = $this->_moduleReader->getConfigurationFiles($filename);
break;
case 'design':
$iterator = $this->iteratorFactory->create($this->themesDirectory, $this->themesDirectory->search('/*/*/etc/' . $filename));
break;
default:
$iterator = $this->iteratorFactory->create($this->themesDirectory, array());
break;
}
return $iterator;
}
作者:nblai
项目:magescotc
/**
* Render view config object for current package and theme
*
* @param array $params
* @return \Magento\Framework\Config\View
*/
public function getViewConfig(array $params = [])
{
$this->assetRepo->updateDesignParams($params);
/** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
$currentTheme = $params['themeModel'];
$key = $currentTheme->getCode();
if (isset($this->viewConfigs[$key])) {
return $this->viewConfigs[$key];
}
$configFiles = $this->moduleReader->getConfigurationFiles(basename($this->filename))->toArray();
$themeConfigFile = $currentTheme->getCustomization()->getCustomViewConfigPath();
if (empty($themeConfigFile)
|| !$this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$themeConfigFile = $this->viewFileSystem->getFilename($this->filename, $params);
}
if ($themeConfigFile
&& $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$configFiles[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile(
$this->rootDirectory->getRelativePath($themeConfigFile)
);
}
$config = $this->viewFactory->create($configFiles);
$this->viewConfigs[$key] = $config;
return $config;
}
作者:pradeep-wagent
项目:magento
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
switch ($scope) {
case 'global':
$iterator = $this->_moduleReader->getConfigurationFiles($filename);
break;
case 'design':
$themePaths = $this->componentDirSearch->collectFiles(ComponentRegistrar::THEME, 'etc/' . $filename);
$iterator = $this->iteratorFactory->create($themePaths);
break;
default:
$iterator = $this->iteratorFactory->create([]);
break;
}
return $iterator;
}
作者:shabbirvividad
项目:magento
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
switch ($scope) {
case 'primary':
$directory = $this->filesystem->getDirectoryRead(DirectoryList::CONFIG);
$iterator = $this->iteratorFactory->create($directory, $directory->search('{' . $filename . ',*/' . $filename . '}'));
break;
case 'global':
$iterator = $this->_moduleReader->getConfigurationFiles($filename);
break;
default:
$iterator = $this->_moduleReader->getConfigurationFiles($scope . '/' . $filename);
break;
}
return $iterator;
}