mtymek / expressive-config-manager

Lightweight library for merging and caching application config
30 stars 4 forks source link

Integration with service-provider #15

Closed weierophinney closed 7 years ago

weierophinney commented 8 years ago

I'm investigating service-provider, which is being developed as part of the PSR-11 initiative around container interoperability. It's looking like some form of this project will be what is proposed to FIG.

The basic idea is that a service provider returns a list of services, pointing to their factories. Each factory expects a container, and optionally a callback returning the instance generated by a previous factory (in zend-servicemanager terms, every factory has the potential of being a delegator factory).

I've created a project for seeding a zend-servicemanager instance from providers: phly/zend-servicemanager-interop. It has two classes, one that aggregates providers, and another that uses providers to inject a service manager instance.

I've been doing some brainstorming, and propose that the config manager check for service-providers.

In pseudo-logic, this would look something like:

if (is_callable($provider)) {
    // grab configuration to merge, or skip if we already cached it
}
if ($provider instanceof ServiceProvider) {
    // push into provider aggregate
}

The ConfigManager would then also expose a new method, getServiceProviders(), which would return the provider aggregate. We can then use that to seed containers.

For this to work, config/config.php would now return the ConfigManager instance, and not the merged config. We would grab the merged configuration when injecting our container with the config service.

// config/container.php

// build our $container

$configManager = include __DIR__ . '/config.php';
$container->setService('config', $configManager->getMergedConfig());

// grab service providers and inject:
return (new ConfigInjector())->inject($configManager->getServiceProviders(), $container);

So, the proposed path is:

Thoughts?

mtymek commented 8 years ago

Initial, proof-of-concept support is added here: #16 (with service provider caching).

I have a few issues with approach you proposed, main being complexity of ProviderAggregate class. What about updating ConfigManager to iterate over service providers and returning flattened array? It is more in line with my initial ideas for this library (process objects to produce simple array). This would also simplify loading cache (single include vs include and unserialize). ContainerInjector could then consume that flattened array directly. What do you think?

mtymek commented 7 years ago

Closing - this package is now replaced by zend-config-aggregator.