English
Getting started v1.0.1
Overview of DevCraft Dev Tools, architecture, requirements, and first steps.
Package devcraftclub/dev-tools is a PHP 8.3 library with two complementary capabilities:
- Fluent mutation and accessors —
#[With]/#[WithItem],#[Getter]/#[Setter](lombok-php),AbstractWith. - DTO mapping —
AbstractReflection, array hydration, attribute validation,toArray()/toJson().
These base classes use different property models and are not meant to be combined through inheritance.
Architecture
Fluent API DTO Mapping
─────────── ───────────
#[With] / #[WithItem] public typed properties
#[Getter] / #[Setter] (lombok-php) │
│ ▼
▼ AbstractReflection
AbstractWith ──__call──► WithHandler │
│ (with* first) ▼
└──parent──► Lombok\Helper ReflectionMapper
(get* / set* / is*) │
▼
PropertyValidator
│
Filter / Range / Regex / ArrayOfDocumentation sections
Installation
Packagist and path repository
With attributes
Fluent builders and WithHandler
Getters and setters
lombok-php accessors on AbstractWith
Reflection mapper
DTO hydration and serialization
Validation
Filter, Range, Regex, ArrayOf
API reference
Classes, methods, and types
Changelog
Release history
Quick start
use Lombok\Getter;
use Devcraft\Abstracts\AbstractWith;
use Devcraft\Attributes\With;
use Devcraft\Attributes\WithItem;
#[Getter]
final class Query extends AbstractWith
{
#[With]
private ?int $page = null;
#[With, WithItem('string')]
private array $tags = [];
#[WithItem('string', ['string', 'null'])]
private array $labels = [];
}
$query = (new Query())
->withPage(1)
->withTagsItem('proxy')
->withLabelsItem('status', 'ready');
$query->getPage(); // 1
$query->getTags(); // ['proxy']
$query->getLabels(); // ['status' => 'ready']DTO mapping:
use Devcraft\Abstracts\AbstractReflection;
use Devcraft\Attributes\ArrayOf;
use Devcraft\Attributes\Range;
use Devcraft\Attributes\Regex;
final class Address extends AbstractReflection
{
public string $city;
}
final class Proxy extends AbstractReflection
{
#[Regex('/^[0-9a-f-]{36}$/i')]
public string $id;
#[Range(min: 1, max: 65535)]
public int $port;
public Address $address;
#[ArrayOf(Address::class)]
public array $locations = [];
}
$proxy = Proxy::fromArray([
'id' => '550e8400-e29b-41d4-a716-446655440000',
'port' => '8080',
'address' => ['city' => 'Berlin'],
'locations' => [
['city' => 'Berlin'],
['city' => 'Paris'],
],
]);
$proxy->port; // int 8080 (string coerced)
$proxy->address->city; // 'Berlin'
$proxy->toArray(); // nested arrays
echo $proxy->toJson(); // pretty-printed JSONChoosing a base class
| Need | Extend | Property style |
|---|---|---|
Fluent with* / query objects, plus get* / set* | AbstractWith | Private (or protected), non-static, non-readonly |
| API response / request DTO | AbstractReflection | Public, typed, hydratable |
Do not combine them through inheritance. If you need both shapes, use composition or two separate classes.
Requirements
- PHP 8.3 or newer
- Composer
- Transitive runtime:
marcin-orlowski/lombok-php^1.2(installed with the package)