laravel-doctrine / extensions

Extensions integration for Doctrine2 and Laravel
http://laraveldoctrine.org/
MIT License
48 stars 24 forks source link

Annotation does not exist (Lumen) #28

Closed mwuhahaha closed 8 years ago

mwuhahaha commented 8 years ago

Hello, first thank you very much for your work on this awesome project.

I am getting the following error:

[Doctrine\Common\Annotations\AnnotationException]                                                      
  [Semantical Error] The annotation "@Gedmo\Mapping\Annotation\Timestampable" in property App\Entities\  
  Customer::$createdAt does not exist, or could not be auto-loaded.   

when attempting to run php artisan doctrine:info

My bootstrap/app.php is as follows

<?php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

$app->withFacades();

// $app->withEloquent();

/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/

// $app->middleware([
//    App\Http\Middleware\ExampleMiddleware::class
// ]);

// $app->routeMiddleware([
//     'auth' => App\Http\Middleware\Authenticate::class,
// ]);

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/

//$app->register(App\Providers\AppServiceProvider::class);
//$app->register(App\Providers\AuthServiceProvider::class);
//$app->register(App\Providers\EventServiceProvider::class);

$app->register(LaravelDoctrine\ORM\DoctrineServiceProvider::class);
$app->register(LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class);
$app->register(Dingo\Api\Provider\LumenServiceProvider::class);

class_alias('LaravelDoctrine\ORM\Facades\EntityManager', 'EntityManager');
class_alias('LaravelDoctrine\ORM\Facades\Registry', 'Registry');
class_alias('LaravelDoctrine\ORM\Facades\Doctrine', 'Doctrine');
class_alias('Dingo\Api\Facade\API','API');
class_alias('Dingo\Api\Facade\Route','Route');

app('Dingo\Api\Transformer\Factory')->setAdapter(function ($app) {
    return new Dingo\Api\Transformer\Adapter\Fractal(new League\Fractal\Manager, 'include', ',');
});

//$app->register('Tymon\JWTAuth\Providers\JWTAuthServiceProvider');

/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
    require __DIR__.'/../app/Http/routes.php';
});

return $app;

and composer.json has been updated.

It's referring to:

namespace App\Entities;
use Doctrine\ORM\Mapping as Orm;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
...
/**
     * @var DateTime $created_at
     *
     * @Gedmo\Timestampable(on="create")
     * @Orm\Column(name="created_at", type="datetime")
     * @access protected
     */
    protected $createdAt;

Any ideas? Seems like many people ran into an issue including the ExtensionsServiceProvider before the DoctrineServiceProvider, but that does not seem to be the case here.

Thanks again for your help.

patrickbrouwers commented 8 years ago

Hey!

At first glance everything looks okay to me. I currently don't have a Lumen app with annotations running. My Laravel5 app with annotations works with Timestampable and my Lumen5 app with Fluent works as well. Is it only the doctrine:info command that fails or if you open the app too?

josenicomaia commented 8 years ago

You are not loading the config files. Could it be the problem? I will post a snipet soon about loading the configs

josenicomaia commented 8 years ago

When I configured lumen, I had to load some config files like it:

PS 1: I am not using annotations too. I am using fluent as mapping drive. PS 2: I had to create the manually the config folder and the config files because you cannot let lumen generate then. Lumen doesn't support it.

...

$app->withFacades();

// $app->withEloquent();

/*
|--------------------------------------------------------------------------
| Register Configuration Files
|--------------------------------------------------------------------------
|
| Now we will register the configuration files.
|
*/
$app->configure('cache');
$app->configure('database');
$app->configure('doctrine');
$app->configure('filesystems');
$app->configure('mail');
$app->configure('migrations');
$app->configure('services');
mwuhahaha commented 8 years ago

@josenicomaia That solved it for me. Thank you very much. I wasn't properly loading the config file.

Thank you both for your help and the great work you've done.