Skip to content

Add a cache: constructor argument to Client and CallbackHandler - #16

Merged
loevgaard merged 1 commit into
1.xfrom
dx/cache-arg
Aug 17, 2026
Merged

Add a cache: constructor argument to Client and CallbackHandler#16
loevgaard merged 1 commit into
1.xfrom
dx/cache-arg

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Part of #10 (finding 7).

Why

Wiring a Valinor cache — the recommended production setup — meant building your own MapperBuilder/NormalizerBuilder and remembering to run them through Client::configureMapperBuilder() / registerNormalizerTransformers(). Forgetting that compiles fine and fails at runtime (dates don't map, superfluous keys throw). That's a footgun on the happy path.

What

  • Client::__construct(..., ?Cache $cache = null) — applied to the SDK's default mapper and normalizer builders. Ignored for a builder passed explicitly (those are used as given, exactly as before), which the docblock spells out.
  • CallbackHandler::__construct(string $privateKey, ?MapperBuilder $mapperBuilder = null, ?Cache $cache = null) — same idea for the callback side.
  • Client::defaultMapperBuilder(?Cache) / defaultNormalizerBuilder(?Cache) are now public (the callback side uses the former; also handy for consumers who map raw arrays themselves).
  • README "Production usage" now leads with the two-liner and explains when (and how) to pass a builder instead.
$cache = new FileSystemCache(__DIR__ . '/var/cache/valinor');
$client = new Client('YOUR_API_KEY', cache: $cache);
$handler = new CallbackHandler('YOUR_PRIVATE_KEY', cache: $cache);

Purely additive (new optional trailing parameters). Tests: the cache directory is populated through both mapping and normalizing on the client and through the handler; the default builders map the SDK's date formats and strip nulls with and without a cache. (QuickpayTestCase gains tempDir()/removeDir() helpers.)

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.03%. Comparing base (fece712) to head (8e22262).

Additional details and impacted files
@@             Coverage Diff              @@
##                1.x      #16      +/-   ##
============================================
+ Coverage     99.02%   99.03%   +0.01%     
- Complexity      190      192       +2     
============================================
  Files            26       26              
  Lines           511      517       +6     
============================================
+ Hits            506      512       +6     
  Misses            5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Wiring a Valinor cache meant building your own MapperBuilder/NormalizerBuilder
AND remembering to run them through Client::configureMapperBuilder() /
registerNormalizerTransformers(). Forgetting that compiles fine and fails at
runtime (dates, superfluous keys) — a footgun for the most common production
setup.

- Client::__construct(..., ?Cache $cache = null): applied to the SDK's default
  mapper and normalizer builders (ignored for a builder passed explicitly —
  those are used as given, as before).
- CallbackHandler::__construct($privateKey, ?$mapperBuilder, ?Cache $cache).
- Client::defaultMapperBuilder(?Cache) / defaultNormalizerBuilder(?Cache) are
  now public (the callback side uses the former).
- README "Production usage" leads with `cache:` and explains when to pass a
  builder instead.

Refs #10 (finding 7).
@loevgaard
loevgaard merged commit 9fbc5a3 into 1.x Aug 17, 2026
35 checks passed
@loevgaard
loevgaard deleted the dx/cache-arg branch August 17, 2026 11:13
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.

1 participant