Skip to content

Commit c3968a2

Browse files
committed
improved configuration loader
1 parent cfef9f7 commit c3968a2

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

.semver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
:major: 8
33
:minor: 0
4-
:patch: 13
4+
:patch: 14
55
:special: ''

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Versions and branches
1515

1616
| CakePHP | CakeDC Api Plugin | Tag | Notes |
1717
| :-------------: | :------------------------: | :--: | :---- |
18-
| 4.0 | [8.x](https://github.com/cakedc/cakephp-api/tree/8.x) | 8.0.13 | unstable |
18+
| 4.0 | [8.x](https://github.com/cakedc/cakephp-api/tree/8.x) | 8.0.14 | unstable |
1919
| ^3.7 | [master](https://github.com/cakedc/cakephp-api/tree/master) | 7.0.0 | stable |
2020
| ^3.7 <4.0 | [7.x](https://github.com/cakedc/cakephp-api/tree/7.x) | 7.1.0 | stable |
2121
| 3.6 | [6.x](https://github.com/cakedc/cakephp-api/tree/6.x) | 6.0.1 | stable |

config/bootstrap.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
use Cake\Log\Log;
1414

1515
Configure::load('CakeDC/Api.api');
16-
collection((array)Configure::read('Api.config'))->each(function ($file) {
17-
Configure::load($file);
16+
collection((array)Configure::read('Api.config'))->each(function ($merge, $file) {
17+
if (is_int($file)) {
18+
$file = $merge;
19+
$merge = true;
20+
}
21+
Configure::load($file, 'default', $merge);
1822
});
1923

2024
if (!Log::engine('api')) {

docs/Documentation/installation.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,50 @@ Plugin::load('CakeDC/Api', ['bootstrap' => true, 'routes' => true]);
2121

2222
## Configuration
2323
You can configure the api overwriting the api.php, how?
24-
we need to create an **api.php** file in the *config* folder. You can copy the existing configuration file
24+
we need to create an **api.php** file in the *config* folder. You can copy the existing configuration file
2525
under `vendor/cakedc/cakephp-api/config/api.php` and customize it for your application.
2626
Remember to load the new configuration file in `bootstrap.php`
2727

2828
```php
2929
Plugin::load('CakeDC/Api', ['bootstrap' => false, 'routes' => true]);
3030
Configure::load('api');
31-
```
31+
```
32+
33+
CakePHP 4.x configuration loading form Application class:
34+
35+
```php
36+
Configure::write('Api.config', ['api']);
37+
$this->addPlugin('CakeDC/Api', ['bootstrap' => true, 'routes' => true]);
38+
```
39+
In this case plugin will load default configuration file from CakeDC/Api/config/api.php
40+
and after that append the configuration from ./config/api.php
41+
42+
If needed to overwrite one of sections in the default confugration file it is possible to pass
43+
config names as key and merge param as value of `Api.config` settings.
44+
45+
Example, if we want merge api.php and overwrite specific node like Api.Middleware we can create addtional configuration file config/api_mw.php
46+
```php
47+
return [
48+
'Api.Middleware' => [
49+
// ... overwrite section here
50+
]
51+
];
52+
```
53+
And in Application.php we will have
54+
```php
55+
Configure::write('Api.config', ['api' => true, 'api_mw' => false]);
56+
$this->addPlugin('CakeDC/Api', ['bootstrap' => true, 'routes' => true]);
57+
```
3258

3359
## OPTIONAL: User Plugin
3460

35-
We rely on CakeDC/Users plugin for Auth, in case you need to define Auth for your API,
61+
We rely on CakeDC/Users plugin for Auth, in case you need to define Auth for your API,
3662
ensure *CakeDC/Users* plugin is installed and loaded from your `bootstrap.php`.
3763

3864
### Configuration and Loading
3965

4066
```
4167
Configure::write('Users.config', ['users']);
4268
Plugin::load('CakeDC/Users', ['bootstrap' => false, 'routes' => true]);
43-
```
69+
```
4470
Check more details about how CakeDC/Users plugin could be configured here: https://github.com/CakeDC/users/blob/master/Docs/Documentation/Configuration.md

0 commit comments

Comments
 (0)