Ability to use metadata map without exact class name match
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
instanceoftest when theget_classcomparison 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;
}
I solved this exact problem in my local source. But it is first time I want to contribute code, where should I start? :/