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

Ability to use metadata map without exact class name match #119

Open
glennschmidt opened this issue Oct 29, 2013 · 1 comment
Open

Ability to use metadata map without exact class name match #119

glennschmidt opened this issue Oct 29, 2013 · 1 comment

Comments

@glennschmidt
Copy link

Currently the MetadataMap always does an exact class name comparison between get_class($your_resource) and the key in the map. It doesn't take inheritance into account. This prevents the map being used with Doctrine entities.

If you retrieve a MyModels\User instance from doctrine, get_class() might actually return DoctrineORMModule\Proxy\__CG__\MyModels\User, which is an auto-generated proxy subclass.

Could I suggest that PhlyRestfully either

  • Make MetadataMap check each map key against the resource with an instanceof test when the get_class comparison fails, or
  • Make it easier to supply a custom subclass of MetadataMap so that Doctrine users can implement this behaviour?

At the moment i'm making do by awkwardly overriding the definition of the 'PhlyRestfully\MetadataMap' service factory in my local module, to instantiate my MetadataMap subclass.

Here's the code I have in my subclass FYI:

    public function get($class)
    {
        //First try the default logic (look for an exact class-name match)
        if (parent::has($class))
            return parent::get($class);

        //Next check each class in the map to see if our object inherits from it
        if (is_object($class))
        {
            foreach ($this->map as $className => $metadata)
            {
                if ($class instanceof $className)
                    return $metadata;
            }
        }

        return null;
    }
@Waldz
Copy link

Waldz commented Dec 7, 2013

I solved this exact problem in my local source.
But it is first time I want to contribute code, where should I start? :/

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

2 participants