Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4 - ClassNotFoundException Kernel

Tags:

php

symfony

I'm actually upgrade my symfony 3.4 project to symfony 4.0. After clone bundles from my gitlab repositories with composer update, I have an error :

ClassNotFoundException

Attempted to load class "Kernel" from namespace "App".
Did you forget a "use" statement for "Symfony\Component\HttpKernel\Kernel"?


in index.php (line 32)

Ok.... Easy... go index.php line 32... but, Kernel is load with App\Kernel, so any idea why I have this error or where I can search?

Thank you for your help.

index.php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
    (new Dotenv())->load(__DIR__.'/../.env');
}

if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) {
    umask(0000);

    Debug::enable();
}


    // Request::setTrustedProxies(['0.0.0.0/0'], Request::HEADER_FORWARDED);

$kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev')));

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

And in the "src" directory, I have the Kernel.php file

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
    .....
like image 339
Skyd Avatar asked Dec 26 '17 18:12

Skyd


2 Answers

Symfony 4 uses the folder App for autoload psr-4. I tried to change it, but it didn't work out. Check the namespace at your composer.json file, in the property autoload and then psr-4. Maybe you changed the default one.

like image 167
Luma Macagnan Avatar answered Sep 18 '22 08:09

Luma Macagnan


Maybe you just accidentially removed the PSR-4 block in composer.json that is always needed for Symfony4:

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
like image 40
Sliq Avatar answered Sep 18 '22 08:09

Sliq