如何知道我有哪个版本的Symfony ?

时间:2022-02-08 07:07:53

I know that I have downloaded a Symfony2 project and started with but I have updated my vendor several times and I want to know which version of symfony I have

我知道我已经下载了Symfony2项目并开始了,但是我已经更新了我的供应商好几次,我想知道我有哪个版本的symfony

Any idea ?

任何想法?

9 个解决方案

#1


151  

Run app/console --version (for Symfony3: bin/console --version), it should give you a pretty good idea. On a random project of mine, the output is:

运行app/控制台——版本(对于Symfony3: bin/console——版本),它应该给你一个不错的主意。对于我的一个随机项目,输出为:

Symfony version 2.2.0-DEV - app/dev/debug

If you can't access the console, try reading symfony/src/Symfony/Component/HttpKernel/Kernel.php, where the version is hardcoded, for instance:

如果您无法访问控制台,请尝试读取symfony/src/ symfony/ Component/HttpKernel/Kernel。php,其中的版本是硬编码的,例如:

const VERSION         = '2.2.0';

Just in case you are wondering, console creates an instance of Symfony\Bundle\FrameworkBundle\Console\Application. In this class constructor, it uses Symfony\Component\HttpKernel\Kernel::VERSION to initialize its parent constructor.

如果您想知道,控制台将创建Symfony\Bundle\FrameworkBundle\应用程序的实例。在这个类构造函数中,它使用Symfony\组件\HttpKernel::VERSION来初始化父构造函数。

#2


14  

Another way is to look at the source for Symfony\Component\HttpKernel\Kernel for where const VERSION is defined. Example on GitHub

另一种方法是查看定义const版本的Symfony\组件\HttpKernel内核的源代码。在GitHub的例子

Locally this would be located in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php.

在本地这将位于供应商/symfony/symfony/src/ symfony/ Component/HttpKernel/Kernel.php。

#3


5  

If you want to dynamicallly display your Symfony 2 version in pages, example in footer, you do can it this way.

如果您想动态地在页面中显示Symfony 2版本,例如在页脚中,您可以这样做。

create a service

创建一个服务

<?php

namespace Project\Bundle\DuBundle\Twig;

class SymfonyVersionExtension extends \Twig_Extension
{


 public function getFunctions()
 {
 return array(
 //this is the name of the function you will use in twig
 new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
   );
 }

public function getName()
{
//return 'number_employees';
 return 'symfony_version_extension';
}   

public function b()
{
 $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
 return $symfony_version;
}
}

Register in service.yml

注册在service.yml

 dut.twig.symfony_version_extension:
    class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
    tags:
        - { name: twig.extension }
    #arguments: []

And you can call it anywhere.In Controller,wrap it in JSON, or in pages example footer

你可以在任何地方叫它。在Controller中,使用JSON或页面示例脚注包装它

 <p> Built With Symfony {{ symfony_version() }} Version MIT License</p>

Now every time you run composer update to update your vendor, symfony version will also automatically updated in your template.I know this is overkill but this how I do it in my projects and it is working

现在,每当您运行composer update来更新供应商时,symfony版本也会在您的模板中自动更新。我知道这有点过头了,但我在我的项目中就是这么做的

#4


3  

we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

我们可以使用内核找到symfony版本。php文件,但问题是Kernal的位置会随着版本而变化(最好在项目目录中进行文件搜索)

in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

在symfony 3.0中:my_project vendor symfony\symfony\src\ symfony\ \symfony\ \组件\ http\ Kernel.php

Check from Controller/ PHP File

从控制器/ PHP文件中检查

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**

#5


2  

if you trying with version symfony

如果你尝试版本symfony

please try with

请试一试

symfony 2 +

symfony 2 +

cmd>php app/console --version

cmd > php应用程序/控制台版本

symfony 3+

symfony 3 +

cmd>php bin/console --version

cmd > php bin /控制台——版本

for example

例如

D:project>php bin/console --version

D:项目> php bin /控制台版本

Symfony 3.2.8 (kernel: app, env: dev, debug: true)

#6


2  

also you can check the version of symfony and versions of all other installed packages by running

您还可以通过运行检查symfony的版本和所有其他已安装包的版本

composer show

or

composer show | grep sonata

to get versions of specific packages like sonata etc.

获取特定包的版本,如奏鸣曲等。

#7


1  

if you are in app_dev, you can find symfony version at the bottom left corner of the page

如果您在app_dev中,可以在页面的左下角找到symfony版本

#8


1  

From inside your Symfony project, you can get the value in PHP this way:

在Symfony项目中,可以通过以下方式获取PHP的值:

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;

#9


0  

For Symfony 3.4

Symfony 3.4

Check the constant in this file vendor/symfony/http-kernel/Kernel.php

检查这个文件供应商/symfony/http-kernel/Kernel.php中的常量。

const VERSION = '3.4.3';

OR

composer show | grep symfony/http-kernel

#1


151  

Run app/console --version (for Symfony3: bin/console --version), it should give you a pretty good idea. On a random project of mine, the output is:

运行app/控制台——版本(对于Symfony3: bin/console——版本),它应该给你一个不错的主意。对于我的一个随机项目,输出为:

Symfony version 2.2.0-DEV - app/dev/debug

If you can't access the console, try reading symfony/src/Symfony/Component/HttpKernel/Kernel.php, where the version is hardcoded, for instance:

如果您无法访问控制台,请尝试读取symfony/src/ symfony/ Component/HttpKernel/Kernel。php,其中的版本是硬编码的,例如:

const VERSION         = '2.2.0';

Just in case you are wondering, console creates an instance of Symfony\Bundle\FrameworkBundle\Console\Application. In this class constructor, it uses Symfony\Component\HttpKernel\Kernel::VERSION to initialize its parent constructor.

如果您想知道,控制台将创建Symfony\Bundle\FrameworkBundle\应用程序的实例。在这个类构造函数中,它使用Symfony\组件\HttpKernel::VERSION来初始化父构造函数。

#2


14  

Another way is to look at the source for Symfony\Component\HttpKernel\Kernel for where const VERSION is defined. Example on GitHub

另一种方法是查看定义const版本的Symfony\组件\HttpKernel内核的源代码。在GitHub的例子

Locally this would be located in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php.

在本地这将位于供应商/symfony/symfony/src/ symfony/ Component/HttpKernel/Kernel.php。

#3


5  

If you want to dynamicallly display your Symfony 2 version in pages, example in footer, you do can it this way.

如果您想动态地在页面中显示Symfony 2版本,例如在页脚中,您可以这样做。

create a service

创建一个服务

<?php

namespace Project\Bundle\DuBundle\Twig;

class SymfonyVersionExtension extends \Twig_Extension
{


 public function getFunctions()
 {
 return array(
 //this is the name of the function you will use in twig
 new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
   );
 }

public function getName()
{
//return 'number_employees';
 return 'symfony_version_extension';
}   

public function b()
{
 $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
 return $symfony_version;
}
}

Register in service.yml

注册在service.yml

 dut.twig.symfony_version_extension:
    class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
    tags:
        - { name: twig.extension }
    #arguments: []

And you can call it anywhere.In Controller,wrap it in JSON, or in pages example footer

你可以在任何地方叫它。在Controller中,使用JSON或页面示例脚注包装它

 <p> Built With Symfony {{ symfony_version() }} Version MIT License</p>

Now every time you run composer update to update your vendor, symfony version will also automatically updated in your template.I know this is overkill but this how I do it in my projects and it is working

现在,每当您运行composer update来更新供应商时,symfony版本也会在您的模板中自动更新。我知道这有点过头了,但我在我的项目中就是这么做的

#4


3  

we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

我们可以使用内核找到symfony版本。php文件,但问题是Kernal的位置会随着版本而变化(最好在项目目录中进行文件搜索)

in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

在symfony 3.0中:my_project vendor symfony\symfony\src\ symfony\ \symfony\ \组件\ http\ Kernel.php

Check from Controller/ PHP File

从控制器/ PHP文件中检查

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**

#5


2  

if you trying with version symfony

如果你尝试版本symfony

please try with

请试一试

symfony 2 +

symfony 2 +

cmd>php app/console --version

cmd > php应用程序/控制台版本

symfony 3+

symfony 3 +

cmd>php bin/console --version

cmd > php bin /控制台——版本

for example

例如

D:project>php bin/console --version

D:项目> php bin /控制台版本

Symfony 3.2.8 (kernel: app, env: dev, debug: true)

#6


2  

also you can check the version of symfony and versions of all other installed packages by running

您还可以通过运行检查symfony的版本和所有其他已安装包的版本

composer show

or

composer show | grep sonata

to get versions of specific packages like sonata etc.

获取特定包的版本,如奏鸣曲等。

#7


1  

if you are in app_dev, you can find symfony version at the bottom left corner of the page

如果您在app_dev中,可以在页面的左下角找到symfony版本

#8


1  

From inside your Symfony project, you can get the value in PHP this way:

在Symfony项目中,可以通过以下方式获取PHP的值:

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;

#9


0  

For Symfony 3.4

Symfony 3.4

Check the constant in this file vendor/symfony/http-kernel/Kernel.php

检查这个文件供应商/symfony/http-kernel/Kernel.php中的常量。

const VERSION = '3.4.3';

OR

composer show | grep symfony/http-kernel