Documentation Index
Fetch the complete documentation index at: https://docs.apivalk.com/llms.txt
Use this file to discover all available pages before exploring further.
The Problem
In Apivalk, request data is populated into bags. While you can access data using$request->getBody()->get('name'), the framework also supports magic getters like $request->name. Without extra metadata, IDEs (like PhpStorm) won’t know that name exists or what type it is.
The Solution: Automated DocBlocks
TheDocBlockGenerator automates the creation of this metadata. It performs the following steps for every Request class in your project:
- Discovery: Scans your API directories for classes extending
AbstractApivalkController. - Extraction: Executes the
getRequestClass()andgetRoute()methods on the Controller to find the associated Request class and its properties. - Shape Generation: Creates “Shape” classes (e.g.,
GetUserBodyShape,GetUserSortingShape,GetUserFilteringShape) in aShape/subdirectory. These classes contain public properties representing your documentation and route-defined sorting/filtering. - Rewrite: Updates the original Request class file with
@methodtags pointing to these Shape classes.
Example Result
Before running the generator, your Request class might look like this:DocBlockGenerator, it is automatically updated to:
$request->body()-> and your IDE will suggest all defined properties with their correct types.
How to Run
You can trigger the generation process from your bootstrap or a CLI tool:Components
DocBlockGenerator: The main entry point that iterates over classes.DocBlockRequestGenerator: Converts anAbstractApivalkRequestinto aDocBlockRequestdata object.DocBlockRequest: Holds the metadata for the shapes (Body, Query, Path, Sorting, Filtering).DocBlockShape: Generates the PHP code for the Shape classes.DocBlockResourceGenerator/DocBlockResource: Generates@propertyannotations forAbstractResourcesubclasses so you get IDE autocompletion on$resource->name,$resource->status, etc.DocBlockResourceRequestGenerator/DocBlockResourceRequest: For eachAbstractListResourceController, generates a typed per-resource list request (e.g.AnimalListRequest) with@methodannotations forsorting(),filtering(), andpaginator()wired to shape interfaces derived from the resource’savailableSortings()/availableFilters().
Resource DocBlock Generation
WhenDocBlockGenerator encounters an AbstractResourceController subclass, it produces two extra artifacts:
- Resource
@propertydocblock — written once per resource class so that$animal->name,$animal->type, etc. autocomplete in your IDE. - Per-resource list request — for each
AbstractListResourceController, a typed request class (e.g.Api/v1/Animal/Request/AnimalListRequest.php) with@methodannotations pointing at generated sorting/filtering shape interfaces. If the file already exists, only the docblock is updated — your class body is preserved.
$request->sorting()->status, $request->filtering()->createdAt, and $request->paginator() without writing the boilerplate yourself.