MasoniteFramework / masonite4

Temporary Repository for a Masonite Rewrite for Masonite 4
14 stars 3 forks source link

Update config to be able to merge config from 3rd party packages #148

Closed girardinsamuel closed 3 years ago

girardinsamuel commented 3 years ago

SHOULD BE MERGED ONCE #147 is merged !

In a package service provider we can do:

from masonite.facades import Config

class MyPackageServiceProvider(Provider):

    def register(self):

        Config.merge_with("mypackage", abspath("mypackage/config.py"))
        # or 
        Config.merge_with("mypackage", "masonite.mypackage.config")

The function takes a file path or a module dotted path (whatever) and is loading parameters inside the module. Then it's overriden with eventual config for mypackage found in the project dir.

An exception will be raised if we try to use this for config (application, auth, ...).

Summary

If a Masonite package is installed in your project and the package service provider is using Config.merge_with:

  1. without publishing config file to the project, the package configuration will be accessible at config("mypackage.param").
  2. if the config is published to the project, the package configuration will be accessible at config("mypackage.param") and project parameters will take precedence over package default parameters.

This will be useful for #79.