Symfony - 树枝 - 自动加载器预期类 [英] Symfony - twig - Autoloader expected class

查看:22
本文介绍了Symfony - 树枝 - 自动加载器预期类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 symfony 和显然是树枝有问题.我已经在一个项目上工作了一段时间,当我即将发布一个新版本时(通过通过 ftp 上传所有内容,如下:https://medium.com/@runawaycoin/deploying-symfony-4-application-to-shared-hosting-with-just-ftp-access-e65d2c5e0e3d).

I have a problem with symfony and apparently twig. I've been working on a project for some time, and as I was about to make a new release (by uploading everything througn ftp, following this : https://medium.com/@runawaycoin/deploying-symfony-4-application-to-shared-hosting-with-just-ftp-access-e65d2c5e0e3d).

就在上传之前,我发现应用程序在一天前停止工作.我开始搜索问题,但日志中没有任何内容.我决定重新上传所有内容并清除缓存,以防这可能是问题所在,但仍然没有,只是 500 错误.

Just before doing the upload, I discover that the application stopped working a day before. I start to search for the issue, but there wasn't anything in the logs. I decide to reupload everything and clear the cache, in case that could be the problem, but still nothing, just a 500 error.

然后我启用调试,并得到错误:

I then enable the debug, and get the error :

The autoloader expected class "Twig\Extension\AbstractExtension" to be defined in file ".../symfony/vendor/composer/../twig/twig/src/Extension/AbstractExtension.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

我尝试了网上能找到的所有方法,但唯一一个遇到类似问题的人通过添加树枝/扩展来解决它,但这也不能解决问题.

I tried everything I could find online, but the only one who had a similar problem solved it by adding twig/extensions, but this does not solve it either.

我完全不明白可能发生了什么,但是这个问题似乎是无缘无故出现的,也没有任何文件更改.

I don't get at all what may have happened, but this problem seemed to have appeared with no reason, and without any file change.

该应用程序以前可以运行,并且仍然可以离线运行.

The application did work before, and still works offline.

这是 AbstractExtension.php 的代码,与 twigphp/twig repo 上的代码相同:

Here's the code of the AbstractExtension.php, which is the same as on the twigphp/twig repo :

<?php

namespace Twig\Extension;

class_exists('Twig_Extension');

if (\false) {
    class AbstractExtension extends \Twig_Extension
    {
    }
}

PS : 这个 if false 听起来很奇怪,但和网上一样,所以我不明白

PS : this if false sounds weird but is the same as online so i don't get it

这是作为文本的日志:

(1/1) RuntimeException
The autoloader expected class "Twig\Extension\AbstractExtension" to be defined in file "/home/homeviewcx/symfony/vendor/composer/../twig/twig/src/Extension/AbstractExtension.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

in DebugClassLoader.php line 288
at DebugClassLoader->checkClass('Twig\\Extension\\AbstractExtension', '/home/homeviewcx/symfony/vendor/composer/../twig/twig/src/Extension/AbstractExtension.php')
in DebugClassLoader.php line 159
at DebugClassLoader->loadClass('Twig\\Extension\\AbstractExtension')
at spl_autoload_call('Twig\\Extension\\AbstractExtension')
in CsrfExtension.php line 21
at require('/home/homeviewcx/symfony/vendor/symfony/twig-bridge/Extension/CsrfExtension.php')
in DebugClassLoader.php line 145
at DebugClassLoader->loadClass('Symfony\\Bridge\\Twig\\Extension\\CsrfExtension')
at spl_autoload_call('Symfony\\Bridge\\Twig\\Extension\\CsrfExtension')
at class_exists('Symfony\\Bridge\\Twig\\Extension\\CsrfExtension')
in FrameworkExtension.php line 1240
at FrameworkExtension->registerSecurityCsrfConfiguration(array('enabled' => true), object(MergeExtensionConfigurationContainerBuilder), object(XmlFileLoader))
in FrameworkExtension.php line 205
at FrameworkExtension->load(array(array('router' => array('resource' => 'kernel::loadRoutes', 'type' => 'service')), array('secret' => 'env_d3d895c31330f4ea_APP_SECRET_dd4bd60cef72a43e4dea38ee2ba60137', 'session' => array('handler_id' => null), 'php_errors' => array('log' => true), 'cache' => null), array('router' => array('strict_requirements' => null)), array('default_locale' => 'en', 'translator' => array('paths' => array('/home/homeviewcx/symfony/translations'), 'fallbacks' => array('en'))), array('validation' => array('email_validation_mode' => 'html5')), array('cache' => array('pools' => array('doctrine.result_cache_pool' => array('adapter' => 'cache.app'), 'doctrine.system_cache_pool' => array('adapter' => 'cache.system'))))), object(MergeExtensionConfigurationContainerBuilder))
in MergeExtensionConfigurationPass.php line 76
at MergeExtensionConfigurationPass->process(object(ContainerBuilder))
in MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder))
in Compiler.php line 95
at Compiler->compile(object(ContainerBuilder))
in ContainerBuilder.php line 746
at ContainerBuilder->compile()
in Kernel.php line 519
at Kernel->initializeContainer()
in Kernel.php line 123
at Kernel->boot()
in Kernel.php line 183
at Kernel->handle(object(Request))
in app.php line 50

这是我的 composer.json :

here's my composer.json :

    {
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "sensio/framework-extra-bundle": "^5.1",
        "symfony/apache-pack": "^1.0",
        "symfony/asset": "^4.1",
        "symfony/config": "^4.1",
        "symfony/console": "^4.1",
        "symfony/dependency-injection": "^4.1",
        "symfony/expression-language": "^4.1",
        "symfony/flex": "^1.0",
        "symfony/form": "^4.1",
        "symfony/framework-bundle": "^4.1",
        "symfony/lts": "^4@dev",
        "symfony/monolog-bundle": "^3.1",
        "symfony/orm-pack": "*",
        "symfony/process": "^4.1",
        "symfony/security-bundle": "^4.1",
        "symfony/serializer-pack": "*",
        "symfony/swiftmailer-bundle": "^3.1",
        "symfony/twig-bundle": "^4.1",
        "symfony/validator": "^4.1",
        "symfony/web-link": "^4.1",
        "symfony/yaml": "^4.1"
    },
    "require-dev": {
        "symfony/debug-pack": "*",
        "symfony/dotenv": "^4.1",
        "symfony/maker-bundle": "^1.0",
        "symfony/profiler-pack": "*",
        "symfony/test-pack": "^1.0",
        "symfony/web-server-bundle": "^4.1"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ],
        "prod": [
          "SET APP_ENV=prod",
          "composer install --no-dev --optimize-autoloader",
          "composer dump-autoload --optimize --no-dev --classmap-authoritative"
        ],
        "dev": [
          "SET APP_ENV=dev",
          "composer install"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false
        }
    }
}

PS:我个人没有在任何地方扩展 AbstractExtension 类(也没有扩展任何其他树枝类),也没有接触容器编译器(这里仍然相对较新),但是是的,可能就是这样

PS: I'm personally not extending the AbstractExtension class anywhere (nor any other twig classes), and haven't touched the container compiler either (still relatively new here), but yes, that might be it

推荐答案

在此处查看导致错误的提交:

Looking at the commit that caused the error here :

https://github.com/twigphp/Twig/commit/2c174e4015dcfdcb4f39d004e3b1aeccae77aa25#diff-d2944cb9ff29770359c04590530f931aL5

唯一的变化是加载类的方式,因为 class_exists('Twig_Extension') 将调用 __autoload() 因此类应该是已经在这个阶段调用了.

The only change is the way the class is expected to be loaded, since class_exists('Twig_Extension') will call __autoload() thus the class is expected to be already called at this stage.

您似乎已经更新了依赖项,但是您是否清除了缓存?由于该问题在本地不可用(在 dev 上工作正常),因此问题仅在您的服务器上(应用在 prod 模式下运行)symfony 可能仍在使用旧的解释错误的缓存.

It looks like you already updated your dependencies, but did you clear the cache ? Since the problem is not available locally (works fine on dev), on the issue is only on your server (app runing in prod mode) symfony could be still using the old cache which explain the error.

如果是这种情况,您需要通过运行以下命令来刷新服务器上的缓存:

If that's the case, you will need to refresh the cache on your server by running:

php bin/console cache:clear --no-warmup --env=prod

这篇关于Symfony - 树枝 - 自动加载器预期类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆