Skip to main content

Key Responsibilities

  1. Request Matching: Analyzing the incoming HTTP method and URI to find a matching route definition.
  2. Route Discovery: Automatically scanning specified namespaces for controllers and extracting their route definitions.
  3. Path Parameter Extraction: Using regex patterns to identify and capture dynamic parts of the URL (e.g., /user/{id}).
  4. Performance Optimization: Caching the discovered routes to disk to ensure that heavy scanning logic only runs when necessary.

Core Components

  • Router: The main dispatcher that handles the matching logic and produces a response.
  • Route: A data object representing a single API endpoint, including its URL, HTTP method, and metadata.
  • Router Cache: A subsystem responsible for persisting and retrieving route definitions for maximum efficiency.

How it Works

  1. The Router is initialized with a RouterCacheInterface implementation.
  2. During dispatch, the Router retrieves a RouterCacheCollection from the cache.
  3. The Router iterates through the collection, comparing the current request’s URI against the pre-generated regex patterns for each route.
  4. If a match is found, the Router identifies the associated controller and request classes.
  5. The Router then populates the request object and executes the middleware stack.
By combining documentation-driven route definitions with automated discovery and caching, Apivalk provides a powerful routing system that requires minimal manual intervention.