|
| 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. |
0 commit comments