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.
You can do something like this:
$filename = $this->getParameter('%app.kernel_dir%') . '/../composer.json';
$composerData = json_decode(file_get_contents($filename), true);
$version = $composerData['version'];
The variable should then containv the value 0.0.0 from your example.
This assumes that your controller extends the base Controller to access the %app.kernel_dir% parameter. If not, you could just as well use the relative path from your controller or something else to determine the location of the composer.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With