Returns a list of packages available for updates.
I searched for a package that could provide the same feature some package offer using the command line.
My goal is to display a web page on my web app with a vision of package up to date to help (advanced) users require the administrator help to update packages if needed.
- Scan for your installed packages in the
composer.lockfile and returns the last available version for it - Respect your
composer.jsonrequirements version
- PHP >= 7.0.0
composer.lockalongside yourcomposer.jsonpublished and ready to be read- An internet connection (because this library requests Packagist API)
In your console, install this package.
composer require khalyomede/dependency-scannerIn this example, we will use the default configuration to find the file composer.json and composer.lock and get a list of key pair of out of date packages.
<?php
require __DIR__ . '/../vendor/autoload.php';
use Khalyomede\DependencyScanner;
$scanner = new DependencyScanner;
$dependencies = $scanner->getOutdatedDependencies();In this example, we will use custom path (in case your run this script in a certain location where the default file path is not valid anymore).
<?php
use Khalyomede\DependencyScanner;
require __DIR__ . "/../vendor/autoload.php";
$scanner = new DependencyScanner;
$scanner->setComposerFilePath(__DIR__ . "/../composer.json");
$scanner->setLockFilePath(__DIR__ . "/../composer.lock");
$dependencies = $scanner->getOutdatedDependencies();- class
DependencyScanner
Get the path to the composer.json file.
public function getComposerFilePath(): string;Get the path to the composer.lock file.
public function getLockFilePath(): string;Get a array of key pairs (name associated with the last available version) of your outdated dependencies.
public function getOutdatedDependencies(): arraythrows
Khalyomede\Exception\HttpException: If we can't connect to the Packagist API.Khalyomede\Exception\JsonDecodeException: If an error occured while parsing the content of the composer or lock file or while decoding the JSON response of the Packagist API.Khalyomede\Exception\FileNotFoundException: If the composer or lock file cannot be found in the disk.Khalyomede\Exception\FileNotReadableException: if the composer or lock file is not readable.Khalyomede\Exception\FileReadFailedException: If an error occured while reading the composer or lock file (usingfile_get_contents()).
Set the path to the composer.json file.
public function setComposerFilePath(string $path): self;Set the path to the composer.lock file.
public function setlockFilePath(string $path): self;