barnythorpe / wp-config-containers
A simple package with auto-generated builder and DTO classes for Wordpress Post Types and Taxonomies.
Requires (Dev)
- barnythorpe/clarify: ^0.1.0
- laravel/pint: ^1.22
- mockery/mockery: ^1.6
- nette/php-generator: ^4.1
- pestphp/pest: ^3.8
- php-stubs/wordpress-stubs: ^6.7
- phpdocumentor/reflection-docblock: ^5.6
- phpdocumentor/type-resolver: ^1.10
- phpstan/phpstan: ^2.1
- roots/wordpress: ^6.7
- ryangjchandler/lexical: ^0.2.1
- symfony/property-access: ^7.2
- symfony/string: ^7.2
- symfony/var-dumper: ^7.2
- twig/string-extra: ^3.20
- twig/twig: ^3.20
This package is auto-updated.
Last update: 2025-05-19 17:32:17 UTC
README
A Composer package for WordPress that provides strongly-typed DTO (Data Transfer Object) classes and Builder classes for various Wordpress configurations such as Post Types and Taxonomies.
This package helps bring structure, clarity, and type safety to WordPress projects by wrapping Post Type and Taxonomy configurations in clean, typed objects with fluent builder interfaces.
đź“– About
This package auto-generates Builder Classes and in some cases DTOs for:
WP_Post_Type
WP_Taxonomy
WP_Block_Type
- Block attributes from https://github.com/WordPress/gutenberg/blob/trunk/schemas/json/block.json
The generators read the DocBlocks of WordPress' native classes and automatically create various classes to help construct the above configurations in a clean and safe manner.
📦 Installation
You’ll need Composer installed.
composer require barnythorpe/wp-config-containers
🚀 Usage
use function Barnythorpe\WpConfigContainers\post_type; $postType = post_type() ->name('my_custom_post') ->public(true) ->build(); $configArray = $postType->toArray();
See the Tests directory for more examples of how to use.
🛠️ Contributing & Developer Notes
If you're working on this package or maintaining it in the future, here’s what you need to know:
The Generator
- Located in:
src/WpConfigContainersGenerator/Generator.php
- Uses:
phpDocumentor
to parse DocBlocks and typesTwig
templates to generate DTO and Builder class files
- Templates:
src/WpConfigContainersGenerator/templates/dto.twig
src/WpConfigContainersGenerator/templates/builder.twig
To run the generator:
php generate.php
How It Works:
- The Generator reflects on the original WordPress classes (
WP_Post_Type
,WP_Taxonomy
). - It parses each property’s
@var
annotation to determine type and description. - Uses
Twig
ornette/php-generator
to generate builder classes with fluent methods for setting those properties - Generated files are written to the
src
directory.
Testing
We use PestPHP for testing.
Tests are located in:
/tests/
Fixtures and test doubles are in:
/tests/Fixtures/
Run tests with:
./vendor/bin/pest
or
composer test