Skip to content

Commit b971015

Browse files
committed
update docs
1 parent 0de68b3 commit b971015

3 files changed

Lines changed: 122 additions & 3 deletions

File tree

docs/configuration.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Configuration
2+
3+
To make changes to the config file, you need to have your own copy in `app/Config/Settings.php`. The easiest way to do it is by using the publish command.
4+
5+
When you run:
6+
7+
php spark settings:publish
8+
9+
You will get your copy ready for modifications.
10+
11+
---
12+
13+
## Handlers
14+
15+
An array of handler aliases to use for storing and retrieving settings. Handlers are checked in order, with the first handler that has a value returning it.
16+
17+
**Type:** `array`
18+
19+
**Default:** `['database']`
20+
21+
**Available handlers:** `database`, `file`, `array`
22+
23+
Example:
24+
25+
```php
26+
public $handlers = ['database'];
27+
```
28+
### Multiple handlers
29+
30+
When multiple handlers are configured, they are checked in the order specified in $handlers. The first handler that has a value for the requested setting will return it.
31+
32+
Example with fallback:
33+
34+
```php
35+
public $handlers = ['file', 'database'];
36+
```
37+
This configuration will:
38+
39+
1. Check the file handler first
40+
2. If not found, check the database handler
41+
3. If not found in any handler, return the default value from the config file
42+
43+
### Writeable Handlers
44+
45+
Only handlers marked as `writeable => true` will be used when calling `set()`, `forget()`, or `flush()` methods.
46+
47+
## DatabaseHandler
48+
49+
This handler stores settings in a database table and is production-ready for high-traffic applications.
50+
51+
**Available options:**
52+
53+
* `class` - The handler class. Default: `DatabaseHandler::class`
54+
* `table` - The database table name for storing settings. Default: `'settings'`
55+
* `group` - The database connection group to use. Default: `null` (uses default connection)
56+
* `writeable` - Whether this handler supports write operations. Default: `true`
57+
58+
Example:
59+
60+
```php
61+
public $database = [
62+
'class' => DatabaseHandler::class,
63+
'table' => 'settings',
64+
'group' => null,
65+
'writeable' => true,
66+
];
67+
```
68+
69+
!!! note
70+
You need to run migrations to create the settings table: `php spark migrate -n CodeIgniter\\Settings`
71+
72+
---
73+
74+
## FileHandler
75+
76+
This handler stores settings as PHP files and is optimized for production use with built-in race condition protection.
77+
78+
**Available options:**
79+
80+
* `class` - The handler class. Default: `FileHandler::class`
81+
* `path` - The directory path where settings files are stored. Default: `WRITEPATH . 'settings'`
82+
* `writeable` - Whether this handler supports write operations. Default: `true`
83+
84+
Example:
85+
86+
```php
87+
public $file = [
88+
'class' => FileHandler::class,
89+
'path' => WRITEPATH . 'settings',
90+
'writeable' => true,
91+
];
92+
```
93+
94+
!!! note
95+
The `FileHandler` automatically creates the directory if it doesn't exist and checks write permissions on instantiation.
96+
97+
---
98+
99+
## ArrayHandler
100+
101+
This handler stores settings in memory only and is primarily useful for testing or as a parent class for other handlers.
102+
103+
**Available options:**
104+
105+
* `class` - The handler class. Default: `ArrayHandler::class`
106+
* `writeable` - Whether this handler supports write operations. Default: `true`
107+
108+
Example:
109+
110+
```php
111+
public $array = [
112+
'class' => ArrayHandler::class,
113+
'writeable' => true,
114+
];
115+
```
116+
117+
!!! note
118+
`ArrayHandler` does not persist data between requests. It's mainly used for testing or extended by other handlers.

docs/limitations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The following are known limitations of the library:
44

5-
1. You can currently only store a single setting at a time. While the `DatabaseHandler` uses a local cache to
6-
keep performance as high as possible for reads, writes must be done one at a time.
5+
1. You can currently only store a single setting at a time. While the `DatabaseHandler` and `FileHandler`
6+
uses a local cache to keep performance as high as possible for reads, writes must be done one at a time.
77
2. You can only access the first level within a property directly. In most config classes this is a non-issue,
88
since the properties are simple values. Some config files, like the `database` file, contain properties that
99
are arrays.

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extra:
5353
site_url: https://settings.codeigniter.com/
5454
repo_url: https://github.com/codeigniter4/settings
5555
edit_uri: edit/develop/docs/
56-
copyright: Copyright © 2023 CodeIgniter Foundation.
56+
copyright: Copyright © 2025 CodeIgniter Foundation.
5757

5858
markdown_extensions:
5959
- admonition
@@ -73,5 +73,6 @@ extra_javascript:
7373
nav:
7474
- Home: index.md
7575
- Installation: installation.md
76+
- Configuration: configuration.md
7677
- Basic usage: basic-usage.md
7778
- Limitations: limitations.md

0 commit comments

Comments
 (0)