Skip to content

Let applications extend Repository into typed repositories - #5

Merged
SoloPHP merged 1 commit into
mainfrom
rc4/extendable-repository
Oct 27, 2026
Merged

SoloPHP merged 1 commit into
mainfrom
rc4/extendable-repository

Conversation

@SoloPHP

@SoloPHP SoloPHP commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Makes Repository extensible before v1.0.0-RC4. The dilio backend moved all 140 of its tables to the package and wanted one injectable type per table instead of a container id per mapping.

Changes

  • Repository is a non-final readonly class. An application can extend it with a readonly class that fixes the mapping in its own constructor, so a container injects each table's repository by type and PHPStan reads the model of every read from @extends Repository<Model>.
  • Every public method except the constructor is final: a subclass adds methods of its own and cannot change the inherited reads and writes.
  • Guides: a "Typed repositories" section in docs/guide/api.md; the migration guide and the details page offer extending next to owning an instance; changelog section "Changes since 1.0.0-RC3".

Behavior changes for RC3 users

None. Code that constructs Repository directly keeps working unchanged.

Verification

  • 574 unit tests, PHPStan max and PSR-12 on PHP 8.3 and 8.5; composer validate --strict; the examples run.
  • RepositorySubclassTest: a subclass fixes its mapping and adds a method; the class is readonly and non-final, and every public method but the constructor is final. tests/Types/PublicApiTypes.php checks that reads through a typed subclass keep its model.
  • Integration suite on MySQL 8.4, MariaDB 12.3 and PostgreSQL 17: 31 tests on each.
  • The dilio backend with this Repository in place of RC3: 140 typed table repositories over three abstract per-database bases, injected by type; Unit 919 and Feature 1704 pass, and its PHPStan and PHPCS findings are unchanged.

🤖 Generated with Claude Code

Repository is no longer final. An application can extend it with a
readonly class that fixes the mapping in its own constructor, so a
container injects each table's repository by type and static analysis
reads the model from @extends Repository<Model>. Every public method
except the constructor is final: a subclass adds methods of its own and
cannot change the inherited reads and writes.
@SoloPHP
SoloPHP merged commit 9d9f96b into main Oct 27, 2026
26 checks passed
@SoloPHP
SoloPHP deleted the rc4/extendable-repository branch October 27, 2026 21:46
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.

1 participant