Skip to main content
Version: 4.x

Application Configuration

Introduction​

All of BowPHP's configuration files are stored in the config folder. Every option is documented, so feel free to browse the files and familiarize yourself with the options available to you.

Configuration​

You can access and modify the configuration with the config helper. Values are accessed through a dot notation system (Dot notation).

Retrieving a value:

echo config('app.public_path')

Modifying a value:

config('view.engine', 'twig');
config('view.extension', '.twig');

Explanation of dot notation​

In dot notation, the part before the first dot represents the file name, and all the values that follow represent keys or values of the configuration array.

Imagine we have an array defined as follows, located in a file named bow.php:

return [
'name' => 'Bow',
'skill' => [
'level' => 'easiest',
'orm' => true,
'preset' => [
'reactjs', 'vue'
]
]
];

With config we are going to see how to access these values.

config('bow.name'); // Bow
config('bow'); // Returns the entire array
config('bow.skill.orm') // true
config('bow.skill.preset.0') // reactjs

Notice that the first part is the name of the file that contains the configuration, here bow.

The .env.json file​

It is often desirable to have different configuration values depending on the environment in which your application is running. For example, you might want to enable debug logs in development but not in production.

For this, Bow uses the .env.json file, in which the information about your application's configuration is defined in JSON format. It is also the ideal place to define sensitive information such as an access key to a service.

Your .env.json file should not be under version control, because each developer/server using your application may require a different environment configuration. Furthermore, it would also pose a security risk if an intruder gained access to your source code repository, because all the sensitive credentials would be exposed.

The .env.example.json file serves as a basis for creating the .env.json file.

Retrieving values​

All the variables listed in the .env.json file are loaded when your application receives a request. However, you can use the app_env helper to retrieve the values of these variables in the configuration files. In fact, if you examine Bow's configuration files, you will notice several options already using this helper:

'database' => app_env('MYSQL_DATABASE'),

In the case where the variable is not defined, app_env will return null, or you can pass a second parameter to app_env which will be the default value if the value is not found.

'database' => app_env('MYSQL_DATABASE', 'localhost'),

Helpers​

Bow includes a variety of global PHP "helper" functions. Many of these functions are used by the Framework itself; however, you are free to use them in your own applications if you find them convenient.

Note that in the config/helpers.php file there are also helpers, but these are not used in the Framework. You can also define your own helpers in this file.

Is something missing?

If you run into problems with the documentation or have suggestions to improve the documentation or the project in general, please open an issue for us, or send a tweet mentioning the Twitter account @bowframework or directly on github.