> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/config/usage.md).

# Usage

## Import a normal package config file

This is the common Quantum pattern.

```php
use Quantum\Loader\Setup;

config()->import(new Setup('config', 'mailer'));

$defaultAdapter = config()->get('mailer.default');
$smtpHost = config()->get('mailer.smtp.host');
```

Use `import()` when the file should live under its own top-level section.

## Load one file as the whole root store

```php
use Quantum\Config\Config;
use Quantum\Loader\Setup;

$config = new Config();
$config->load(new Setup('config', 'app'));

$name = $config->get('name');
$debug = $config->get('debug', false);
```

Use this pattern for isolated tasks where one file should define the whole config payload.

## Override values at runtime

You can add or replace values after loading.

```php
config()->set('mailer.smtp.host', 'smtp.internal');
config()->set('feature_flags.beta_checkout', true);
```

This updates the in-memory store only. It does not write back to the PHP config file.

## Remove or reset config

```php
config()->delete('feature_flags.beta_checkout');
config()->flush();
```

Use `flush()` carefully. It clears the whole shared store for the current runtime.

## Prefer one loading style per store

Mixing `load()` and `import()` is allowed, but the resulting key shape changes depending on which method populated the store first.

* after `load(new Setup('config', 'app'))`, keys look like `name` and `debug`
* after `import(new Setup('config', 'app'))`, keys look like `app.name` and `app.debug`

Pick one shape deliberately so the rest of your code reads the expected keys.

## Common pitfalls

### Calling `load()` twice

Later `load()` calls are ignored once the store has been initialized.

If you need a fresh root load, call `flush()` first or create a separate `Config` instance.

### Re-importing the same section name

This fails:

```php
config()->import(new Setup('config', 'app'));
config()->import(new Setup('config', 'app')); // throws
```

Use unique filenames per imported section.

### Assuming runtime changes persist to disk

`set()`, `delete()`, and `flush()` change the in-memory copy only.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/config/usage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
