zendframework/zend-expressive-hal

populateMetadataMapFromConfig should allow classes

grizzm0 opened this issue · 1 comments

Provide a narrative description of what you are trying to accomplish.

Code to reproduce the issue

MetadataMap::class => [
    [
        '__class__' => RouteBasedResourceMetadata::class,
        'resource_class' => Post::class,
        'route' => 'blog.post',
        'extractor' => ClassMethods::class,
    ],
    new RouteBasedResourceMetadata(
        Post::class,
        'blog.post',
        ClassMethods::class
    ),
];

Expected results

Imho both of the above should work the same. The later is better as it's typed.

Actual results

The second config fails as only arrays are allowed.

There's a bit of an issue, however, when it comes to usage within Expressive: we cache configuration. As such, having actual instances in play could lead to errors.

The whole point of using configuration is to have a serialization format that we can then expand into objects. If it also includes actual object instances, why bother with configuration in the first place?

Additionally, if you want to use actual object instances, you can already do so by registering delegators for the MetadataMap service.

Closing, as this is not a feature we want to support at this time.