Getting the Symfony minor version of a project
Published on 2024-12-21 • Modified on 2024-12-21
This snippet shows how to get the Symfony minor version of a project. Be careful; this will not work any more as of Symfony 10!
<?php
declare(strict_types=1);
namespace App\Controller\Snippet;
use Symfony\Component\HttpKernel\Kernel;
/**
* I am using a PHP trait to isolate each snippet in a file.
* This code should be called from a Symfony controller extending AbstractController (as of Symfony 4.2)
* or Symfony\Bundle\FrameworkBundle\Controller\Controller (Symfony <= 4.1).
* Services are injected in the main controller constructor.
*/
trait Snippet334Trait
{
public function snippet334(): void
{
echo 'The Symfony minor version of this blog is: '.substr(Kernel::VERSION, 0, 3);
// That's it! π
}
}
Run this snippet More on Stackoverflow Read the doc More on the web Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky π¦
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges π .
Thank you for reading! And see you soon on Strangebuzz! π
[π¬π§] Snippet 48/50: Getting the Symfony minor version of a project www.strangebuzz.com/en/snippets/... #PHP #symfony #version
— COil π (@coil.ooo) 23 dΓ©cembre 2024 Γ 11:10
[image or embed]