Returns the module name, module package, and its' version

@param null $moduleName - provide the module name if you want to get the package specific information

@return array
2943
public function getModulesAndVersions($moduleName = null)
    {
        $tmpModules = [];
        $repos = $this->getComposer()->getRepositoryManager()->getLocalRepository();

        $composerFile = $_SERVER['DOCUMENT_ROOT'] . '/../vendor/composer/installed.json';
        $composer = (array) \Zend\Json\Json::decode(file_get_contents($composerFile));
       

        foreach ($composer as $package) {
            $packageModuleName = isset($package->extra) ? (array) $package->extra : null;
            $module = null;
            if (isset($packageModuleName['module-name'])) {
                $module = $packageModuleName['module-name'];
            }

            if ($module) {
                $tmpModules[$module] = [
                    'package' => $package->name,
                    'module' => $module,
                    'version' => $package->version,
                ];

                if ($module == $moduleName) {
                    break;
                }
            }

        }

        $userModules = $this->getUserModules();
        $exclusions = ['MelisModuleConfig', 'MelisSites'];

        foreach ($userModules as $module) {
            if (!in_array($module, $exclusions)) {
                $class = $_SERVER['DOCUMENT_ROOT'] . '/../module/' . $module . '/Module.php';
                $class = file_get_contents($class);

                $package = $module;
                $version = '1.0';

                if (preg_match_all('/@(\w+)\s+(.*)\r?\n/m', $class, $matches)) {

                    $result = array_combine($matches[1], $matches[2]);
                    $version = isset($result['version']) ? $result['version'] : '1.0';
                    $package = isset($result['module']) ? $result['module'] : $module;

                }
                $tmpModules[$package] = [
                    'package' => $package,
                    'module' => $package,
                    'version' => $version,
                ];

            }
        }


        $modules = $tmpModules;


        if (!is_null($moduleName)) {
            return isset($modules[$moduleName]) ? $modules[$moduleName] : null;
        }

        return $modules;
    }
33449
protected function getCSVModuleAttr(string $moduleName) : array
    {
        if (empty($this->modules[$moduleName])) {
            return [];
        }

        return $this->modules[$moduleName];
    }
183869
public function getVersion()
  {
    $composerJson = config('app.dir') . 'composer.json';

    if (file_exists($composerJson)) {
      $composer = json_decode(file_get_contents($composerJson, true));

      $version  = isset($composer->version) ? $composer->version : '1';
      $require  = isset($composer->require) ? (array)$composer->require : false;

      if (!is_array($require)) return "{$version} (1)";

      if (isset($require['modulusphp/framework'])) {
        return $version . " ({$require['modulusphp/framework']})";
      } else {
        return "{$version} (1)";
      }
    }

    return '1';
  }
1014657
private function getEnabledMappingsByModuleName($moduleName)
    {
        $mappingsToAdd = array();

        foreach ($this->mappings->listByModuleName($moduleName) as $repositoryPath => $mapping) {
            if ($mapping->isEnabled()) {
                // Remove duplicates
                $mappingsToAdd[$mapping->getRepositoryPath()] = $mapping;
            }
        }

        return $mappingsToAdd;
    }
575541
private function getCurrentVendorAndModuleName()
	{
		$composerDotJson = json_decode( file_get_contents( base_path('composer.json') ) );
		$psr4Autoload = $composerDotJson->autoload->{'psr-4'};
		$name = null;
		foreach( $psr4Autoload as $nameSpace => $folder ) {
			if( $folder == 'app/' ) {
				$name = $nameSpace;
				break;
			}
		}
		if( is_null( $name ) ) {
			$this->error('Could not find namespace from composer.json');
		}
		if( ! preg_match( "#^([a-z0-9]+)\\\([a-z0-9]+)\\\\$#is", $name, $match ) ) {
			$this->error('Could not find namespace from composer.json');
		}
		return [
			'vendor' => $this->getComputerNameFromCamelCase($match[1]),
			'module' => $this->getComputerNameFromCamelCase($match[2]),
			'camelCasedVendor' => $match[1],
			'camelCasedModule' => $match[2]
		];
	}
719586
private function getConstraint($packageName)
    {
        $requires = $this->rootPackage->getRequires();
        if (isset($requires[$packageName])) {
            /** @var Link $link */
            $link = $requires[$packageName];
            return $link->getConstraint()->getPrettyString();
        }

        foreach ($requires as $link) {
            /** @var Link $link */
            if ($link->getTarget() == $packageName) {
                return $link->getConstraint()->getPrettyString();
            }
        }

        return null;
    }
631976
public function get($name)
    {
        return isset($this->modules[$name]) ? $this->modules[$name] : null;
    }
176562
public function _getName()
    {
        $moduleName = '\\' . get_class($this);

        if (strpos($moduleName, ModuleContainer::MODULE_NAMESPACE) === 0) {
            return substr($moduleName, strlen(ModuleContainer::MODULE_NAMESPACE));
        }

        return $moduleName;
    }
483668
public function getPackages(string $name = null): array
    {
        if (isset($this->packages[$name])) {
            return $this->packages[$name];
        }

        return $this->packages;
    }
547475
protected function moduleName(): string
    {
        return $this->moduleName ?? $this->input->getOption('module') ?? $this->moduleName = $this->ask('What is your module?');
    }
235946
public function getModuleVersion() {
        // Get the module path
        $module_path = $this->directoryReader->getModuleDir('', 'CheckoutCom_Magento2');

        // Get the content of composer.json
        $json = file_get_contents($module_path . '/composer.json');

        // Decode the data and return
        $data = json_decode($json);

        return $data->version;
    }
97022
public function inModuleList(string $item, string $moduleName, string $listName)
    {
        try {
            $items = (new ModuleConfig(ConfigType::LISTS(), $moduleName, $listName))->parseToArray();
        } catch (InvalidArgumentException $e) {
            return $e->getMessage();
        }

        /** @var mixed[]|null $config */
        $inactive = $items['items'][$item]['inactive'] ?? null;
        if ($inactive === null || $inactive === true) {
            return (string)__('Invalid list item: `{0}`', $item);
        }

        return true;
    }
1278735
public static function getPackageName($classname)
    {
        $reflect = new ReflectionClass($classname);

        if (method_exists($reflect, 'getNamespaceName')) {
            $namespace = $reflect->getNamespaceName();

            if ($namespace != '') {
                return $namespace;
            }
        }

        if (preg_match('/@package[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches)) {
            return $matches[1];
        }

        return "default";
    }
629466
public function getModuleVersionFromComposer($modules = [])
    {
        $versions = [];
        $lockData = $this->getComposerLock();
        if ($lockData && !empty($lockData['packages'])) {
            foreach ($lockData['packages'] as $package) {
                if (in_array($package['name'], $modules) && isset($package['version'])) {
                    $versions[$package['name']] = $package['version'];
                }
            }
        }
        return $versions;
    }
137095
public function getModuleVersion($module)
    {
        $config = $this->getModuleDefinition($module);
    
        if (isset($config['version'])) {
            return $config['version'];
        } else {
            return SoftwareVersion::DEFAULT_UNRESOLVED_VERSION;
        }
    }
1113469
public function getAggregatePackageContaining($packageName)
    {
        foreach ($this->packages as $packageNode) {
            if ($packageNode->replaces($packageName)) {
                return $packageNode;
            }
        }

        return null;
    }
724294
public function getModule($name)
    {
        // Optimised find
        if (isset($this->modules[$name])) {
            return $this->modules[$name];
        }

        // Fall back to lookup by shortname
        if (!strstr($name, '/')) {
            foreach ($this->modules as $module) {
                if (strcasecmp($module->getShortName(), $name) === 0) {
                    return $module;
                }
            }
        }

        return null;
    }