Added source definition as class - #12
jeppekroghitk wants to merge 7 commits into
Conversation
rimi-itk
left a comment
There was a problem hiding this comment.
This is great! I've commented a little on the naming and some minor stuff.
This pull request contains a little too much. Many changes are not related to “source definition as class”, e.g. the clean ups (which, by the way, has already been made in #9).
| * @see AbstractSource | ||
| * @see docs/adr/007-source-manifest.md | ||
| */ | ||
| final readonly class SourceDefinition |
There was a problem hiding this comment.
I find the name “source definition” confusing and see it more as a “configuration” for a source (which is defined as an instance of SourceInterface).
Therefore I suggest renaming this class to Definition and placing it in the Source folder.
| private ?SourceDefinition $resolved = null; | ||
|
|
||
| public SourceDefinition $definition { | ||
| get => $this->resolved ??= $this->define(); |
There was a problem hiding this comment.
I don't see the need for this.
In HandicapParking.php, say, we can just create the definition in the constructor:
final class HandicapParking extends AbstractSource
{
public function __construct(
…,,
public readonly SourceDefinition $definition = new SourceDefinition(
id: 'mtm_spatialmaps-handicap-parking',
title: 'Handicapparkering, Aarhus Kommune',
…
) {
}
}There was a problem hiding this comment.
Could we land on defining it is the constructor body then? I don't like the idea of the definition of the adapter being handed to it, rather than something it is. Tried implementing said proposal, if you will look at it again :)
There was a problem hiding this comment.
I think defining the configuration in the contructor argument is more elegant that doing it in the body – and it requires less typing. But I understand your point that the configuration should be something that the source owns (and controls).
The best approach may actually be to use a custom attribute for this, e.g. something like
#[AsDataSource(
id: 'mtm_spatialmaps-handicap-parking',
title: 'Handicapparkering, Aarhus Kommune',
…,
)]
final class HandicapParking extends AbstractSource {
}but I don't have much experience (as in none) with that.
| 'id' => $this->definition->id, | ||
| 'title' => $this->definition->title, | ||
| 'description' => $this->definition->description, | ||
| 'publisher' => $this->definition->publisher, | ||
| 'contact' => $this->definition->contact, | ||
| 'landing_page' => $this->definition->landingPage, | ||
| 'access_url' => $this->definition->accessUrl, | ||
| 'media_type' => $this->definition->mediaType, | ||
| 'crs' => $this->definition->crs, | ||
| 'model' => $this->definition->model, | ||
| 'context_url' => $this->definition->contextUrl, | ||
| 'update_frequency' => $this->definition->updateFrequency, | ||
| 'licence' => $this->definition->licence, | ||
| 'omitted_fields' => $this->definition->omittedFields, |
There was a problem hiding this comment.
Add a toArray function in the definition and call that, e.g.
| 'id' => $this->definition->id, | |
| 'title' => $this->definition->title, | |
| 'description' => $this->definition->description, | |
| 'publisher' => $this->definition->publisher, | |
| 'contact' => $this->definition->contact, | |
| 'landing_page' => $this->definition->landingPage, | |
| 'access_url' => $this->definition->accessUrl, | |
| 'media_type' => $this->definition->mediaType, | |
| 'crs' => $this->definition->crs, | |
| 'model' => $this->definition->model, | |
| 'context_url' => $this->definition->contextUrl, | |
| 'update_frequency' => $this->definition->updateFrequency, | |
| 'licence' => $this->definition->licence, | |
| 'omitted_fields' => $this->definition->omittedFields, | |
| 'definition' => $this->definition->toArray(), |
Maybe the definition key is superfluous and this could be shortened to
public function toArray(): array {
return $this->definition->toArray();
}3485a70 to
fcb37df
Compare
The adapter builds its own Definition in the constructor. SourceInterface requires the property, so an adapter that fails to declare it cannot be loaded, and one that declares it without assigning it fails static analysis.
fcb37df to
d0a471d
Compare
| * | ||
| * @see AbstractSource | ||
| */ | ||
| final readonly class Definition |
There was a problem hiding this comment.
I made a typo in #12 (comment): I meant to suggest that we call this Configuration since that is what it is (as I see it):
| final readonly class Definition | |
| final readonly class Configuration |
| private ?SourceDefinition $resolved = null; | ||
|
|
||
| public SourceDefinition $definition { | ||
| get => $this->resolved ??= $this->define(); |
There was a problem hiding this comment.
I think defining the configuration in the contructor argument is more elegant that doing it in the body – and it requires less typing. But I understand your point that the configuration should be something that the source owns (and controls).
The best approach may actually be to use a custom attribute for this, e.g. something like
#[AsDataSource(
id: 'mtm_spatialmaps-handicap-parking',
title: 'Handicapparkering, Aarhus Kommune',
…,
)]
final class HandicapParking extends AbstractSource {
}but I don't have much experience (as in none) with that.
5598a29 to
0a74084
Compare
#8191
Propose source definition as class.