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
AbstractApivalkRequest. - Extraction: Executes the
getRequestDocumentation()method on the associated Controller to find all defined properties. - Shape Generation: Creates “Shape” classes (e.g.,
GetUserBodyShape) in aShape/subdirectory. These classes contain public properties representing your documentation. - Rewrite: Updates the original Request class file with
@propertytags 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 three shapes (Body, Query, Path).DocBlockShape: Generates the PHP code for the Shape classes.