atrauzzi / laravel-doctrine

An ORM for a Framework for Web Artisans
121 stars 59 forks source link

No Metadata Classes to process #104

Closed jacekjagiello closed 9 years ago

jacekjagiello commented 9 years ago

Hey, I've read #72 because I have the same problem. I set 'metadata' => [ 'driver' => 'annotation' ] in doctrine.php, clear cache, but it does not pick up my entities; I got No Metadata Classes to process when I run vendor/bin/doctrine orm:schema:create

Heres my doctrine.php

<?php return [

    'metadata' => [
        'driver' => 'annotation',
    ],

    'connections' => [
        // Some preset configurations to map laravel sqlite configs to doctrine
        'sqlite' => [
            'driver' => 'pdo_sqlite',
            'mappings' => [
                'database' => 'path'
            ]
        ]
    ],

    'cache' => [
        'redis' => [
            'host'     => '127.0.0.1',
            'port'     => 6379,
            'database' => 1
        ],
        'memcache' => [
            'host' => '127.0.0.1',
            'port' => 11211
        ],
        'providers' => [
            'memcache' => 'Atrauzzi\LaravelDoctrine\CacheProvider\MemcacheProvider',
            'memcached' => 'Atrauzzi\LaravelDoctrine\CacheProvider\MemcachedProvider',
            'couchbase' => 'Atrauzzi\LaravelDoctrine\CacheProvider\CouchebaseProvider',
            'redis' => 'Atrauzzi\LaravelDoctrine\CacheProvider\RedisProvider',
            'apc' => 'Atrauzzi\LaravelDoctrine\CacheProvider\ApcProvider',
            'xcache' => 'Atrauzzi\LaravelDoctrine\CacheProvider\XcacheProvider',
            'array' => 'Atrauzzi\LaravelDoctrine\CacheProvider\ArrayCacheProvider'
        ]
    ],

    'migrations' => [
        'directory' => '/database/doctrine-migrations',
        'namespace'  => 'DoctrineMigrations',
        'table_name' => 'doctrine_migration_versions'
    ],

    'custom_types' => [
        'json' => 'Atrauzzi\LaravelDoctrine\Type\Json'
    ],

    'auth' => [
        //'authenticator' => 'Atrauzzi\LaravelDoctrine\DoctrineAuthenticator',
        //'model' => 'App\Models\User',
    ]
];
jacekjagiello commented 9 years ago

One more thing, my Entity namespace look like this: Acme\Blog\Model\Post When I move my entity to app folder and change namespace to just App, it works! I've tried to create mappings like:

'mappings' => [
        'Acme\Blog\Model\Post => [
            'table' => 'task',
            'abstract' => false,
        ],
    ],

But it doesn't work, still No Metadata Classes to process

josenicomaia commented 9 years ago

@JacekJagiello To use annotations with a custom namespace, you should set: doctrine.php

    'metadata' => [
        [
            'driver' => 'annotation',
            'namespace' => 'Acme'
        ]
    ],

The default option for metada."array".namespace is App

josenicomaia commented 9 years ago

@JacekJagiello In my case, instead of running a "full annotation scan", i did this:

    'metadata' => [
        [
            'driver' => 'annotation',
            'namespace' => 'App\\Model\\X\\Entity',
            'alias' => 'X'
        ],
        [
            'driver' => 'annotation',
            'namespace' => 'App\\Model\\Y\\Entity',
            'alias' => 'Y'
        ],
        [
            'driver' => 'annotation',
            'namespace' => 'App\\Model\\Z\\Entity',
            'alias' => 'Z'
        ]
    ],

With this, i reduced the number of files to scan. And i can use this:

    // Return the repository for this model
    \EntityManager::getRepository('X:Class');
    \EntityManager::getRepository('Y:Class');
jacekjagiello commented 9 years ago

@josenicomaia Thanks to you I find out something:

    'metadata' => [
        [
            'driver' => 'annotation',
        'namespace' => 'App\\Blog\\Model\\Post',
        'alias' => 'Post'
        ]
    ],

It works! Post entity was found. But if I have Acme as a first part of namespace:

    'metadata' => [
        [
            'driver' => 'annotation',
        'namespace' => 'Acme\\Blog\\Model\\Post',
        'alias' => 'Post'
        ]
    ],

It does not work. I still have No Metadata Classes to process. Well, I like to keep application on it's own namespace, and I don't want to move it into app/ folder, only to make it recognizable by library. My Acme namespace is loaded by composer autoloader, I can use it within my code, but Doctrine don't pick it up for some reason. Maybe when I run vendor/bin/doctrine orm:schema:create my entity isn't loaded jet, or isn't loaded at all?

josenicomaia commented 9 years ago

@JacekJagiello Can you print your files tree?

jacekjagiello commented 9 years ago

Yes of course: project_tree

josenicomaia commented 9 years ago

Wow. Now i understand. Why are you using app folder? It's supposed to be used for you app development. image

josenicomaia commented 9 years ago

@JacekJagiello If you want, I guess you can do using this: doctrine.php

    'metadata' => [
        [
            'driver' => 'annotation',
            'namespace' => 'Acme\\Blog\\Model',
            'alias' => 'Blog',
            'paths' => base_path('src/Acme')
        ]
    ],
    // Return the repository for this model
    \EntityManager::getRepository('Acme\\Blog\\Model\\Post');
    // or just:
    \EntityManager::getRepository('Blog:Post');
jacekjagiello commented 9 years ago

Well, for me, any kind of framework(like Laravel) or library(like thi library) is a "plugin" to the application. Framework, it's not something your app is build upon, it's rather like tool to help you build an app. This is called hexagonal architecture, and it's say you shouldn't mix your application code(application use cases, domain logic and business rules) with your framework. Framework should only "trigger" your application code(via controllers).

So, in the app folder I will keep Laravel specific code(controllers, service providers, forms) and in src I will keep my entities, aggregates, value objects, domain events, use cases etc.

jacekjagiello commented 9 years ago

@josenicomaia Wow, adding 'paths' => base_path('src/Acme') solves the problem! :) I must say that doctrine mapping config is a bit tricky.

Thanks again!

josenicomaia commented 9 years ago

@JacekJagiello Hmmm, I understand. I will learn about this architecture =]

I am grad to help. You're welcome =]

josenicomaia commented 9 years ago

PS.: If this problem is solved, you can close this issue. =]

josenicomaia commented 9 years ago

I guess that we need to document more =P