繁体   English   中英

Symfony错误:找不到类'Symfony \\ Component \\ HttpKernel \\ Kernel'

[英]Symfony error: Class 'Symfony\Component\HttpKernel\Kernel' not found

从Symfony 3.1升级到3.2后,我收到以下错误消息:

致命错误:第6行的/var/www/html/HeliosBlog/app/AppKernel.php中找不到类'Symfony \\ Component \\ HttpKernel \\ Kernel'

这是我的app / autoload.php的样子:

<?php

use Doctrine\Common\Annotations\AnnotationRegistry;

if (!$loader = @include __DIR__.'/../vendor/autoload.php') {

    $message = <<< EOF

EOF;

    if (PHP_SAPI === 'cli') {
        $message = strip_tags($message);
    }

    die($message);
}

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

这是我的app_dev.php文件的样子:

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], array(
            '127.0.0.1',
            'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

这就是我的AppKernel.php的样子:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{

    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\AopBundle\JMSAopBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new Helios\BlogBundle\HeliosBlogBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Helios\UserBundle\HeliosUserBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new FOS\ElasticaBundle\FOSElasticaBundle(),
            new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
            new Helios\ManagerBundle\HeliosManagerBundle(),
            new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
            //new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
            new Oneup\UploaderBundle\OneupUploaderBundle(),
            new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

            $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
            $bundles[] = new CoreSphere\ConsoleBundle\CoreSphereConsoleBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

已经尝试删除供应商文件夹并进行作曲家安装。

有任何想法吗?

我只需添加即可解决问题

require_once __DIR__.'/autoload.php';

到应用程序/控制台之前

require_once __DIR__ . '/AppKernel.php';` 

陷入同样的​​错误。 发现bootstrap.php.cache没有意识到内核类。 这是因为Sensio Distibution捆绑包有更新。 为此,我发布了一个问题,可以在这里找到: https//github.com/sensiolabs/SensioDistributionBundle/issues/302

我希望这对其他人也有帮助。

我在运行composer update时遇到了这个问题,因为它仍然使用app/console (可能已过时)而不是新的bin/console

我解决了这个问题:

  • 删除app/console文件。
  • 在我的项目根目录中创建一个var/文件夹 - 请参阅此答案以获得解释。

我也遇到了这个问题,同时将我的项目从Symfony 2.x更新(不记得是2.7还是2.8)到3.2。 结果是问题是由app/console文件引起的。 我认为问题是由我很久以前创建项目的方式引起的。

为了解决这个问题,我从另一个成功升级到3.2的项目中复制了app/console文件。 我不确定是否会有其他问题,但至少我摆脱了这个错误。

促使我做出这一改变的讨论是https://github.com/symfony/symfony/issues/16713

暂无
暂无

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

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