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

Friday, January 7, 2022

[FIXED] Get version from composer.json [Symfony]

 January 07, 2022     composer-php, symfony     No comments   

Issue

I wonder if there is a way to get the composer.json version from a controller with Symfony. My composer.json looks like:

{
    "name": "myProject",
    "version": "0.0.0",
    "description": "myProject description",
    "license": "AGPL-3.0",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        ...
    }
}

I can't find any reference to this.

PS: I'm using Symfony 4.


Solution

You can use the PackageVersions library and its relative PrettyPackageVersions.

They provide a single class API to get the currently installed version of your Composer dependencies, for example:

use PackageVersions\Versions;
use Jean85\PrettyVersions;

// Will output "1.0.0@0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
echo Versions::getVersion('myvendor/mypackage');

// Will output "1.0.0"
echo (string) PrettyVersions::getVersion('myvendor/mypackage');


Answered By - Edi Modrić
  • 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