Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.
This repository was archived by the owner on Aug 17, 2025. It is now read-only.

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

@glennschmidt

Description

@glennschmidt

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions