File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Getting Started
2+
3+ Basic use.
4+ ``` php
5+ use \Locker\XApi\Statement as Statement;
6+
7+ // Returns the given statement as a string of JSON.
8+ function getJsonStatement($statement) {
9+ return $statement->toJson();
10+ }
11+
12+ // Returns the given errors as a string of JSON.
13+ function getJsonValidationErrors($errors) {
14+ return json_encode(array_map(function ($error) {
15+ $error->addTrace('statement');
16+ return (string) $error;
17+ }, $errors));
18+ }
19+
20+ // Creates a statement and validates it.
21+ $statement = Statement::createFromJson($json_string);
22+ $errors = $statement->validate();
23+
24+ // Outputs validation errors or the statement as JSON.
25+ if (empty($errors)) {
26+ echo getJsonStatement($statement);
27+ } else {
28+ echo getJsonValidationErrors($errors);
29+ }
30+ ```
You can’t perform that action at this time.
0 commit comments