Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typed DB entities based on PHP reflection #35767

Closed
wants to merge 2 commits into from

Conversation

ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Dec 14, 2022

Resolves: n/a

Summary

Right now columns of a type other than string need to be refined using Entity::addType, typically from the Entity constructor. We can derive this information from typed properties in PHP7.4+ and the help of reflection.

Combined with constructor property promostion in PHP8.0+ entities can be as simple as

class Foo extends TypedEntity {
    public function __construct(
        protected int $id, 
        protected string $bar, 
        protected float $x,
        protected float $y,
    ) {}
}

While having PHPs full type support and automatic database type conversion.

The reason why I haven't added this feature into the existing Entity is that it has to be done in the constructor and Entity has none. https://en.wikipedia.org/wiki/Fragile_base_class

TODO

  • Add TypedEntity
  • Tests

Checklist

@ChristophWurst ChristophWurst added 2. developing Work in progress integration pending documentation This pull request needs an associated documentation update labels Dec 14, 2022
continue;
}

$this->addType($property->getName(), $propertyType->getName());

Check failure

Code scanning / Psalm

UndefinedMethod

Method ReflectionType::getName does not exist
}

$this->addType($property->getName(), $propertyType->getName());
self::$reflectedFieldTypes[$class][$property->getName()] = $propertyType->getName();

Check failure

Code scanning / Psalm

UndefinedMethod

Method ReflectionType::getName does not exist
@blizzz blizzz added this to the Nextcloud 29 milestone Nov 23, 2023
This was referenced Mar 12, 2024
@Altahrim Altahrim mentioned this pull request Mar 20, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 29, Nextcloud 30 Mar 28, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
@skjnldsv skjnldsv closed this Aug 14, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 31 milestone Aug 14, 2024
@skjnldsv skjnldsv deleted the enhancement/typed-db-entity branch August 30, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress integration pending documentation This pull request needs an associated documentation update
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

3 participants