ezimuel / apigility-symfony2-use-case

Create a RESTful API for a Symfony2 project using Apigility (http://apigility.org)
41 stars 11 forks source link

Cant find Symfony application AppKernel.php by apigility. #5

Open vrkansagara opened 8 years ago

vrkansagara commented 8 years ago

I am accessing the http://apigility.local/post where I have successfully added the ApiBlog module from this repository. and added Symfony application. file into PostResource.php under the __construct method as bellow

public function __construct()
    {
        $symfonyApp = '/home/vallabh/www/symfony2app';
        require_once $symfonyApp . '/app/AppKernel.php';

        $kernel = new \AppKernel('prod', true);
        $kernel->loadClassCache();
        $kernel->boot();

        $this->doctrine = $kernel->getContainer()
            ->get('doctrine')
            ->getManager();
    }

But still error showing.

I have tested that AppKernel.php is successfully called into the __construct but while accessing the api get request http://apigility.local/post thowring the errors as bellow.

Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in /home/vallabh/www/symfony2app/app/AppKernel.php on line 7
vrkansagara commented 8 years ago

Ping :+1: @ezimuel and @weierophinney

ezimuel commented 8 years ago

@vrkansagara this example of integration with Symfony is quite old, I didn't check for a while. The idea here is to execute the bootstrap part of a Symfony app. The error that you reported shows a problem of autoloading for the Symfony components. Are you sure that your Symfony app is working fine without Apigility? I suggest to have a look at composer.json.

vrkansagara commented 8 years ago

@ezimuel Yes my symfony working fine independently and apigility as well. The root cause I find that there a one package name called kriswallsmith is common in apigility and symfony so it generating the errors. But any way I have figure it out how to resolve it. Thanks a lot to sharing a POC.

here is my recent code which is working fine under the apigility under the PostResource.php.

 require_once  '/home/vallabh/www/symfony2app/web/app.php';
        $kernel = new \AppKernel('prod', true);
        $kernel->loadClassCache();
        $kernel->boot();

        $this->doctrine = $kernel->getContainer()
            ->get('doctrine')
            ->getManager();

I would like to ask you that if possible than can you make a POC for the magento. A contact book or any other idea which is built on zf2 core (having exprassive as a middleware) Application + apigility as api.

Think-It commented 8 years ago

Hi guys,

I got the same error. And when I try your solution @vrkansagara I got this error :

PHP Fatal error:  Cannot redeclare assetic_init() (previously declared in /Users/lucas/Sites/booking/apigility/vendor/kriswallsmith/assetic/src/functions.php:24) in /Users/lucas/Sites/booking/booking/vendor/kriswallsmith/assetic/src/functions.php on line 30

Poke @ezimuel

Think-It commented 8 years ago

Hi,

I fixed this issue with :

$symfonyApp = '/path/to/symfony/';
require_once $symfonyApp . '/app/bootstrap.php.cache'; // This line is important
require_once $symfonyApp . '/app/AppKernel.php';

$kernel = new \AppKernel('prod', true);
$kernel->loadClassCache();
$kernel->boot();

$this->doctrine = $kernel->getContainer()
->get('doctrine')
->getManager();