Best practice to display the version of a Symfony

2019-06-16 09:35发布

问题:

We built a web application build on top of the Symfony2 framework.

Now we need to display the current version of our software in the front end for the user to see. The version number is currently a tag in the git repository.

Now what is considered best practice to achieve this? The Composer documentation discourages the use of the version field used in the composer.json

Symfony itself seems to set the version string in the app/bootstrap.php.cache file: const VERSION ='2.7.6';

Is there any best practice regarding this issue? Is there a way to directly access the git tag name? Or should I go with the constant or composer.json way?

回答1:

You could try versioning-bundle. From their doc:

  • Adds additional parameter to your parameters.yml file and keeps it inline with your current application version.
  • Basic Version handlers implemented for manual and git tag versioning


回答2:

with this example now you can do everything :

   \Symfony\Component\VarDumper\VarDumper::dump(\Symfony\Component\HttpKernel\Kernel::VERSION);

This is a Hardcoded const in source of symfony.

You can :

  • code your own const with this
  • function for request this info
  • trigger or listener
  • etc.....