Repository: pimcore/pimcore (language: php)

Issue:
[Pimcore 11]: Pimcore Kernel registerContainerConfiguration
### Expected behavior

Resolving parameters after all Bundle Extensions have been loaded

### Actual behavior

It wants to resolve them before the Extensions have been loaded

### Steps to reproduce

Install CoreShop with Pimcore 11, when building the container, you get following issue:

```
You have requested a non-existent parameter "coreshop.model.user.class"
```

Reason for that is: CoreShop has a configuration for the pimcore security encoders like:

```yaml
pimcore:
    security:
        encoder_factories:
            '%coreshop.model.user.class%': coreshop.security.user.password_encoder_factory
```

CoreShop registers these parameters in another Dependency Injection Extension that is not loaded when Pimcore calls `Kernel::registerContainerConfiguration`. 

This is a chicken egg sort of Problem. The idea is to, based on configuration, load settings from Config Files.  I don't have a real solution for this. Although I see it is a major Problem, no Pimcore config can depend on Parameters defined in other Bundle Extensions or Compiler Passes.


Discussion / hints:
Is that a Pimcore topic or more a symfony topic?
Definitely a Pimcore topic, Pimcore decided to load configs in a way that is not default to symfony.
In my case, it is fixable. I just need to add documentation on how to handle it. But I don't think it is ideal to not allow dynamic parameters to be used in Pimcore Configs. Like if you wanna use it for routes or maybe even image thumbnail definitions. there are lots of use cases for that.
Probably caused by #14749 
I'm wondering why this doesn't work, is it maybe a timing issue as other things are getting registered there as well by Symfony itself (`MicroKernelTrait`)? 

Does it maybe help to call `$this->microKernelRegisterContainerConfiguration($loader);` at the end of `registerContainerConfiguration()` method? 🤔 


@brusch Issue is that `resolveEnv´ tries to resolve Container Parameters that are set by other extensions, these extensions haven't been called yet.
@dpfaffenbauer was this really possible with v10? I don't see a change in v11 that would cause this behavior ... 
in v10, pimcore just loads the configs required. in v11, pimcore loads the config based on the storage configuration.
@brusch I can show you in detail if you have some time this week
I was just trying to reproduce the above example and for me it works well. 
What I did: 

```yaml
# file: config/local/foo.yaml
pimcore:
    security:
        password_hasher_factories:
            '%bernie.test.foo%': pimcore_admin.security.password_hasher_factory
``` 

```php
# file: \Pimcore\Bundle\BernieBundle\DependencyInjection\PimcoreBernieExtension
final class PimcoreBernieExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container): void
    {
        $container->setParameter('bernie.test.foo', 'bla.blupp.foo');
     }
}
```

So that works well for me without any issues. 
It stops working as soon as the priority of `PimcoreBernieBundle` is less or equal `60`, which is the priority of `PimcoreCoreBundle` which of course needs to be loaded after `PimcoreBernieBundle`. 

alrighty, it was the priority. When I load the CoreShopCoreBundle with 100, it works. Thanks @brusch 
@dpfaffenbauer you're welcome - thanks for the feedback 👍😊 
@dpfaffenbauer @brusch  does this not hint at the default bundle priority needing to be changed? :thinking: Ideally, the bundles the user loads into Pimcore should work without needing a special priority, or maybe I misunderstood the issue.
The problem exist from version `10.6.0` on. The version `10.5.23` does nat have this issue.

@dpfaffenbauer How do i set the priority correctly? Since Pimcore 11.x the `extensions.php` does not exists anymore and the `bundles.php` has no feature for priority. And when i add the Bundle via the `Kernel.php` i get different errors (see below). Do i missunderstand something completely?

```
Compile Error: Type of CoreShop\Bundle\OrderBundle\Controller\OrderController::$serializer must be Symfony\Component\Serializer\SerializerInterface (as in class Pimcore\Bundle\AdminBundle\Controller\AdminController)
```
@lukadschaak confirmed, I'm getting the same errors on 10.6 with latest Coreshop, but it works on 10.5. 

@brusch 
> It stops working as soon as the priority of PimcoreBernieBundle is less or equal 60, which is the priority of PimcoreCoreBundle which of course needs to be loaded after PimcoreBernieBundle.

Would 60 be a magic number of sorts here? Since the default priority is 0, shouldn't PimcoreCoreBundle be below that to come after by default? It seems like it would work in more cases by default.
```
Type of CoreShop\Bundle\OrderBundle\Controller\OrderController::$serializer must be Symfony\Component\Serializer\SerializerInterface (as in class Pimcore\Bundle\AdminBundle\Controller\AdminController)
```

This is due to Pimcore 10.6 introducing the serializer via `\Pimcore\Controller\Traits\JsonHelperTrait`, but Coreshop already has it defined and with a different type. /cc @dpfaffenbauer can you confirm?
@dkarlovi can you please create a new ticket for that? 
Regarding your question: to be honest I'm not sure about the priority of `60` and whether it has a reason or not, that needs to be checked. 
@dkarlovi nevermind, I can reopen this ticket 😊 
@brusch The priority was set [here](https://github.com/pimcore/pimcore/pull/1464/files#diff-c70540acf50b9f0bf7f1bc96fdb0449aded2f10d50c042ac133cd090570f185eR189) and can't find any reference to why the priority was set to 60. Should we change it to negative as suggested by @dkarlovi to load custom bundles first?  
@lukadschaak @dkarlovi I have the same issues with 10.6 and 11.0. I fixed it by manually adding CoreShopCoreBundle in Kernel.php and having it a priority of 100. Regarding bundles.php, you have to have the right order in there for it to work. Other issues I found with 10.6 have been fixed here: https://github.com/coreshop/CoreShop/pull/2285
I think there is some weird corner case where the order in bundles.php is not kept, I've been debugging it once and gave up after a while. 😃
well, Pimcore mix and matches the Kernel.php, extensions.php (<= Pimcore 10) and bundles.php with statically configured dependencies with other priorities as well. CoreShop uses this quite a lot to enable all needed bundles. that is quite a nightmare to figure out when which bundle actually gets loaded.
@dvesh3 I'm fine with changing the priority (don't see that it could break something if we lower the prio) ... probably `60` is a leftover from earlier times ... 🤔
Ideally, we should try to see if it's possible to use the order in bundles.php and ensure it works without surprises in the majority of cases, not requiring custom priority set per bundle. This would make the experience frictionless.
Fixed by #15270

Fix patch:
diff --git a/lib/Kernel.php b/lib/Kernel.php
index 1d5bd370f60..d35d4dcec8a 100644
--- a/lib/Kernel.php
+++ b/lib/Kernel.php
@@ -447,7 +447,7 @@ protected function registerCoreBundlesToCollection(BundleCollection $collection)
         $collection->addBundles([
             new PimcoreCoreBundle(),
             new PimcoreAdminBundle(),
-        ], -10);
+        ], 60);
 
         // load development bundles only in matching environments
         if (in_array($this->getEnvironment(), $this->getEnvironmentsForDevBundles(), true)) {


Test patch: