PHPackages                             kaiseki/wp-acf-dto - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kaiseki/wp-acf-dto

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kaiseki/wp-acf-dto
==================

Easily create DTOs from ACF fields

1.0.0(1mo ago)1971MITPHPPHP ^8.2CI passing

Since Jan 28Pushed 3w ago2 watchersCompare

[ Source](https://github.com/kaisekidev/kaiseki-wp-acf-dto)[ Packagist](https://packagist.org/packages/kaiseki/wp-acf-dto)[ Docs](https://github.com/kaisekidev/kaiseki-wp-acf-dto)[ RSS](/packages/kaiseki-wp-acf-dto/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (20)Versions (4)Used By (0)

kaiseki/wp-acf-dto
==================

[](#kaisekiwp-acf-dto)

Easily create DTOs from ACF fields.

Maps Advanced Custom Fields (ACF) data onto typed, immutable [`spatie/laravel-data`](https://github.com/spatie/laravel-data) objects. Define a DTO once, then hydrate it from a post's ACF fields — with casts that turn raw field values into `WP_Post`/`WP_Term`/`WP_User`objects, `DateTimeImmutable`s, validated e-mails/URLs, and nested DTOs.

Installation
------------

[](#installation)

```
composer require kaiseki/wp-acf-dto
```

Requires PHP 8.2 or newer.

Usage
-----

[](#usage)

### Define a DTO

[](#define-a-dto)

Extend the package's `Data` base class (a `spatie/laravel-data` data object with a safe-construction helper) and annotate properties with the bundled casts. Property names map to ACF field names via spatie's name mappers.

```
use DateTimeImmutable;
use Kaiseki\WordPress\ACF\Dto\Casts\DateTimeCast;
use Kaiseki\WordPress\ACF\Dto\Casts\WpPostCast;
use Kaiseki\WordPress\ACF\Dto\Castables\Link;
use Kaiseki\WordPress\ACF\Dto\Data;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
use WP_Post;

#[MapName(SnakeCaseMapper::class)]
class EventData extends Data
{
    public function __construct(
        public readonly ?string $headline,
        #[WithCast(DateTimeCast::class)]
        public readonly ?DateTimeImmutable $startsAt,
        // Resolves an ACF post-object field to a lazy WP_Post wrapper.
        #[WithCast(WpPostCast::class, postType: 'page')]
        public readonly ?WP_Post $relatedPage,
        // Nested DTO: an ACF link field becomes a Link data object.
        public readonly ?Link $cta,
    ) {
    }
}
```

### Build a DTO from a post's ACF fields

[](#build-a-dto-from-a-posts-acf-fields)

`AcfDataBuilder` reads every field for a post (via ACF's `get_fields()`), merges in any defaults, and constructs the DTO:

```
use Kaiseki\WordPress\ACF\Dto\AcfDataBuilder;
use Kaiseki\WordPress\ACF\Dto\AcfGetFields;

$builder = new AcfDataBuilder(new AcfGetFields());

$event = $builder->create(
    EventData::class,
    postId: get_the_ID(),
    defaults: ['headline' => 'Untitled'],
);
```

To swallow construction errors (e.g. validation failures) and get `null` instead of an exception, use the trait's `safeFrom()`:

```
$event = EventData::safeFrom(get_fields());
```

### Read single fields with type safety

[](#read-single-fields-with-type-safety)

`AcfFieldValue` wraps `get_field()` with a typed accessor per return type, narrowing ACF's loose return values to the declared PHP type (or `null`):

```
use Kaiseki\WordPress\ACF\Dto\AcfFieldValue;

$field = new AcfFieldValue();

$title    = $field->string('headline');           // ?string
$count    = $field->int('seats');                 // ?int
$starts   = $field->dateTime('starts_at');        // ?DateTimeImmutable
$ids      = $field->idList('related_posts');      // list
$author   = $field->wpUser('author');             // ?WpUser
$link     = $field->link('cta');                  // ?Link
```

### Register the spatie/laravel-data config

[](#register-the-spatielaravel-data-config)

`ConfigProvider` returns the package's `spatie/laravel-data` configuration (date format, casts, transformers, normalizers) for laminas-style config aggregators:

```
use Kaiseki\WordPress\ACF\Dto\ConfigProvider;

$config = (new ConfigProvider())();
```

Development
-----------

[](#development)

```
composer install
composer check   # check-deps, cs-check, phpstan
```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c3a6b11aea9668c9e9ca0c0f8515ef114d344acb552c695d715d35d5b388ea4?d=identicon)[woda](/maintainers/woda)

---

Top Contributors

[![davidmondok](https://avatars.githubusercontent.com/u/3883758?v=4)](https://github.com/davidmondok "davidmondok (66 commits)")[![wolfgangschaefer](https://avatars.githubusercontent.com/u/26325205?v=4)](https://github.com/wolfgangschaefer "wolfgangschaefer (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kaiseki-wp-acf-dto/health.svg)

```
[![Health](https://phpackages.com/badges/kaiseki-wp-acf-dto/health.svg)](https://phpackages.com/packages/kaiseki-wp-acf-dto)
```

###  Alternatives

[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/container

The Illuminate Container package.

31182.0M2.4k](/packages/illuminate-container)[illuminate/events

The Illuminate Events package.

13557.0M2.1k](/packages/illuminate-events)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
