简体   繁体   English

国际组件Symfony2

[英]The Intl Component Symfony2

I am deploying a symfony2 application to a server where php intl extension is not enabled. 我正在将symfony2应用程序部署到未启用php intl扩展名的服务器。 I have no say in this. 我对此没有发言权。

The answer to this question suggests a solution: Possible to disable intl requirement for Symfony? 该问题的答案提出了一个解决方案:是否可以禁用Symfony的国际要求?

I have put the "symfony/intl": "3.0.*@dev" in my composer.json and everything updates fine. 我已经在我的composer.json文件中放入了“ symfony / intl”:“ 3.0.*@dev”,并且一切正常。 Must I do anything more to activate/enable it? 我还必须做些其他事来激活/启用它吗? In AppKernel like with bundles? 在AppKernel中像捆绑包一样?

Now I get the following errors when I run check.php on deployment server: 现在,在部署服务器上运行check.php时出现以下错误:

 PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Extension intl does not exist' in /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php:658
Stack trace:
#0 /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php(658): ReflectionExtension->__construct('intl')
#1 /web/folk/eirik/030476/releases/20150528181203/app/check.php(6): SymfonyRequirements->__construct()
#2 {main}
  thrown in /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php on line 658

I look at line 658 in SymfonyRequirements.php and find: 我在SymfonyRequirements.php中查看第658行,发现:

    if (class_exists('Locale')) {
              if (defined('INTL_ICU_VERSION')) {
                $version = INTL_ICU_VERSION;
            } else {
                $reflector = new ReflectionExtension('intl');

                ob_start();
                $reflector->info();
                $output = strip_tags(ob_get_clean());

                preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
                $version = $matches[1];
            }

            $this->addRecommendation(
                version_compare($version, '4.0', '>='),
                'intl ICU version should be at least 4+',
                'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
            );
        }

I don't know much about this stuff, but I assume new ReflectionExtension('intl') requires the intl exension to be enabled in php, which is no option for me. 我对这些东西不太了解,但是我假设新的ReflectionExtension('intl')要求在php中启用intl扩展,这对我来说是没有选择的。

But what is INTL_ICU_VERSION? 但是什么是INTL_ICU_VERSION? And why is it not defined? 为什么没有定义? And why won't the symfony/intl component fix this for me? 为什么symfony / intl组件不能为我解决这个问题?

And btw 和顺便说一句

if (class_exists('Collator')) {
           $this->addRecommendation(
               null !== new Collator('FR_fr'),
               'intl extension should be correctly configured',
            'The intl extension does not behave properly. This problem is       typical on PHP 5.3.X x64 WIN builds.'
        );
    }

I have also changed 'FR_fr' to 'en' here, this was an error given by check.php that disappeared when I made the change. 我还在这里将“ FR_fr”更改为“ en”,这是check.php给出的错误,当我进行更改时该错误消失了。

If you take a look into the file check.php you are running you'll see that it does not load the Composer autoloader therefore it makes no difference whether you have installed that Symfony Intl component or not, it'll keep failing because it's looking for a required extension that is not there. 如果查看运行中的文件check.php ,您会看到它没有加载Composer自动加载器,因此,无论是否安装了Symfony Intl组件都不会造成任何影响,它会一直失败,因为它看上去所需的扩展名不存在。 The SO question you linked does mention the problem got solved but it doesn't say that the check passed. 您链接的SO问题确实提到问题已解决,但并不表示检查通过。

If that extension was your problem with your Symfony installation and the only locale you needed is "en" than the problem should have gone away already after you installed the Symfony Intl drop in replacement. 如果该扩展程序是您在Symfony安装中遇到的问题,并且唯一需要的语言环境是“ en”,则在安装了Symfony Intl替代产品后,该问题应该已经消失了。 Although if you want to run the check for other problems you can comment out those lines so the script can finish. 虽然如果您要运行其他问题的检查,但是可以注释掉这些行,以便脚本可以完成。 Don't worry that script is totally decoupled from the framework, you can even delete it when you are done. 不必担心脚本与框架完全脱钩,甚至可以在完成后将其删除。

If you are using Capistrano for the deployment and you are running those checks on every deployment you might want to disable that as well, or customise that script for your needs. 如果将Capistrano用于部署,并且在每个部署上运行这些检查,则可能也要禁用该检查,或者根据需要自定义该脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM