Skip to content

Commit 48089d3

Browse files
author
Greg Bowler
committed
docs: update examples
1 parent 3b05cc3 commit 48089d3

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎example/01-json-encode.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Gt\DataObject\DataObject;
4+
5+
require __DIR__ . "/../vendor/autoload.php";
6+
7+
$obj = (new DataObject())
8+
->with("name", "Cody")
9+
->with("colour", "orange")
10+
->with("food", [
11+
"biscuits",
12+
"mushrooms",
13+
"corn on the cob",
14+
]);
15+
16+
echo json_encode($obj);

‎example/02-json-decode.php‎

Whitespace-only changes.

‎example/03-type-casting.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Gt\DataObject\DataObject;
4+
5+
require __DIR__ . "/../vendor/autoload.php";
6+
7+
// Set an object with all string values, similar to a web requests:
8+
$obj = new DataObject();
9+
$obj = $obj->with("one", "1");
10+
$obj = $obj->with("two", "two");
11+
$obj = $obj->with("pi", "3.14159");
12+
13+
// Automatically cast to int:
14+
15+
$int1 = $obj->getInt("one");
16+
$int2 = $obj->getInt("two");
17+
$int3 = $obj->getInt("pi");
18+
19+
echo "One: $int1, two: $int2, three: $int3", PHP_EOL;
20+
// Outputs: One: 1, two: 0, three: 3
21+
// Note how the decimal data is lost in the cast to int,
22+
// but how the original data is not lost.

‎example/04-type-safety-arrays.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require __DIR__ . "/../vendor/autoload.php";

0 commit comments

Comments
 (0)