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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16846189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:46:56  来源:igfitidea点击:

How to know which version of Symfony I have?

phpsymfony

提问by zizoujab

I know that I have downloaded a Symfony2project 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 ?

任何的想法 ?

回答by Diego Agulló

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/console --version(对于 Symfony3: bin/console --version),它应该会给你一个很好的主意。在我的一个随机项目中,输出是:

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, consolecreates an instance of Symfony\Bundle\FrameworkBundle\Console\Application. In this class constructor, it uses Symfony\Component\HttpKernel\Kernel::VERSIONto initialize its parent constructor.

以防万一你想知道,console创建一个Symfony\Bundle\FrameworkBundle\Console\Application. 在此类构造函数中,它用于Symfony\Component\HttpKernel\Kernel::VERSION初始化其父构造函数。

回答by Adam Elsodaney

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

另一种方法是查看定义Symfony\Component\HttpKernel\Kernelwhere的来源const VERSIONGitHub 上的示例

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

在本地,这将位于vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php.

回答by cezar

Although there are already many good answers I'd like to add an option that hasn't been mentioned. Using the command:

尽管已经有很多好的答案,但我想添加一个尚未提及的选项。使用命令:

php bin/console about

you can get many details about the current project. The first section is about Symfony itself and looks like this:

您可以获得有关当前项目的许多详细信息。第一部分是关于 Symfony 本身的,看起来像这样:

-------------------- ------------------------------------------- 
 Symfony                                                         
-------------------- ------------------------------------------- 
 Version              4.2.3                                      
 End of maintenance   07/2019                                    
 End of life          01/2020                                    
-------------------- ------------------------------------------- 

I find the other information besides the version number very useful.

我发现除了版本号之外的其他信息非常有用。

There are also other sections providing details about the (framework) Kernel, PHP, Environment.

还有其他部分提供有关(框架)内核、PHP、环境的详细信息。

回答by user2815519

Use the following command in your Terminal/Command Prompt:

在终端/命令提示符中使用以下命令:

php bin/console --version

This will give you your Symfony Version.

这会给你你的 Symfony 版本。

回答by user2815519

If you want to dynamicallly display your Symfony 2 version in pages, for example in footer, you can do 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 中,或在 pages 示例页脚中

 <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 update in your template.I know this is overkill but this is how I do it in my projects and it is working.

现在每次你运行 composer update 来更新你的供应商时,symfony 版本也会在你的模板中自动更新。我知道这有点矫枉过正,但这就是我在我的项目中这样做的方式并且它正在工作。

回答by Pavel Alazankin

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.

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

回答by Mohammad Fareed

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

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

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\Component\HttpKernel\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**

回答by afeef

if you trying with version symfony

如果您尝试使用 symfony 版本

please try with

请尝试

symfony 2 +

symfony 2 +

cmd>php app/console --version

cmd>php 应用程序/控制台 --version

symfony 3+

symfony 3+

cmd>php bin/console --version

cmd>php bin/console --version

for example

例如

D:project>php bin/console --version

D:project>php bin/console --version

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

回答by redreinard

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

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

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

回答by jef

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

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