Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 1.41 KB

Read.md

File metadata and controls

71 lines (57 loc) · 1.41 KB

Back

Read

JSON data

[
	{
		"CUSTOM_ID": 1,
		"name": "First"
	},
  {
		"CUSTOM_ID": 2,
		"name": "Second"
	},
	{
		"CUSTOM_ID": 3
	}
]

Reading by collection

	use Matraux\JsonOrm\Json\SimpleExplorer;

	$explorer = SimpleExplorer::fromFile('path to JSON file'); // Access data from file
	$explorer = SimpleExplorer::fromString('JSON string'); // Access data from string
	$collection = CommonCollection::fromExplorer($explorer); // Create collection

	/**
	 * ArrayAccess
	 */
	$entity = $collection[0];
	echo $entity->id; // Print 1
	echo $entity->name; // Print "First"
	$time = $entity->timestamp; // null|DateTime object

	/**
	 * Iterator
	 */
	foreach($collection as $entity) {
		echo $entity->id; // Print 1, 2 and 3
		echo $entity->name; // Print "First", "Second" and null
	}

	echo count($collection); // Print count of entities

JSON data

{
	"CUSTOM_ID": 1,
	"name": "First"
}

Reading by entity

	use Matraux\JsonOrm\Json\SimpleExplorer;

	$explorer = SimpleExplorer::fromFile('path to JSON file'); // Access data from file
	$explorer = SimpleExplorer::fromString('JSON string'); // Access data from string
	$entity = CommonEntity::fromExplorer($explorer);

	echo $entity->id; // Print "1"

	echo $entity->name; // Print "First"

	$time = $entity->timestamp; // null|DateTime object