Skip to content

Add ServerContextInterface for coroutine-safe request handling#172

Merged
koriym merged 1 commit into1.xfrom
coroutine-safe
Feb 2, 2026
Merged

Add ServerContextInterface for coroutine-safe request handling#172
koriym merged 1 commit into1.xfrom
coroutine-safe

Conversation

@koriym
Copy link
Member

@koriym koriym commented Feb 2, 2026

Summary

  • Add ServerContextInterface and GlobalServerContext to abstract $_SERVER access for coroutine-safe environments (Swoole, RoadRunner, ReactPHP)
  • Add RepositoryLoggerInterface with reset() for long-running process support
  • Bind ServerContextInterface in QueryRepositoryModule, use it in ResourceStorage

Test plan

  • Unit tests for GlobalServerContext
  • Unit tests for RepositoryLogger
  • All existing tests pass
  • PHPStan / Psalm clean

@koriym
Copy link
Member Author

koriym commented Feb 2, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

Updates CHANGELOG.md with a new version entry (1.15.0) documenting the introduction of ServerContextInterface for request handling in long-running server environments and the addition of RepositoryLoggerInterface with reset() method support.

Changes

Cohort / File(s) Summary
Changelog Documentation
CHANGELOG.md
Added version 1.15.0 entry documenting new ServerContextInterface, GlobalServerContext implementation, and RepositoryLoggerInterface with reset() method; includes binding change in QueryRepositoryModule and ResourceStorage updates to use ServerContextInterface instead of direct $_SERVER access.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • BEAR.QueryRepository#171: Implements the code-level changes documented in this changelog entry—adding ServerContextInterface and GlobalServerContext, updating ResourceStorage to use the new interface, and introducing RepositoryLoggerInterface.reset() for long-running process support.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding ServerContextInterface for coroutine-safe request handling, which is the primary focus of this PR.
Description check ✅ Passed The description is directly related to the changeset, detailing the new interfaces, their purpose, and the test plan covering the changes made.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch coroutine-safe

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@greptile-apps
Copy link

greptile-apps bot commented Feb 2, 2026

Greptile Overview

Greptile Summary

This PR adds version 1.15.0 release notes to the CHANGELOG documenting the ServerContextInterface feature that enables coroutine-safe request handling in environments like Swoole and RoadRunner.

Key changes documented:

  • ServerContextInterface abstracts $_SERVER access for thread-safe operation
  • GlobalServerContext provides default implementation for traditional PHP-FPM
  • RepositoryLoggerInterface::reset() enables log cleanup in long-running processes
  • ResourceStorage now uses ServerContextInterface instead of direct $_SERVER access

The CHANGELOG entry follows Keep a Changelog format and accurately reflects the implementation from the earlier commits (ff919e8, 31485c2, 82fd020).

Confidence Score: 5/5

  • Safe to merge - CHANGELOG-only update with accurate documentation
  • Score reflects that this is a documentation-only change to CHANGELOG.md with no code modifications, accurately documenting features already implemented and merged
  • No files require special attention

Important Files Changed

Filename Overview
CHANGELOG.md Added version 1.15.0 release notes documenting ServerContextInterface and RepositoryLogger enhancements

Sequence Diagram

sequenceDiagram
    participant Client
    participant CacheInterceptor
    participant ResourceStorage
    participant ServerContext as ServerContextInterface
    participant Cache as TagAwareAdapter
    
    Note over Client,Cache: Traditional PHP-FPM Request (using GlobalServerContext)
    Client->>CacheInterceptor: Resource Request
    CacheInterceptor->>ResourceStorage: get(uri)
    ResourceStorage->>ServerContext: has('X_VARY')
    ServerContext->>$_SERVER: Check $_SERVER['X_VARY']
    $_SERVER-->>ServerContext: true/false
    ServerContext-->>ResourceStorage: boolean
    
    alt X_VARY exists
        ResourceStorage->>ResourceStorage: getVary()
        ResourceStorage->>ServerContext: get('X_VARY')
        ServerContext->>$_SERVER: Read $_SERVER['X_VARY']
        $_SERVER-->>ServerContext: "user_agent,language"
        ServerContext-->>ResourceStorage: "user_agent,language"
        loop For each vary value
            ResourceStorage->>ServerContext: get('X_USER_AGENT')
            ServerContext->>$_SERVER: Read $_SERVER['X_USER_AGENT']
            $_SERVER-->>ServerContext: "Mozilla/5.0..."
            ServerContext-->>ResourceStorage: "Mozilla/5.0..."
        end
        ResourceStorage->>ResourceStorage: Build cache key with vary
    else No X_VARY
        ResourceStorage->>ResourceStorage: Build cache key without vary
    end
    
    ResourceStorage->>Cache: getItem(cacheKey)
    Cache-->>ResourceStorage: ResourceState or null
    ResourceStorage-->>CacheInterceptor: ResourceState or null
    
    Note over Client,Cache: Coroutine Environment (Swoole/RoadRunner)
    Note over ServerContext: Custom implementation uses<br/>request-scoped context instead of $_SERVER
Loading

@koriym koriym merged commit 8e4ab37 into 1.x Feb 2, 2026
11 of 12 checks passed
@koriym koriym deleted the coroutine-safe branch February 2, 2026 16:20
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