How to get the current version of composer dependency inside PHP script?

Is there a way to get the current slim version? How is the php code expression or one that displays the real version the script is currently running?

+3


source to share


1 answer


You can parse the composer.lock

file to get a version of this dependency.

$composerLock = json_decode(file_get_contents('composer.lock'));
foreach($composerLock->packages as $package) {
    if ($package->name == 'slim/slim') {
        $version = $package->version;
        break;
    }
}
echo $version;

      



There is also a VERSION

class- App

constant (v3.x) or Slim

(v2.x) in slim

// 2.x
$app = \Slim\Slim;
$version = \Slim\Slim::VERSION;

// 3.x
$app = \Slim\App;
$version = \Slim\App::VERSION;

      

+2


source







All Articles