/** * Retrieve the list of resources declared by the given module * * @param string $moduleName * @return string[] */ public function getResourceList($moduleName) { if (!isset($this->_moduleResources[$moduleName])) { // Process sub-directories within modules sql directory $moduleSqlDir = $this->_moduleReader->getModuleDir('sql', $moduleName); $sqlResources = array(); $resourceDirs = glob($moduleSqlDir . '/*', GLOB_ONLYDIR); if (!empty($resourceDirs)) { foreach ($resourceDirs as $resourceDir) { $sqlResources[] = basename($resourceDir); } } $moduleDataDir = $this->_moduleReader->getModuleDir('data', $moduleName); // Process sub-directories within modules data directory $dataResources = array(); $resourceDirs = glob($moduleDataDir . '/*', GLOB_ONLYDIR); if (!empty($resourceDirs)) { foreach ($resourceDirs as $resourceDir) { $dataResources[] = basename($resourceDir); } } $this->_moduleResources[$moduleName] = array_unique(array_merge($sqlResources, $dataResources)); } return $this->_moduleResources[$moduleName]; }
/** * @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'); }
public function testGetModuleDirWhenCustomDirIsSet() { $moduleDir = 'app/code/Test/Module/etc/custom'; $this->_dirsMock->expects($this->never())->method('getDir'); $this->_model->setModuleDir('Test_Module', 'etc', $moduleDir); $this->assertEquals($moduleDir, $this->_model->getModuleDir(Dir::MODULE_ETC_DIR, 'Test_Module')); }
/** * 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'; }
/** * @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; }
/** * 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); } }
/** * 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; }
/** * Return generated varnish.vcl configuration file * * @param string $vclTemplatePath * @return string * @api */ public function getVclFile($vclTemplatePath) { $moduleEtcPath = $this->reader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_PageCache'); $configFilePath = $moduleEtcPath . '/' . $this->_scopeConfig->getValue($vclTemplatePath); $directoryRead = $this->readFactory->create($moduleEtcPath); $configFilePath = $directoryRead->getRelativePath($configFilePath); $data = $directoryRead->readFile($configFilePath); return strtr($data, $this->_getReplacements()); }
/** * Get content of include file (in adminhtml area) * * @param string $includePath * @return string * @throws LocalizedException */ protected function getContent($includePath) { // <include path="Magento_Payment::my_payment.xml" /> list($moduleName, $filename) = explode('::', $includePath); $path = 'adminhtml/' . $filename; $directoryRead = $this->readFactory->create($this->moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, $moduleName)); if ($directoryRead->isExist($path) && $directoryRead->isFile($path)) { return $directoryRead->readFile($path); } throw new LocalizedException(__('The file "%1" does not exist', $path)); }
/** * Download sample file action * * @return \Magento\Framework\Controller\Result\Raw */ public function execute() { $fileName = $this->getRequest()->getParam('filename') . '.csv'; $moduleDir = $this->reader->getModuleDir('', self::SAMPLE_FILES_MODULE); $fileAbsolutePath = $moduleDir . '/' . $fileName; $directoryRead = $this->readFactory->create($moduleDir); $filePath = $directoryRead->getRelativePath($fileAbsolutePath); if (!$directoryRead->isFile($filePath)) { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $this->messageManager->addError(__('There is no sample file for this entity.')); $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/import'); return $resultRedirect; } $fileSize = isset($directoryRead->stat($filePath)['size']) ? $directoryRead->stat($filePath)['size'] : null; $this->fileFactory->create($fileName, null, DirectoryList::VAR_DIR, 'application/octet-stream', $fileSize); /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); $resultRaw->setContents($directoryRead->readFile($filePath)); return $resultRaw; }
/** * Get content include file (in adminhtml area) * * @param string $includePath * @return string * @throws LocalizedException */ protected function getContent($includePath) { $modulesDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MODULES); // <include path="Magento_Payment::my_payment.xml" /> list($moduleName, $filename) = explode('::', $includePath); $file = $this->moduleReader->getModuleDir('etc', $moduleName) . '/adminhtml/' . $filename; $path = $modulesDirectory->getRelativePath($file); if ($modulesDirectory->isExist($path) && $modulesDirectory->isFile($path)) { return $modulesDirectory->readFile($path); } throw new LocalizedException(__('The file "' . $path . '" does not exist')); }
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; } }
/** * Get persistent XML config xpath * * @return \DOMXPath * @throws \Magento\Framework\Model\Exception */ protected function _getConfigDomXPath() { if (is_null($this->_configDomXPath)) { $filePath = $this->_modulesDirectory->getRelativePath($this->_configFilePath); $isFile = $this->_modulesDirectory->isFile($filePath); $isReadable = $this->_modulesDirectory->isReadable($filePath); if (!$isFile || !$isReadable) { throw new \Magento\Framework\Model\Exception(__('We cannot load the configuration from file %1.', $this->_configFilePath)); } $xml = $this->_modulesDirectory->readFile($filePath); /** @var \Magento\Framework\Config\Dom $configDom */ $configDom = $this->_domFactory->createDom(array('xml' => $xml, 'idAttributes' => array('config/instances/blocks/reference' => 'id'), 'schemaFile' => $this->_moduleReader->getModuleDir('etc', 'Magento_Persistent') . '/persistent.xsd')); $this->_configDomXPath = new \DOMXPath($configDom->getDom()); } return $this->_configDomXPath; }
/** * Internal constructor * * @return void */ protected function _construct() { parent::_construct(); $paymentCode = $this->_getCheckout()->getQuote()->getPayment()->getMethod(); if (in_array($paymentCode, $this->_hssHelper->getHssMethods())) { $this->_paymentMethodCode = $paymentCode; $templatePath = str_replace('_', '', $paymentCode); $templateFile = "{$templatePath}/iframe.phtml"; $directory = $this->readFactory->create($this->reader->getModuleDir('', 'Magento_Paypal')); $file = $this->resolver->getTemplateFileName($templateFile, ['module' => 'Magento_Paypal']); if ($file && $directory->isExist($directory->getRelativePath($file))) { $this->setTemplate($templateFile); } else { $this->setTemplate('hss/iframe.phtml'); } } }
/** * Retrieve available Data install/upgrade files for current module * * @param string $actionType * @param string $fromVersion * @param string $toVersion * @return array */ protected function _getAvailableDataFiles($actionType, $fromVersion, $toVersion) { $modName = (string) $this->_moduleConfig['name']; $files = []; $filesDir = $this->_modulesReader->getModuleDir('data', $modName) . '/' . $this->_resourceName; $modulesDirPath = $this->modulesDir->getRelativePath($filesDir); if ($this->modulesDir->isDirectory($modulesDirPath) && $this->modulesDir->isReadable($modulesDirPath)) { $regExp = sprintf('#%s-(.*)\\.php$#i', $actionType); foreach ($this->modulesDir->read($modulesDirPath) as $file) { $matches = []; if (preg_match($regExp, $file, $matches)) { $files[$matches[1]] = $this->modulesDir->getAbsolutePath($file); } } } if (empty($files)) { return []; } return $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $files); }
/** * Get persistent XML config xpath * * @return \DOMXPath * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getConfigDomXPath() { if ($this->_configDomXPath === null) { $dir = explode("/", $this->_configFilePath); array_pop($dir); $dir = implode("/", $dir); $directoryRead = $this->readFactory->create($dir); $filePath = $directoryRead->getRelativePath($this->_configFilePath); $isFile = $directoryRead->isFile($filePath); $isReadable = $directoryRead->isReadable($filePath); if (!$isFile || !$isReadable) { throw new \Magento\Framework\Exception\LocalizedException(__('We cannot load the configuration from file %1.', $this->_configFilePath)); } $xml = $directoryRead->readFile($filePath); /** @var \Magento\Framework\Config\Dom $configDom */ $configDom = $this->_domFactory->createDom(['xml' => $xml, 'idAttributes' => ['config/instances/blocks/reference' => 'id'], 'schemaFile' => $this->_moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Persistent') . '/persistent.xsd']); $this->_configDomXPath = new \DOMXPath($configDom->getDom()); } return $this->_configDomXPath; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir('etc', 'Magento_Integration') . '/integration/config.xsd'; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Cron') . '/' . 'crontab.xsd'; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Directory') . '/zip_codes.xsd'; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Catalog') . '/catalog_attributes.xsd'; }
/** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory * @param \Psr\Log\LoggerInterface $logger * @param Security $xmlSecurity * @param \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory * @param \Magento\Shipping\Model\Rate\ResultFactory $rateFactory * @param \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory * @param \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory * @param \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory * @param \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory * @param \Magento\Directory\Model\RegionFactory $regionFactory * @param \Magento\Directory\Model\CountryFactory $countryFactory * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory * @param \Magento\Directory\Helper\Data $directoryData * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Module\Dir\Reader $configReader * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, Security $xmlSecurity, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Module\Dir\Reader $configReader, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, array $data = []) { $this->_storeManager = $storeManager; $this->_productCollectionFactory = $productCollectionFactory; parent::__construct($scopeConfig, $rateErrorFactory, $logger, $xmlSecurity, $xmlElFactory, $rateFactory, $rateMethodFactory, $trackFactory, $trackErrorFactory, $trackStatusFactory, $regionFactory, $countryFactory, $currencyFactory, $directoryData, $stockRegistry, $data); $wsdlBasePath = $configReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Fedex') . '/wsdl/'; $this->_shipServiceWsdl = $wsdlBasePath . 'ShipService_v10.wsdl'; $this->_rateServiceWsdl = $wsdlBasePath . 'RateService_v10.wsdl'; $this->_trackServiceWsdl = $wsdlBasePath . 'TrackService_v5.wsdl'; }
/** * Return reports dashboard * * @return string */ public function getDashboard() { return file_get_contents($this->_moduleReader->getModuleDir('etc', 'Magento_Reports') . '/flexDashboard.xml'); }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir('etc', 'Magento_Theme') . '/page_layouts.xsd'; $this->_perFileSchema = $moduleReader->getModuleDir('etc', 'Magento_Theme') . '/page_layouts_file.xsd'; }
/** * Retrieve translation file for module * * @param string $moduleName * @param string $locale * @return string */ protected function _getModuleTranslationFile($moduleName, $locale) { $file = $this->_modulesReader->getModuleDir(Module\Dir::MODULE_I18N_DIR, $moduleName); $file .= '/' . $locale . '.csv'; return $file; }
/** * Get Country Params by Country Code * * @param string $countryCode * @return \Magento\Framework\Object * * @see $countryCode ISO 3166 Codes (Countries) A2 */ protected function getCountryParams($countryCode) { if (empty($this->_countryParams)) { $etcPath = $this->_configReader->getModuleDir('etc', 'Magento_Dhl'); $countriesXmlPath = $this->modulesDirectory->getRelativePath($etcPath . '/countries.xml'); $countriesXml = $this->modulesDirectory->readFile($countriesXmlPath); $this->_countryParams = $this->_xmlElFactory->create(array('data' => $countriesXml)); } if (isset($this->_countryParams->{$countryCode})) { $countryParams = new \Magento\Framework\Object($this->_countryParams->{$countryCode}->asArray()); } return isset($countryParams) ? $countryParams : new \Magento\Framework\Object(); }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir('etc', 'Magento_Customer') . '/' . 'sections.xsd'; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir('etc', 'Magento_Eav') . '/eav_attributes.xsd'; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $etcDir = $moduleReader->getModuleDir('etc', 'Magento_Catalog'); $this->_schema = $etcDir . '/product_options_merged.xsd'; $this->_perFileSchema = $etcDir . '/product_options.xsd'; }
/** * Retrieve full path to an email template file * * @param string $templateId * @return string */ public function getTemplateFilename($templateId) { $module = $this->getTemplateModule($templateId); $file = $this->_getInfo($templateId, 'file'); return $this->_moduleReader->getModuleDir('view', $module) . '/email/' . $file; }
/** * @param \Magento\Framework\Module\Dir\Reader $moduleReader */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { $this->_schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Email') . '/email_templates.xsd'; }