Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dict dot #517

Merged
merged 5 commits into from
Jan 5, 2019
Merged

Add dict dot #517

merged 5 commits into from
Jan 5, 2019

Conversation

josephmancuso
Copy link
Member

@josephmancuso josephmancuso commented Jan 5, 2019

This PR adds a new feature called the config helper.

This config helper allows you to fetch configuration values from your application using dot notation rather than importing and fetching information.

To use this helper you will need to import it like so:

from masonite.helpers import config

and then use it in a controller to fetch any values from your config. Take this example where you want to check if your application is in debug mode:

from masonite.helpers import config

def show(self):
    if config('config.application.debug'): #== True
        # do something

Notice this is case insensitive. It will look for both config.application.DEBUG as well as the lowercase version.

but whats even cooler is we can actually go an unlimited amount of layers deep into a dictionary:

lets say we have a config like this:

# config/storage.py

DRIVERS = {
    's3': {
        'locations': {
             'west': 'https://west.amazon.com/...',
             'east': 'https://east.amazon.com/...',
         }
    }
}
from masonite.helpers import config

def show(self):
    if config('config.storage.drivers.s3.locations.west'): #== 'https://west.amazon.com/...'
        # do something

We can also set a default value if none exists:

from masonite.helpers import config

def show(self):
    if config('config.storage.drivers.s3.locations.north', 'http://north.amazon.com/...'):
        # do something

@coveralls
Copy link

coveralls commented Jan 5, 2019

Coverage Status

Coverage increased (+0.05%) to 89.791% when pulling e3ea966 on add-dict-dot into 043bc11 on master.

@josephmancuso josephmancuso merged commit bbda5a0 into master Jan 5, 2019
@josephmancuso josephmancuso mentioned this pull request Jan 9, 2019
4 tasks
@josephmancuso josephmancuso deleted the add-dict-dot branch January 10, 2019 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants