Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - read version number in composer.json

How do I make a script there can tell me what version i run when it stored in composer.json?

composer.json

{
    "require": {
        "someLiberyNameHere": "8.3.3.1"
    }
}
like image 669
Budget Avatar asked Jan 05 '23 08:01

Budget


1 Answers

I think that this is as simple as this since composer.json is a Json file:

<?php

$content = file_get_contents('/path/to/composer.json');
$content = json_decode($content,true);

var_dump($content['require']['someLiberyNameHere']);

You can also iterate through your dependencies:

foreach ($content['require'] as $key => $value) {
    echo $key . ' => ' . $value . PHP_EOL;
}
like image 168
Hammerbot Avatar answered Jan 07 '23 17:01

Hammerbot