dealnews/typed-objects

This package is abandoned and no longer maintained. No replacement package was suggested.

Base classes for creating objects with typed/constrained properties

Maintainers

Package info

github.com/dealnews/typed-objects

pkg:composer/dealnews/typed-objects

Statistics

Installs: 20

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v1.1.0 2019-06-30 14:23 UTC

This package is auto-updated.

Last update: 2026-02-28 15:12:12 UTC


README

PHP now supports typed properties. We suggest using moonspot/value-objects in place of this library.

PHP Objects with typed/constrained properties

A library for creating PHP objects with typed properties.

It supports all of the types that are supported by dealnews/constraints.

Object with Typed Properties Example

// A very simple example
class Foo extends \DealNews\TypedObjects\TypedProperty {
    protected $id;
    protected $name;

    const CONSTRAINTS = [
        "id" => [
            "type" => "integer"
        ],
        "name" => [
            "type" => "string"
        ],
    ];
}

$foo = new Foo();
$foo->id = "1"; // will be integer 1
$foo->id = "string"; // will throw an exception

Typed Array Example

class FooSet extends \DealNews\TypedObjects\TypedArray {
    const REQUIRED_TYPE = "Foo";
}

$set = new FooSet();
$set[] = new Foo(); // allowed
$set[] = 1; // Throws an exception