0

I have a messy web application writen in Symfony and Yii. stucture of application looks like:

|- app
|  |- app
|  |- src <code>
|  |  |-App
|  |- protected <symfony fw>
|  |  |-vendor
|  |- yii <yii fw>
|  |- composer.json
|  |- index.php

and index.php require symfony.php. and at that file, i new Kernel class. and it locales inside src/App. but when running, it throw code:

Attempted to load class "Kernel" from namespace "App". Did you forget a "use" statement for e.g. "Symfony\Component\HttpKernel\Kernel", "Illuminate\Contracts\Console\Kernel" or "Illuminate\Contracts\Http\Kernel"?

My symofony.php

<?php

require_once  __DIR__ . '/../protected/vendor/autoload.php';
require_once  __DIR__ . '/../protected/Application.php';
require_once  __DIR__ . '/../protected/Environment.php';

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

require __DIR__ . '/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
    umask(0000);

    Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);

The class Kernel is:

<?php

namespace App;


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

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    private const CONFIG_EXTS = '.{php,xml,yaml,yml}';

    private $files;

My composer.json at autoload:

"autoload": {
        "psr-4": {
            "SCO\\": "src/",
            "App\\": "app/src/App/",
        },
        "classmap" : [
            "protected/components/",
            "protected/models/",
            "protected/modules/"
        ],
    },

you can see, namespace SCO actually cover the App in file directory view.

It work on my macbook (docker), but when i move to windows using xampp, it brokes

Erics Nguyen
  • 370
  • 4
  • 16
  • 1
    add symfony.php file contents to question. That is where you make use of kernel, right? where is symfony.php? – Toskan Aug 18 '22 at 09:33
  • 1
    I'll ask the same question as the error message: "Did you forget a "use" statement for e.g. "Symfony\Component\HttpKernel\Kernel"...?" – M. Eriksson Aug 18 '22 at 09:36
  • i 've updated the `synfony.php`. yes i have requred the `autoload` and use ... – Erics Nguyen Aug 18 '22 at 09:40
  • 1
    `"App\\": "app/src/App/"` From your project structure there doesn't seem to be a `app/src/App/` folder, only `app` and another one `src/App/`. Try `"App\\": "src/App/"` (and maybe `composer du`) – brombeer Aug 18 '22 at 09:47
  • i changed, but still got that error @b – Erics Nguyen Aug 18 '22 at 10:05
  • From this interactive debugging session here on SO, it is now for some hours that it manifests it has ended. We serialize guessing just on the platform to a related error message as we think [edit] is too late. Please see [help] for appropriate usage and further instructions. Thanks for flying with Symfony. – hakre Aug 18 '22 at 21:48
  • i 'm really sorry everybody, i for some reason, when migrate from mac -> win, some folder has been messied, that lead to unable to load it – Erics Nguyen Nov 09 '22 at 13:54

0 Answers0