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

  Work with me!


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 )

Thank you for reading! And see you soon on Strangebuzz! πŸ˜‰

COil

[πŸ‡¬πŸ‡§] Snippet 48/50: Getting the Symfony minor version of a project www.strangebuzz.com/en/snippets/... #PHP #symfony #version

[image or embed]

— COil 🐝 (@coil.ooo) 23 dΓ©cembre 2024 Γ  11:10