Skip to content

feat: add getMany settings API#163

Open
memleakd wants to merge 2 commits intocodeigniter4:developfrom
memleakd:feat/get-many-settings
Open

feat: add getMany settings API#163
memleakd wants to merge 2 commits intocodeigniter4:developfrom
memleakd:feat/get-many-settings

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

@memleakd memleakd commented May 2, 2026

Description
Hello! This PR proposes adding a small getMany() convenience API for retrieving multiple settings in one call:

  • Settings::getMany()

This follows the recently merged batch write APIs from #161, but keeps the read side intentionally simple. The new method behaves like calling get() repeatedly for each requested key, while preserving the requested keys in the returned array.

Why

Applications and modules often need to read a related group of settings together, such as when preparing configuration forms, loading module preferences, or gathering setup values.

With this PR, callers can group those reads directly:

$settings = service('settings')->getMany([
    'App.siteName',
    'App.siteEmail',
]);

This returns:

[
    'App.siteName'  => 'My Great Site',
    'App.siteEmail' => 'support@example.com',
]

Behavior

getMany() follows the same behavior as repeated calls to get():

  • keys use the existing Class.property syntax
  • contexts work the same way
  • context fallback behavior is unchanged
  • config fallback behavior is unchanged
  • missing values return null
  • returned array keys match the requested keys
  • no handler contract changes are required

Scope

This PR does not add handler-level batch read methods or optimized read paths. The existing handlers already cache hydrated data, and keeping this first step at the Settings API level avoids expanding the handler contract unnecessarily.

Tests and Docs

This PR adds tests for stored values, config fallback values, contextual reads, missing values, requested key preservation, and empty input.

The user guide is updated with getMany() examples.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Comment thread docs/basic-usage.md
@michalsn michalsn requested a review from paulbalandan May 4, 2026 19:40
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants