I was using the mapResolver in the site, but now changed to ResolverCollection and is giving me the exception “Return value of App\Application::getAuthorizationService() must be an instance of Authorization\AuthorizationServiceInterface, instance of Authorization\Policy\ResolverCollection returned”.
This is the code for getAuthorizationService:
public function getAuthorizationService(ServerRequestInterface $request): AuthorizationServiceInterface {
$ormResolver = new OrmResolver();
$mapResolver = new MapResolver();
$mapResolver->map(ServerRequest::class, RequestPolicy::class);
return new ResolverCollection([$mapResolver, $ormResolver]);
}
How do I have to write the code for the getAuthorizationService method so that it doesn’t give me that exception?
The example code in the docs shows:
public function getAuthorizationService(ServerRequestInterface $request): AuthorizationServiceInterface
{
$resolver = new OrmResolver();
return new AuthorizationService($resolver);
}
So your implementation should also be returning a new AuthorizationService
object which might take your MapResolver
as an argument.
Here is some example code from my own app:
public function getAuthorizationService(ServerRequestInterface $request): AuthorizationServiceInterface
{
$resolver = new OrmResolver();
$mapResolver = new MapResolver();
$mapResolver->map(ServerRequest::class, RequestPolicy::class);
$mapResolver->map(IdPackage::class, IdAccessPolicy::class);
$mapResolver->map(StackSet::class, StackSetPolicy::class);
$mapResolver->map(OrderWrapper::class, OrderLifecylePolicy::class);
$resolverCollection = new ResolverCollection([$resolver, $mapResolver]);
return new AuthorizationService($resolverCollection);
}