Skip to content

Winter Boot Utilities: Data Trait, Typed Lists, TypeAssert

Winter Boot bundles a handful of small utility classes and traits that keep application code type-safe and boilerplate-free. This page is a reference for the utilities exposed under dev\winterframework\bombok, dev\winterframework\type, and dev\winterframework\util.

The Data trait provides automatic getter and setter methods similar to Java Lombok. Use the trait in your class and access properties via getFieldName() and setFieldName().

use dev\winterframework\bombok\Data;
/**
* @method setId(string|int $val): void
* @method string|int getId()
*
* @method setTitle(string $val): void
* @method getTitle(): string
*/
class Option {
use Data;
private string|int $id;
private string $title;
}
$obj = new Option();
$obj->setId('123');
$obj->setTitle('Example');
echo $obj->getId(); // '123'
echo $obj->getTitle(); // 'Example'

Setters automatically validate that argument types match the property’s type declaration.

A simple wrapper around PHP’s spl_object_hash() for consistent object hashing.

use dev\winterframework\type\Objects;
$hash = Objects::hash($object);

Winter Boot provides typed list implementations for type-safe collections.

Base class for typed lists with ArrayAccess, Countable, and IteratorAggregate support.

use dev\winterframework\type\ArrayList;
$list = ArrayList::ofValues(1, 2, 3);
$list[] = 4;
count($list); // 4

A list specifically for strings with type validation.

use dev\winterframework\type\StringList;
$list = new StringList();
$list[] = 'hello';
// $list[] = 123; // Would throw TypeError

Static factory methods:

  • ofValues(...$values) creates a list from variadic arguments
  • ofArray(array $values) creates a list from an array
  • emptyList() returns the singleton empty list

A read-only map implementing ImmutableCollection.

use dev\winterframework\type\ImmutableMap;
$map = ImmutableMap::of([
'key1' => 'value1',
'key2' => 'value2'
]);
echo $map->get('key1'); // 'value1'
echo $map->getOrDefault('key3', 'default'); // 'default'
$map->contains('value1'); // true
$map->containsIndex('key1'); // true
$map->keys(); // ['key1', 'key2']
$map->values(); // ['value1', 'value2']
$map->count(); // 2
$map->isEmpty(); // false

A min-heap implementation built on SplHeap.

use dev\winterframework\type\IntegerMinHeap;
$heap = new IntegerMinHeap();
$heap->insert(5);
$heap->insert(1);
$heap->insert(3);
while (!$heap->isEmpty()) {
echo $heap->extract(); // 1, 3, 5 (ascending order)
}

Highly reusable type validation methods used throughout the framework.

use dev\winterframework\type\TypeAssert;
TypeAssert::string($value);
TypeAssert::integer($value);
TypeAssert::boolean($value);
TypeAssert::float($value);
TypeAssert::scalar($value);
TypeAssert::positiveInteger($value);
TypeAssert::positiveNoZeroInteger($value);
TypeAssert::negativeInteger($value);
TypeAssert::negativeNoZeroInteger($value);
TypeAssert::callable($value);
TypeAssert::array($value);
TypeAssert::stringArray($value);
TypeAssert::intArray($value);
TypeAssert::object($value);
TypeAssert::null($value);
TypeAssert::typeOf($value, 'ClassName1', 'ClassName2');
TypeAssert::objectOf($value, 'ClassName');
TypeAssert::objectOfIsA($value, 'ClassName');
TypeAssert::notEmpty($name, $value);
TypeAssert::arrayItemNotEmpty($array, $key);
TypeAssert::arrayItemNotSet($array, $key);
TypeAssert::notNull($name, $value);
TypeAssert::state($expression, $message);

MurmurHash3 hash implementation for consistent, non-cryptographic hashing.

use dev\winterframework\util\hash\MurmurHash3Provider;
$provider = new MurmurHash3Provider(seed: 42);
$hashInt = $provider->getHashInt('some value');
$hash = $provider->getHash('some value');

The provider implements the HashProvider interface for swappable hash strategies.