Skip to content

Commit ad08887

Browse files
committed
4.11 app-type config files, remove mention of custom config
1 parent 29a24a1 commit ad08887

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

docs/4.x/config/README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Each setting accepts specific [types and values](#types-and-values) (like an int
9292
Craft takes the first discovered value, in this order:
9393

9494
0. **Environment Overrides:** For general and database settings, Craft looks for special [environment variables](#environment-overrides) and [PHP constants](#php-constants).
95-
1. **Config Files:** Craft [evaluates and merges](#multi-environment-configs) PHP config files.
95+
1. **Config Files:** Craft evaluates and merges [multi-environment](#multi-environment-configs) and [application type](#application-types) PHP config files.
9696
2. **Defaults:** Every option has a default value, even if it’s `null`. You can find these defaults in the documentation for each setting.
9797

9898
### Style: Map vs. Fluent
@@ -122,7 +122,77 @@ return GeneralConfig::create()
122122
Each option becomes a method call, accepting the same values that you would provide in a config map. The modified configuration object is returned to allow chaining.
123123

124124
::: warning
125-
Fluent config is currently only available for _general_ and _database_ settings, and unsupported in plugins. When in doubt, use a config map!
125+
Fluent config is currently only available for _general_ and _database_ settings, and unsupported in plugins, [custom](#custom-settings) config files, and [application config](#application-configuration). When in doubt, use a config map!
126+
:::
127+
128+
Config files can also return a closure that accepts a single `$config` argument and returns a config object. <Since ver="4.11.0" feature="Closures in config files" />
129+
130+
```php
131+
// config/general.php
132+
133+
use craft\config\GeneralConfig;
134+
135+
return function(GeneralConfig $config) {
136+
return $config
137+
->aliases([
138+
'@webroot' => dirname(__DIR__) . '/web',
139+
])
140+
// ...
141+
;
142+
};
143+
```
144+
145+
Craft will always pass an instance of <craft5:craft\config\GeneralConfig> or <craft5:craft\config\DbConfig> to a closure in the primary general or database config files, respectively—but [application type-specific files](#application-types) should accept whatever the _primary_ file returns:
146+
147+
::: code
148+
```php general.php
149+
return [
150+
'aliases' => [
151+
'@webroot' => dirname(__DIR__) . '/web',
152+
],
153+
];
154+
```
155+
```php general.console.php
156+
return function(array $config) {
157+
$config['aliases']['@web'] = App::env('CLI_WEB_URL');
158+
159+
return $config;
160+
};
161+
```
162+
:::
163+
164+
There is no equivalent to `GeneralConfig` and `DbConfig` for [application](#application-configuration). If you return an array from the primary file, there is limited value in using a closure in an application type-specific file.
165+
166+
::: tip
167+
The `GeneralConfig` class has a special `addAlias()` method that allows you to merge additional aliases, when using closures _and_ fluent config.
168+
:::
169+
170+
### Application Types <Since ver="4.11.0" feature="Application type-specific config files" />
171+
172+
Craft has two primary application types—_web_ and _console_. Web requests are typically initiated by an HTTP server via `index.php`; console requests are initiated from the `craft` executable, on the command line.
173+
174+
You can provide configuration that targets a specific application type by creating additional general, database, application, or custom configuration files with the appropriate suffix:
175+
176+
<div class="croker-table">
177+
178+
Category | File | Application Type
179+
--- | --- | ---
180+
[General](#general) | `general.php` | All
181+
&nbsp; | `general.web.php` | Web only
182+
&nbsp; | `general.console.php` | Console only
183+
[Database](#database) | `db.php` | All
184+
&nbsp; | `db.web.php` | Web only
185+
&nbsp; | `db.console.php` | Console only
186+
[Application](#application-configuration) | `app.php` | All
187+
&nbsp; | `app.web.php` | Web only
188+
&nbsp; | `app.console.php` | Console only
189+
190+
</div>
191+
192+
The primary config file is always evaluated, but only one of the `web` or `console` files are merged on top of it, when present.
193+
194+
::: tip
195+
See the previous section for some examples of how to combine application type-specific configuration and config styles.
126196
:::
127197

128198
### Types and Values

docs/5.x/configure.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ return function(array $config) {
166166
```
167167
:::
168168

169-
There is no equivalent to `GeneralConfig` and `DbConfig` for [application](#application-configuration) or [custom](#custom-settings) config files. If you return an array from the primary file, there is limited value in using a closure in an application type-specific file.
169+
There is no equivalent to `GeneralConfig` and `DbConfig` for [application](#application-configuration). If you return an array from the primary file, there is limited value in using a closure in an application type-specific file.
170170

171171
::: tip
172172
The `GeneralConfig` class has a special `addAlias()` method that allows you to merge additional aliases, when using closures _and_ fluent config.
@@ -176,7 +176,7 @@ The `GeneralConfig` class has a special `addAlias()` method that allows you to m
176176

177177
Craft has two primary application types—_web_ and _console_. Web requests are typically initiated by an HTTP server via `index.php`; console requests are initiated from the `craft` executable, on the command line.
178178

179-
You can provide configuration that targets a specific application type by creating additional general, database, application, or custom configuration files with the appropriate suffix:
179+
You can provide configuration that targets a specific application type by creating additional general, database, or application configuration files with the appropriate suffix:
180180

181181
<div class="croker-table">
182182

@@ -191,16 +191,13 @@ Category | File | Application Type
191191
[Application](#application-configuration) | `app.php` | All
192192
&nbsp; | `app.web.php` | Web only
193193
&nbsp; | `app.console.php` | Console only
194-
[Custom](#custom-settings) | `custom.php` | All
195-
&nbsp; | `custom.web.php` | Web only
196-
&nbsp; | `custom.console.php` | Console only
197194

198195
</div>
199196

200197
The primary config file is always evaluated, but only one of the `web` or `console` files are merged on top of it, when present.
201198

202199
::: tip
203-
See the previous section for some examples of how to combine application type-specific configuration and config styles. General and database config files support [fluent](#style) config, but application and custom config files do not.
200+
See the previous section for some examples of how to combine application type-specific configuration and config styles.
204201
:::
205202

206203
### Types and Values

0 commit comments

Comments
 (0)