EkinoWordpressBundle icon indicating copy to clipboard operation
EkinoWordpressBundle copied to clipboard

Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in {project directory}\symfony\app\AppKernel.php on line 7

Open daifma opened this issue 8 years ago • 3 comments

Hello; I'm interested in using symfony and Wordpress but at the first install a get this error Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in {project directory}\symfony\app\AppKernel.php on line 7 My PHP version is 5.6 My symfony version is 2.8 My wordpress version is 4.6.1

daifma avatar Oct 15 '16 18:10 daifma

I am experiencing the same issue using the same versions (with a little tweaked worpdpress docker container)

terox avatar Dec 16 '16 17:12 terox

@daifabde I think that example of wordpress index.php is outdated or use something new in Symfony 3.x. Try the new index.php file. It worked for me:

<?php

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

/**
 * Retrieves or sets the Symfony Dependency Injection container
 *
 * @param ContainerInterface|string $id
 *
 * @return mixed
 */
function symfony($id)
{
    static $container;

    if ($id instanceof ContainerInterface) {
        $container = $id;
        return;
    }

    return $container->get($id);
}

$loader = require __DIR__.'/../symfony/app/autoload.php';
require_once __DIR__.'/../symfony/app/bootstrap.php.cache';

// Load application kernel
require_once __DIR__.'/../symfony/app/AppKernel.php';

$sfKernel = new AppKernel('dev', true);
$sfKernel->loadClassCache();
$sfKernel->boot();

// Add Symfony container as a global variable to be used in Wordpress
$sfContainer = $sfKernel->getContainer();

if (true === $sfContainer->getParameter('kernel.debug', false)) {
    Debug::enable();
}

symfony($sfContainer);

$sfRequest = Request::createFromGlobals();
$sfResponse = $sfKernel->handle($sfRequest);
$sfResponse->send();

$sfKernel->terminate($sfRequest, $sfResponse);

As you will see the path to bootstrap.php.cache was changed into app/ (older/newer versions of Symfony works with var/ but I haven't known what versions exactly). The error is related with autoload.php (inexistent) in the original file by the same reasons (the Symfony versions).

I hope that it solves your headaches

terox avatar Dec 16 '16 17:12 terox

As of 11/01/2017 and Symfony 3.3 :)

<?php

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

/**
 * Retrieves or sets the Symfony Dependency Injection container
 *
 * @param ContainerInterface|string $id
 *
 * @return mixed
 */
function symfony($id)
{
    static $container;

    if ($id instanceof ContainerInterface) {
        $container = $id;
        return;
    }

    return $container->get($id);
}

$loader = require __DIR__.'/../symfony/vendor/autoload.php';
require_once __DIR__.'/../symfony/var/bootstrap.php.cache';

// Load application kernel
require_once __DIR__.'/../symfony/app/AppKernel.php';

$sfKernel = new AppKernel('dev', true);
$sfKernel->loadClassCache();
$sfKernel->boot();

// Add Symfony container as a global variable to be used in Wordpress
$sfContainer = $sfKernel->getContainer();

if (true === $sfContainer->getParameter('kernel.debug', false)) {
    Debug::enable();
}

symfony($sfContainer);

$sfRequest = Request::createFromGlobals();
$sfResponse = $sfKernel->handle($sfRequest);
$sfResponse->send();

$sfKernel->terminate($sfRequest, $sfResponse);

autoload.php will be located at: symfony/vendor/autoload.php And bootstrap.php.cache at: symfony/var/bootstrap.php.cache

wiejakp avatar Nov 05 '17 04:11 wiejakp