Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: No Metadata Classes to process. #46

Open
mikebell opened this issue Feb 5, 2015 · 20 comments
Open

Question: No Metadata Classes to process. #46

mikebell opened this issue Feb 5, 2015 · 20 comments

Comments

@mikebell
Copy link

mikebell commented Feb 5, 2015

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
Copy link
Member

simensen commented Feb 5, 2015

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
Copy link
Contributor

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

@mikebell
Copy link
Author

mikebell commented Feb 5, 2015

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
Copy link
Member

simensen commented Feb 5, 2015

@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
Copy link
Author

mikebell commented Feb 5, 2015

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

It resides inside src/

@simensen
Copy link
Member

simensen commented Feb 5, 2015

@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
Copy link
Contributor

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

@simensen
Copy link
Member

simensen commented Feb 5, 2015

@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
Copy link
Contributor

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

@mikebell
Copy link
Author

mikebell commented Feb 5, 2015

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
Copy link
Contributor

@mikebell change 10/11 with 13/14

@simensen
Copy link
Member

simensen commented Feb 5, 2015

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
Copy link
Author

mikebell commented Feb 5, 2015

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
Copy link
Contributor

@mikebell your welcome

@ggioffreda
Copy link

Try and change:

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

with:

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

That should work.

@PapyDanone
Copy link

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
Copy link
Contributor

@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
Copy link

pmpr commented Jun 16, 2016

exact same problem here with no success!

@fearintino
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants