Skip to content

Commit

Permalink
Configurable path to json schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Minstel committed Jul 12, 2019
1 parent d46fe84 commit 1b98f56
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/settings.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ lto:

event_chain:
url: http://foo-event-chain-service/

json_schema_path: tests/_data/json-schema
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ db:
database: lto_workflow

event_chain: null

json_schema_path: config/schemas
5 changes: 3 additions & 2 deletions declarations/services/json-schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

return new JsonSchemaValidator($validator, $repository);
},
JsonSchemaRepository::class => static function() {
JsonSchemaRepository::class => static function(AutowireContainerInterface $container) {
$config = $container->get('config');
$loaders = [
'file' => new FileSource()
'file' => new FileSource($config->json_schema_path)
];

return new JsonSchemaRepository($loaders);
Expand Down
17 changes: 16 additions & 1 deletion services/JsonSchema/Validator/Loader/FileSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
*/
class FileSource
{
/**
* @var string
**/
protected $basePath;

/**
* Constructor
*
* @param string $basePath
*/
public function __construct(string $basePath)
{
$this->basePath = $basePath;
}

/**
* Fetch schema
*
Expand Down Expand Up @@ -54,6 +69,6 @@ public function toLocalPath(string $url): ?string

$path = parse_url($url, PHP_URL_PATH);

return 'config/schemas' . $path;
return $this->basePath . $path;
}
}
1 change: 1 addition & 0 deletions tests/_data/json-schema/v0.2.0/scenario/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 1b98f56

Please sign in to comment.