Get information for composer installed packages (currently installed version and latest stable version)

@return array
765963
public function getComposerPackageData()
    {
        $moduleVersions = [];

        $installedJsonFile = getcwd() . '/../vendor/composer/installed.json';
        $packages = json_decode(file_get_contents($installedJsonFile));

        if (count($packages) > 0) {
            foreach ($packages as $package) {
                $name = $package->name;

                /**
                 * get latest stable version of the package
                 */
                $latestStable = $this->getLatestPackage($name);

                /**
                 * prepare result
                 */
                $moduleVersions[] = [
                    'name' => $name,
                    'installed_version' => $package->version,
                    'installed_version_licences' => $package->license,
                    'newest_version' => $latestStable->version,
                    'newest_version_licences' => $latestStable->license,
                ];
            }
        }

        return $moduleVersions;
    }
1104407
protected function getPhpRequiredVersion()
    {
        if (!file_exists($path = __DIR__.'/../composer.lock')) {
            return false;
        }

        $composerLock = json_decode(file_get_contents($path), true);
        foreach ($composerLock['packages'] as $package) {
            $name = $package['name'];
            if ('symfony/symfony' !== $name && 'symfony/http-kernel' !== $name) {
                continue;
            }

            return (int) $package['version'][1] > 2 ? self::REQUIRED_PHP_VERSION : self::LEGACY_REQUIRED_PHP_VERSION;
        }

        return false;
    }
1265588
public function findAll()
    {
        $repos = array();
        foreach ($this->repository->findAll() as $repo) {
            $this->loadPackagistInfos($repo);
            $repos[] = $repo;
        }

        return $repos;
    }
99757
function getSupportedVersions()
    {
        $temp = array('version' => $this->version);
        if (isset($this->extensions['versions'])) {
            $temp['extensions'] = $this->extensions['versions'];
        }
        return $temp;
    }
944646
public function list_plugins()
    {
        $plugins    = array();
        $plugin_dir = INSTALL_PATH . 'plugins/';

        foreach (glob($plugin_dir . '*') as $path) {
            if (!is_dir($path)) {
                continue;
            }

            if (is_readable($path . '/composer.json')) {
                $file_json   = json_decode(file_get_contents($path . '/composer.json'));
                $plugin_desc = $file_json->description ?: 'N/A';
            }
            else {
                $plugin_desc = 'N/A';
            }

            $name      = substr($path, strlen($plugin_dir));
            $plugins[] = array(
                'name'    => $name,
                'desc'    => $plugin_desc,
                'enabled' => in_array($name, (array) $this->config['plugins'])
            );
        }

        return $plugins;
    }
60221
public function getLocalAvailableUpdates()
    {
        $app = Application::getFacadeApplication();
        $fh = $app->make('helper/file');
        $updates = [];
        $contents = @$fh->getDirectoryContents(DIR_CORE_UPDATES);
        foreach ($contents as $con) {
            if (is_dir(DIR_CORE_UPDATES . '/' . $con)) {
                $obj = ApplicationUpdate::get($con);
                if (is_object($obj)) {
                    if (version_compare($obj->getUpdateVersion(), APP_VERSION, '>')) {
                        $updates[] = $obj;
                    }
                }
            }
        }
        usort(
            $updates,
            function ($a, $b) {
                return version_compare($a->getUpdateVersion(), $b->getUpdateVersion());
            }
        );

        return $updates;
    }
1135931
private static function getPresetsInfo() {
    $installation_types = self::getInstallationTypes(TRUE);
    $presets_info = [];
    $packages_info = self::getPackages();

    foreach ($installation_types as $preset => $preset_info) {
      $presets_info[$preset] = $preset_info;
      $presets_info[$preset]['packages_expanded'] = [];
      foreach ($preset_info['packages'] as $package) {
        if (empty($packages_info[$package])) {
          continue;
        }
        $presets_info[$preset]['packages_expanded'][$package] = $packages_info[$package];
        if (!isset($packages_info[$package]['usage'])) {
          $packages_info[$package]['usage'] = 0;
        }
        $packages_info[$package]['usage']++;
      }
    }

    return $presets_info;
  }
1172349
protected function getCurrentPackageStates()
    {
        $savePackageStates = false;
        $loadedPackageStates = $this->loadPackageStates();
        if (
            empty($loadedPackageStates)
            || !isset($loadedPackageStates['version'])
            || $loadedPackageStates['version'] < self::PACKAGESTATE_FORMAT_VERSION
        ) {
            $loadedPackageStates = $this->scanAvailablePackages();
            $savePackageStates = true;
        }

        if ($savePackageStates) {
            $loadedPackageStates = $this->sortAndSavePackageStates($loadedPackageStates);
        }

        return $loadedPackageStates;
    }
179146
public function index()
    {
        $this->requireAdmin();

        $json = $this->getComposerJson();
        $this->view->installedPackages = $json['require'];

        $pluginInfo = new PluginInformationCollection();
        $pluginInfo->add(FilesPluginInformation::newFromDir(
            PHPCI_DIR . "PHPCI/Plugin/"
        ));
        $pluginInfo->add(ComposerPluginInformation::buildFromYaml(
            PHPCI_DIR . "vendor/composer/installed.json"
        ));

        $this->view->plugins = $pluginInfo->getInstalledPlugins();

        $this->layout->title = Lang::get('plugins');

        return $this->view->render();
    }
1068505
public function getAll()
    {
        if (!$this->loadRepositories()) {
            return Repository::STATUS_NO_REPOSITORIES;
        }

        $modules = $this->getModulesFromRepository();

        // Is a higher version of an already installed package available?
        foreach ($modules as $key => $module) {
            $version = $this->packageService->getVersion($module->name);

            if (!$version) {
                // Not installed at all.
                unset($modules[$key]);
            } elseif (version_compare($version, $module->version, '<')) {
                // Older version installed.
                $modules[$key]->hasUpdate = true;
                $modules[$key]->versionInstalled = $version;
            } else {
                $modules[$key]->hasUpdate = false;
                $modules[$key]->versionInstalled = $version;
            }
        }

        return $modules;
    }
1326131
protected function findApplicationMigrations(): array
	{
		$migrations = [];

		foreach($this->fileSystem->glob($this->application->getPath() . '/migrations/*.php') as $migration)
		{
			$migrations[] = (object) ['package' => null, 'version' => $this->getBasename($migration)];
		}

		return $migrations;
	}
625956
public function installed()
    {
        try {
            return $this->json($this->manager()->getAllPackages());
        } catch (\Exception $e) {
            return $this->getJsonException($e);
        }
    }
809442
public function getAllPackages()
    {
        $collection = new PackageCollection();

        if ($this->started === false) {
            return $collection;
        }

        // Installed
        $installed = $this->app['extend.action']['show']->execute('installed');
        foreach ($installed as $composerPackage) {
            /** @var CompletePackageInterface $composerPackage */
            $composerPackage = $composerPackage['package'];
            $package = Package::createFromComposerPackage($composerPackage);
            $name = $package->getName();
            $extension = $this->app['extensions']->getResolved($name);

            // Handle non-Bolt packages
            if ($extension instanceof ResolvedExtension) {
                $title = $extension->getDisplayName();
                $descriptor = $extension->getDescriptor();
                $constraint = $descriptor ? $descriptor->getConstraint() : null;
                $readme = $this->linkReadMe($extension);
                $config = $this->linkConfig($extension);
                $valid = $extension->isValid();
                $enabled = $extension->isEnabled();
            } else {
                $title = $name;
                $constraint = null;
                $readme = null;
                $config = null;
                $valid = true;
                $enabled = true;
            }

            $package->setStatus('installed');
            $package->setTitle($title);
            $package->setReadmeLink($readme);
            $package->setConfigLink($config);
            $package->setRepositoryLink($composerPackage->getSourceUrl());
            $package->setConstraint($constraint);
            $package->setValid($valid);
            $package->setEnabled($enabled);

            $collection->add($package);
        }

        // Pending
        $requires = isset($this->json['require']) ? $this->json['require'] : [];
        foreach ($requires as $name => $version) {
            if ($collection->get($name)) {
                continue;
            }
            $package = new Package();
            $package->setStatus('pending');
            $package->setName($name);
            $package->setTitle($name);
            $package->setReadmeLink(null);
            $package->setConfigLink(null);
            $package->setVersion($version);
            $package->setType('unknown');
            $package->setDescription(Trans::__('general.phrase.not-installed-yet'));

            $collection->add($package);
        }

        return $collection;
    }
925147
public function getStatus()
    {
        $reports = [];
        $solrConnections = GeneralUtility::makeInstance(ConnectionManager::class)->getAllConnections();

        foreach ($solrConnections as $solrConnection) {
            $adminService = $solrConnection->getAdminService();
            if ($adminService->ping()) {
                $installationStatus = $this->checkPluginInstallationStatus($adminService);
                $versionStatus = $this->checkPluginVersion($adminService);

                if (!is_null($installationStatus)) {
                    $reports[] = $installationStatus;
                }

                if (!is_null($versionStatus)) {
                    $reports[] = $versionStatus;
                }
            }
        }

        return $reports;
    }
791672
public static function getDirectories() {
        Logger::info("Resolving dependencies for project");
        $packages = array();
        $root = dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))));
        $composer = file_get_contents($root . DIRECTORY_SEPARATOR . 'composer.json');
        $composer = json_decode($composer, true);
        if (array_key_exists('require', $composer) && !empty($composer['require'])) {
            foreach ($composer['require'] as $requirement => $version) {
                $packages = array_merge(self::readFile($requirement), $packages);
            }
        } else {
            Logger::trace("Project has no dependencies");
        }
        foreach ($packages as $package) {
            Logger::debug("Project references package %s", $package);
        }
        Logger::info("%d dependencies found", count($packages));
        return $packages;
    }
209000
public function listReleases(): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/releases',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo()));
    }
739279
private function loadComposerPackages()
    {
        $repository = $this->composer->getRepositoryManager()->getLocalRepository();
        $packages = array();

        foreach ($repository->getPackages() as $package) {
            /* @var PackageInterface $package */
            $packages[$package->getName()] = $package;
        }

        return $packages;
    }