fetch version and licence information of installed composer packages from packagist

1.2.0 2017-09-27 08:24 UTC


A composer package used to fetch version numbers and licence information from all installed composer packages (included in composer.json) and their latest version number registered on packagist.

Installation and configuration

Install the module via composer, therefore adapt the require part of your composer.json:

"require": {
    "anexia/composer-tools": "1.2.0"

Now run

composer update [-o]

to add the packages source code to your /vendor directory.


The package adds the ComposerPackagistTrait to your application. It can be added to a class (e.g. a controller) as any trait and then its methods can be accessed directly.

The trait provides the two methods

  • getLatestFrameworkVersion($package) returns the latest registered packagist version of a given package
  • getComposerPackageData() returns an array of all installed composer packages (found via composer.json) including their currently installed version and their latest registered packagist version

A VersionMonitoringController for a Laravel application might look like this example:

// inside VersionMonitoringController.php

use Anexia\ComposerTools\Traits\ComposerPackagistTrait

class VersionMonitoringController
    use ComposerPackagistTrait;
    public function index()
        $runtime = [
            'platform' => 'php',
            'platform_version' => phpversion(),
            'framework' => 'laravel',
            'framework_installed_version' => $this->getCurrentFrameworkVersion(),
            'framework_newest_version' => $this->getLatestPackageVersion('laravel/framework')
        $modules = $this->getComposerPackageData();
        $response = response()->json([
            'runtime' => $runtime,
            'modules' => $modules
     * Get version number of the currently installed framework package
     * @return string
    public function getCurrentFrameworkVersion()
        // do something to return the currently used framework version,
        // depending on the framwork used within the application

A possible response of the example controller action might look like this:

200 OK