mapbender / mapbender

The spatial web mapping framework and core-module
https://mapbender.org/
Other
92 stars 34 forks source link

Extract Application Resolving Logic to separate service that can be overwritten by DI #1604

Closed Phocacius closed 1 month ago

Phocacius commented 1 month ago

Adding custom, dynamic applications was difficult in the previous implementation, since a couple of controllers inherited from YamlApplicationAwareController. It's behaviour could only be modified controller by controller, reuslting in several sources of truth.

The new implementation extracts the logic of resolving a slug to an application class to a seperate service (Mapbender\CoreBundle\Component\Application\ApplicationResolver, or it alias mapbender.application.resolver. It defaults to Mapbender\CoreBundle\Component\Application\DbAndYamlApplicationResolver, but can be easily overridden by either changing the parameter mapbender.application.resolver.class or creating a new service that aliases to Mapbender\CoreBundle\Component\Application\ApplicationResolver, e.g.

#[AsAlias(ApplicationResolver::class)]
class CustomApplicationResolver extends DbAndYamlApplicationResolver
{
    public function __construct(
        #[Autowire(service: 'mapbender.application.yaml_entity_repository')] ApplicationYAMLMapper $yamlRepository,
        EntityManagerInterface $em,
        AuthorizationCheckerInterface $authorizationChecker)
    {
        parent::__construct($yamlRepository, $em, $authorizationChecker);
    }

    public function getApplicationEntity(string $slug): Application
    {
        // Your custom logic here
        return parent::getApplicationEntity($slug);
    } 
}