1

I've got a fatal error when I try to simply use the HttpKernel Component.

Fatal error: Class 'Symfony\Component\Config\FileLocator' not found in /.../vendor/symfony/http-kernel/Config/FileLocator.php on line 23

All packages has been install via composer 1.8.x The setup is minimalist

PHP 5.6

symfony/dependency-injection          v3.4.27             Symfony DependencyInjection Component
symfony/event-dispatcher              v3.4.27             Symfony EventDispatcher Component
symfony/http-foundation               v3.4.27             Symfony HttpFoundation Component
symfony/http-kernel                   v3.4.27             Symfony HttpKernel Component
symfony/process                       v3.4.27             Symfony Process Component
symfony/yaml                          v3.4.27             Symfony Yaml Component

I do not want to install all symfony/symfony package.

The facts is that symfony/config is a "require-dev" dependency and seems not to be installed. What I usually understand is that require-dev installation is normally install when you just run composer install|update. Apparently not...

Follow the code below

use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
use Symfony\Component\HttpKernel\Config\FileLocator;

class MyKernel extends SymfonyKernel {

  public function boot() {
    // ...
    $this->iamOnError();
    // ...
  }

  public function iamOnError() {
    // @see SymfonyKernel::getContainerLoader
    $locator = new FileLocator($this);
  }

}
use App\MyKernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;

$kernel = new MyKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

My solution is to add "symfony/config" in the root composer.json... This is a kind weird...

So my question is why I've got this error (I know that symfony/config is not installed), or why symfony/config is not a "require" in composer.json for symfony/http-kernel component.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
  • So does "composer require symfony/config --dev" fix the problem? Can't really say why it was not installed automatically. Unless maybe you installed the packaged using a production filter. – Cerad May 09 '19 at 15:02
  • Yep, but: "You are using the deprecated option "dev". Dev packages are installed by default now." So it does not work too... – Adrien Loyant May 09 '19 at 15:57
  • I don't have a 5.6 machine handy but was able to install kernel 4.2 under 7.3. The config was not loaded by default which was a bit surprising but a composer require --dev symfony/config brought it right in as expected. Maybe you need to specify the config version? Just a guess. Maybe try a fresh project and just require the kernel followed by config. – Cerad May 09 '19 at 18:32
  • use symfony/config in the require part of composer.json will do the job but I wanted to know if I was misunderstanding something. Thank you for your help by the way ;) – Adrien Loyant May 10 '19 at 07:35
  • Turns out that the config component is optional for http-kernel. I got: "symfony/http-kernel suggests installing symfony/console" along with various other suggestions which makes sense. You can certainly use the kernel without the config stuff. So you only load it if you need it. – Cerad May 10 '19 at 12:11

0 Answers0