-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1-0-0 See merge request fluxlabs/flux-eco/json-schema-instance!2
- Loading branch information
Showing
17 changed files
with
192 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,66 @@ https://json-schema.org/specification.html | |
The following example application demonstrates the usage: | ||
https://github.com/flux-caps/todo-app | ||
|
||
## Usage | ||
|
||
account.yaml | ||
``` | ||
title: account | ||
type: object | ||
aggregateRootNames: | ||
- account | ||
properties: | ||
personId: | ||
type: number | ||
firstname: | ||
type: string | ||
lastname: | ||
type: string | ||
email: | ||
type: string | ||
type: | ||
type: string | ||
lastChanged: | ||
type: string | ||
``` | ||
|
||
getAndPrintSchemaInstance.php | ||
|
||
``` | ||
$schema = yaml_parse(file_get_contents('account.yaml')); | ||
$schemaInstance = fluxJsonSchemaInstance\getSchemaInstance('Emmett', $schema['properties']['firstname']); | ||
print_r($schemaInstance); | ||
$schemaInstance = fluxJsonSchemaInstance\getSchemaInstance('123', $schema['properties']['personId']); | ||
print_r($schemaInstance); | ||
``` | ||
|
||
outputs | ||
``` | ||
Array | ||
( | ||
[value] => Emmett | ||
[describedBy] => {"type":"string"} | ||
) | ||
Array | ||
( | ||
[value] => 123 | ||
[describedBy] => {"type":"number"} | ||
) | ||
``` | ||
|
||
## Contributing :purple_heart: | ||
|
||
Please ... | ||
|
||
1. ... register an account at https://git.fluxlabs.ch | ||
2. ... create pull requests :fire: | ||
|
||
## Adjustment suggestions / bug reporting :feet: | ||
|
||
Please ... | ||
|
||
1. ... register an account at https://git.fluxlabs.ch | ||
2. ... ask us for a Service Level Agreement: [email protected] :kissing_heart: | ||
3. ... read and create issues | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: account | ||
type: object | ||
aggregateRootNames: | ||
- account | ||
properties: | ||
personId: | ||
type: number | ||
firstname: | ||
type: string | ||
lastname: | ||
type: string | ||
email: | ||
type: string | ||
type: | ||
type: string | ||
lastChanged: | ||
type: string | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
||
$schema = yaml_parse(file_get_contents('account.yaml')); | ||
|
||
$schemaInstance = fluxJsonSchemaInstance\getSchemaInstance('Emmett', $schema['properties']['firstname']); | ||
print_r($schemaInstance); | ||
|
||
$schemaInstance = fluxJsonSchemaInstance\getSchemaInstance('123', $schema['properties']['personId']); | ||
print_r($schemaInstance); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace fluxJsonSchemaInstance; | ||
|
||
use FluxEco\JsonSchemaInstance; | ||
|
||
function getSchemaInstance(string $value, array $jsonSchema) : array | ||
{ | ||
return JsonSchemaInstance\Api::new()->getSchemaInstance($value, $jsonSchema); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace FluxEco\JsonSchemaInstance; | ||
|
||
class Api | ||
{ | ||
|
||
private Core\Ports\SchemaInstanceService $service; | ||
|
||
private function __construct(Core\Ports\SchemaInstanceService $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
public static function new() : self | ||
{ | ||
$service = Core\Ports\SchemaInstanceService::new(); | ||
return new self($service); | ||
} | ||
|
||
final public function getSchemaInstance(string $value, array $jsonSchema) : array | ||
{ | ||
$schemaInstance = $this->service->getSchemaInstance($value, $jsonSchema); | ||
return SchemaInstance::fromDomain($schemaInstance)->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace FluxEco\JsonSchemaInstance; | ||
|
||
class SchemaInstance | ||
{ | ||
private Core\Domain\Models\SchemaInstance $schemaInstance; | ||
|
||
private function __construct(Core\Domain\Models\SchemaInstance $schemaInstance) | ||
{ | ||
$this->schemaInstance = $schemaInstance; | ||
} | ||
|
||
public static function fromDomain(Core\Domain\Models\SchemaInstance $schemaInstance) : self | ||
{ | ||
return new self($schemaInstance); | ||
} | ||
|
||
public function toArray() : array | ||
{ | ||
return $this->schemaInstance->toArray(); | ||
} | ||
} |