tessera-php / tessera-type-string
Tessera type: String
Package info
github.com/tessera-php/tessera-type-string
pkg:composer/tessera-php/tessera-type-string
dev-main
2026-02-23 11:36 UTC
Requires
- php: 8.1 - 8.5
- tessera-php/tessera-core: dev-main
Requires (Dev)
- phpunit/phpunit: ^10.0
Provides
- tessera-contract-type/string: 1.0.0
This package is auto-updated.
Last update: 2026-04-25 18:17:46 UTC
README
Строковый тип для Tessera.
Установка
composer require tessera-php/tessera-type-string
Использование
use Tessera\Type\String\StringType; use Tessera\Type\String\StringData; $type = new StringType(); // Валидация $type->validate('hello'); // true $type->validate(''); // true $type->validate(42); // true $type->validate(3.14); // true $type->validate(true); // true $type->validate(null); // true $type->validate(['a']); // false // Нормализация $data = $type->normalize(42); echo $data->value; // '42' (string) $data = $type->normalize(true); echo $data->value; // '1' $data = $type->normalize(false); echo $data->value; // '0' $data = $type->normalize(null); echo $data->value; // '' (пустая строка) // DTO $data = new StringData('hello'); echo $data->value; // 'hello'
Принимаемые форматы
string— нативная строкаint— целое число (приводится к строке)float— число с плавающей точкой (приводится к строке)bool— булево значение (приводится к '1' или '0')null— null (приводится к пустой строке)
Контракт
provide: tessera-contract-type/string
Лицензия
MIT