PHP - read version number in composer.json
Asked Answered
O

3

8

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"
    }
}
Overestimate answered 19/3, 2017 at 15:22 Comment(0)
M
13

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;
}
Mercy answered 19/3, 2017 at 15:35 Comment(0)
R
3
\Composer\InstalledVersions::getRootPackage();

\Composer\InstalledVersions::getVersion('vendor/package');

https://getcomposer.org/doc/07-runtime.md#installed-versions

Rioux answered 26/10, 2022 at 12:45 Comment(0)
W
0

You can make composer object from factory And find your package in repository and give package info.

Weltanschauung answered 19/3, 2017 at 17:0 Comment(2)
What a cryptic reply. A sort of DIY eh?Lounge
That wasn't a permalink, so it goes to the wrong line now.Leftward

© 2022 - 2024 — McMap. All rights reserved.