Giter VIP home page Giter VIP logo

typed-objects's Introduction

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

typed-objects's People

Contributors

brianlmoon avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

pwfoo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.