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}';
.....
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.
Maybe you just accidentially removed the PSR-4 block in composer.json
that is always needed for Symfony4:
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With