PHP code example of dealnews / typed-objects
1. Go to this page and download the library: Download dealnews/typed-objects library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dealnews / typed-objects example snippets
// 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
class FooSet extends \DealNews\TypedObjects\TypedArray {
const REQUIRED_TYPE = "Foo";
}
$set = new FooSet();
$set[] = new Foo(); // allowed
$set[] = 1; // Throws an exception