dflydev / dflydev-doctrine-orm-service-provider

Doctrine ORM Service Provider
MIT License
209 stars 59 forks source link

Question: No Metadata Classes to process. #46

Open mikebell opened 9 years ago

mikebell commented 9 years ago

I'm trying to get this working in Silex but struggling when setting it up.

I get "No Metadata Classes to process." when trying to create the schema through my console app.

The schema validates fine if I run orm:validate-schema

Below is my config. Example\Api\Entities is mapped to "src/Example/Api/Entities" in my composer.json file (similar namespaces are working)

"orm.em.options" => array(
    "mappings" => array(
        // Using actual filesystem paths
        array(
            "type" => "annotation",
            "namespace" => "Example\Api\Entities",
            "path" => __DIR__."/../src/Example/Api/Entities",
        ),
    ),
),

Changing the path to a none existant path breaks validate-schema as expected.

This is my entity file

<?php

namespace Example\Api\Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="example")
 */
class Example
{
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=100)
 */
protected $name;

/**
 * @ORM\Column(type="decimal", scale=2)
 */
protected $price;

/**
 * @ORM\Column(type="text")
 */
protected $description;
}

I'm not really sure how to fix this. Any help would be greatly appreciated.

simensen commented 9 years ago

Does this help at all? It seems like it would not matter if things are working for the schema part but maybe it loads up slightly differently?

dominikzogg commented 9 years ago

@simensen was also my first thought ;-), Cause everything else seems to be ok

mikebell commented 9 years ago

Thanks for the quick support, I've tried adding the AnnotationRegistry to both my console.php and index.php (where orm.em.options is) and still no luck.

simensen commented 9 years ago

@mikebell Where is the orm:validate-schema command coming from? And which command are you running to try and create your schema? Maybe posting your console.php to a gist/pastebin would be useful?

mikebell commented 9 years ago

Here is my console.php - https://gist.github.com/mikebell/b7f7e94887cd00723830

It resides inside src/

simensen commented 9 years ago

@mikebell Nothing is jumping out at me as being wrong. :-/ I haven't used those commands like that in awhile so I'm not sure what they are looking for or are expecting. You can look at the command that works (ValidateSchemaCommand) and see how it differs from the one that does not (CreateCommand). It is possible the commands in the SchemaTool namespace have different dependencies than the ValidateSchemaCommand. I'd look to see how each is using the HelperSet and see if there is something else you need to be adding to it in order for the CreateCommand to work.

If you end up finding a solution here it would be great if you could report that here so we can track this down in the future or look to adding it into some documentation somewhere.

dominikzogg commented 9 years ago

@mikebell it seems you register the Annotation Registry after calling the entity manager Call it at first after the use statments.

simensen commented 9 years ago

@dominikzogg d'oh. i was looking at how far down the annotation registry was being added but i decided in the end that i wouldn't mention it. i usually do that right after the class loader is created so i've never run into anything like this.

@mikebell my guess is that @dominikzogg is right on this. try moving the annotation registry call before you get $em from the container.

thank you so much, @dominikzogg!

dominikzogg commented 9 years ago

@simensen i hope it's the solution and you know i try to support this provider as it would be mine ;-)

mikebell commented 9 years ago

Seem to be getting somewhere now. I've updated my console.php to - https://gist.github.com/mikebell/b7f7e94887cd00723830

I know get:

PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'A callable is expected in AnnotationRegistry::registerLoader().' in /var/www/kardio.dev/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:111
Stack trace:
#0 /var/www/kardio.dev/src/console.php(14): Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(Array)
#1 /var/www/kardio.dev/src/console(3): require('/var/www/kardio...')
#2 {main}
  thrown in /var/www/kardio.dev/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php on line 111
dominikzogg commented 9 years ago

@mikebell change 10/11 with 13/14

simensen commented 9 years ago

I think this is because of how require_once works. I believe you are probably doing require_once in web/index.php already. So when you require_once again, it doesn't actually return the $loader since it was already required in web/index.php. I'd suggest putting these lines just before you include web/index.php.

$loader = require_once __DIR__.'/../vendor/autoload.php';
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

All of which is a longer form (with explanation) of what @dominikzogg just said while I was writing this. :)

mikebell commented 9 years ago

Back to the "No Metadata Classes to process." error again. I'm going to park this for now, thanks for both your help, didn't expect to get this much help!

dominikzogg commented 9 years ago

@mikebell your welcome

ggioffreda commented 9 years ago

Try and change:

    "path" => __DIR__."/../src/Example/Api/Entities",

with:

    "path" => __DIR__."/../src",

That should work.

PapyDanone commented 9 years ago

My problem with the "No Metadata Classes to process." error was that my generated entities were missing a namespace. Looks like it needs to be the same as the provider's "namespace" config value.

marcojanssen commented 9 years ago

@mikebell Maybe to give you some more ways to use this provider. I used it in my silex skeleton which by default has example entities setup. It lacks proper documentation so if you need help setting it up then gimme a shout. Skeleton can be found at:

https://github.com/marcojanssen/silex-rest

pmpr commented 8 years ago

exact same problem here with no success!

fearintino commented 7 years ago

Hello. You need to set alias to 'core' and disable use_simple_annotation_reader.

['mappings' => [
    [
        'alias' => 'core',
        'type' => 'annotation',
        'namespace' => 'TestApp\Entity',
        'path' => __DIR__ . '/TestApp/Entity',
        'use_simple_annotation_reader' => false,
    ],
]]
youssman commented 7 years ago

It's an old post but if someone have the same problem, I suggest adding "use_simple_annotation_reader" => false, it worked for me.

"orm.em.options" => array(
    "mappings" => array(
        // Using actual filesystem paths
        array(
            "type" => "annotation",
            "namespace" => "Example\Api\Entities",
            "path" => __DIR__."/../src/Example/Api/Entities",
            "use_simple_annotation_reader" => false,
        ),
    ),
),

Hope it will helps someone