Skip to content

tessera-php/tessera-type-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tessera Type: String

Строковый тип для 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages