PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 21, 2022

[FIXED] How to get the current version of a composer dependency inside a php script?

 January 21, 2022     composer-php, php, slim     No comments   

Issue

Is there a way to get the current version of slim? Like a php code expression or such that would display the real version the script is currently running?


Solution

You can parse the composer.lock-file to get the version of that 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;

In slim there is also a VERSION-constant on the App(v3.x) or Slim(v2.x) class

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

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


Answered By - jmattheis
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing