theorchard / monolog-cascade

Configure multiple loggers and handlers in the blink of an eye
MIT License
145 stars 62 forks source link

merging configs #51

Open glensc opened 8 years ago

glensc commented 8 years ago

hi

i would like to have "dist" config and "local" configs, so most of the things, like declaring formatters, processors, handlers are done in "dist" file and loggers from "local" file

from current code reading i see Cascade::fileConfig would just overwrite self::$config, so no merging there.

rantonmattei commented 8 years ago

What would you want? Being able to call it twice and have the 2 configs merged?

I would probably add a method to load the config array into the Config object without configuring it (i.e. parse and interpret).

    /**
     * Load configuration options from a file or a string without configuring Cascade
     *
     * @param string $resource path to config file or string or array
     */
    public static function loadConfig($resource)
    {
        self::$config = new Config($resource, new ConfigLoader());
        self::$config->load();
    }

And then call it one or more times:

Cascade::loadConfig('./my/first_config.yml');
Cascade::loadConfig('./my/second_config.yml');

Cascade::getConfig()->configure();

You would also need to add an array_merge the in the load method of the Config class.

rantonmattei commented 8 years ago

The alternative would be to do the merging offline before you even use Cascade. You read your config files merge them into an array using array_merge and then call Cascade::fileConfig($yourMergedArray)

glensc commented 8 years ago

yup. i already went with the array way. but for future would be good if cascade supported this out of the box. symfony does so ;)