Skip to content

Added source definition as class - #12

Closed
jeppekroghitk wants to merge 7 commits into
feature/source-importfrom
feature/source-manager-source-definition
Closed

jeppekroghitk wants to merge 7 commits into
feature/source-importfrom
feature/source-manager-source-definition

Conversation

@jeppekroghitk

@jeppekroghitk jeppekroghitk commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

#8191

Propose source definition as class.

@jeppekroghitk
jeppekroghitk changed the base branch from main to feature/source-manager September 11, 2026 07:55
@jeppekroghitk jeppekroghitk changed the title Added source definition Added source definition as class Sep 11, 2026

@rimi-itk rimi-itk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread src/Source/SourceDefinition.php Outdated
* @see AbstractSource
* @see docs/adr/007-source-manifest.md
*/
final readonly class SourceDefinition

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Source/AbstractSource.php Outdated
private ?SourceDefinition $resolved = null;

public SourceDefinition $definition {
get => $this->resolved ??= $this->define();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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',
            …
    ) {
    }
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Source/AbstractSource.php Outdated
Comment on lines +37 to +50
'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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a toArray function in the definition and call that, e.g.

Suggested change
'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();
    }

@jeppekroghitk
jeppekroghitk force-pushed the feature/source-manager-source-definition branch from 3485a70 to fcb37df Compare September 11, 2026 09:01
@jeppekroghitk
jeppekroghitk changed the base branch from feature/source-manager to feature/source-import September 11, 2026 09:01
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.
@jeppekroghitk
jeppekroghitk force-pushed the feature/source-manager-source-definition branch from fcb37df to d0a471d Compare September 11, 2026 10:36
Comment thread src/Source/Definition.php
*
* @see AbstractSource
*/
final readonly class Definition

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Suggested change
final readonly class Definition
final readonly class Configuration

Comment thread src/Source/AbstractSource.php Outdated
private ?SourceDefinition $resolved = null;

public SourceDefinition $definition {
get => $this->resolved ??= $this->define();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rimi-itk
rimi-itk force-pushed the feature/source-import branch from 5598a29 to 0a74084 Compare September 11, 2026 11:58
@rimi-itk
rimi-itk deleted the branch feature/source-import September 11, 2026 12:00
@rimi-itk rimi-itk closed this Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Require a specific configuration from new adapters regarding their data source

2 participants