Getting started v1.1.0
What DevCraft Dev Tools is: capabilities, audience, base-class choice, and quick start.
Package overview
DevCraft Dev Tools (devcraftclub/dev-tools) is a small PHP 8.3 library for common building blocks: chainable with* objects, array-backed DTOs with attribute validation, and a filesystem PSR-6 cache.
You install it with Composer. There is no DLE plugin UI — it lives in vendor and is used from your PHP. In the DevCraft Admin stack it is already a dependency of the admin shell.
Version 1.1.0 adds FileCachePool on top of the existing AbstractWith / AbstractReflection toolkit.
Capabilities
- Chainable
with*writers via#[With]/#[WithItem]onAbstractWith get*/set*/is*via lombok-php (#[Getter]/#[Setter]) on the same base class- DTOs with public typed properties:
fromArray(),toArray(),toJson()onAbstractReflection - Field rules:
Filter,Range,Regex,ArrayOf - PSR-6 file cache:
FileCachePool, slash namespaced keys,clearNamespace()(Dev Tools extension)
Who it is for
Module / service developers — pick a base class (or compose FileCachePool) and write business types. See guides and API reference.
Site owners / panel admins — you install DevCraft Admin; Dev Tools arrives as a Composer dependency. You do not configure this library in the browser.
Why not hand-rolled helpers
Custom setters, ad-hoc array mapping, and one-off file caches diverge across modules. Dev Tools gives one contract for builders, DTOs, and cache. Do not merge AbstractWith and AbstractReflection by inheritance — different property models; use two classes or composition.
Architecture
Цепочки with* DTO из массива Кэш PSR-6
───────────── ────────────── ────────
#[With] / #[WithItem] public-свойства с типами FileCachePool
#[Getter] / #[Setter] (lombok-php) │ │
│ ▼ ▼
▼ AbstractReflection {каталог}/{ключ}.cache
AbstractWith ──__call──► WithHandler │ JSON-запись {e,f,v}
│ (сначала with*) ▼
└──parent──► Lombok\Helper ReflectionMapper
(get* / set* / is*) │
▼
PropertyValidator
│
Filter / Range / Regex / ArrayOfChoosing a base class
| Need | Use | Properties |
|---|---|---|
Query / builder with with* plus get* / set* | extend AbstractWith | private or protected, non-static, non-readonly |
| API DTO from arrays / to JSON | extend AbstractReflection | public, typed |
| Filesystem PSR-6 cache | new FileCachePool(...) | — |
Requirements
- PHP 8.3 or newer
- Composer
- Runtime:
psr/cache^3.0(PSR-6) - Runtime:
marcin-orlowski/lombok-php^1.2(installed with the package)
Quick start
File cache
use Devcraft\Cache\FileCachePool;
$pool = new FileCachePool('/path/to/cache', defaultTtlSeconds: 3600);
$item = $pool->getItem('Translation/dict');
$item->set(['hello' => 'world']);
$pool->save($item);
$hit = $pool->getItem('Translation/dict');
if ($hit->isHit()) {
$value = $hit->get();
}
$pool->clearNamespace('Translation'); // расширение Dev Tools (не из PSR-6)Chainable With
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 from array
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 JSONGuides
| Guide | Topic |
|---|---|
| PSR-6 file cache | Pool, keys, TTL, clearNamespace |
| With attributes | #[With], #[WithItem] |
| Getters and setters | lombok-php on AbstractWith |
| Reflection mapper | fromArray / nested DTOs |
| Validation | Filter, Range, Regex, ArrayOf |