/** * Get list of configuration files associated with modules * * @return array */ protected function _getConfigFilesPerModule() { $data = []; $componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar(); $modulesPaths = $componentRegistrar->getPaths(\Magento\Framework\Component\ComponentRegistrar::MODULE); foreach ($modulesPaths as $moduleName => $path) { if (file_exists($configFile = $path . '/etc/config.xml')) { $data[$configFile] = $moduleName; } } return $data; }
/** * @param string $filePath * @return string */ protected function convertPathToClassName($filePath) { $componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar(); $foundItems = null; $moduleNamespace = null; $foundItems = array_filter($componentRegistrar->getPaths(\Magento\Framework\Component\ComponentRegistrar::MODULE), function ($item) use($filePath) { if (strpos($filePath, $item . '/') !== false) { return true; } else { return false; } }); if ($foundItems) { $moduleNamespace = str_replace('_', '\\', array_keys($foundItems)[0]); $classPath = str_replace('/', '\\', str_replace(array_shift($foundItems), '', $filePath)); } else { $foundItems = array_filter($componentRegistrar->getPaths(\Magento\Framework\Component\ComponentRegistrar::LIBRARY), function ($item) use($filePath) { if (strpos($filePath, $item . '/') !== false) { return true; } else { return false; } }); $libName = array_keys($foundItems)[0]; $libName = str_replace('framework-', 'framework/', $libName); $namespaceParts = explode('/', $libName); $namespaceParts = array_map(function ($item) { return str_replace(' ', '', ucwords(str_replace('-', ' ', $item))); }, $namespaceParts); $moduleNamespace = implode('\\', $namespaceParts); $classPath = str_replace('/', '\\', str_replace(array_shift($foundItems), '', $filePath)); } $className = '\\' . $moduleNamespace . $classPath; $className = str_replace('.php', '', $className); return $className; }
<?php Magento\Framework\Component\ComponentRegistrar::register(Magento\Framework\Component\ComponentRegistrar::MODULE, "Tinify_CompressImages", __DIR__);