contao-community-alliance / dependency-container

Dependency container for Contao Open Source CMS based on the Pimple Dependency Injection Container
GNU Lesser General Public License v3.0
1 stars 4 forks source link

[RFC] Release/2.0.0 #13

Closed discordier closed 6 years ago

discordier commented 7 years ago

This PR is the work in progress for the new version 2.0 which will provide compatibility with Contao 3 & 4.

dmolineus commented 7 years ago

Looks good so far. What do you think about simplifying the definition of fallback services for Contao 3 by adding a second param to the share method:

<?php

$container['example'] = $container->share(
    function () {
        return new Example();
    },
    'vendor.example'
);

Inside the share method it's checked if the symfony container is available. If the container is available and second param is passed, the service is delegated. Overthise the first param is used as fallback (Contao 3).

Well, the definition of the closures are parsed in Contao 4 as well. I wouldn't mind for that overhead.

We could provide a $container->factory method as well for non shared services which acts the same way.

discordier commented 7 years ago

Problem is, the share method is stateless and therefore we would then always be setting a service, the alias will get ignored or, worse the exception that the service has been overridden will get triggered.

So I see no way how your idea could work, if you see any, please explain as I'm always open for simplifying stuff.

baumannsven commented 7 years ago

I have update this for contao 4.

For travis i must install contao manager plugin or excluded the path?

@discordier Can you show this?

discordier commented 7 years ago

I added some more changes. Please review.