Presently, the library has a concept of Models and Repositories (which result in Models), but the integration is still largely left to the implementor to connect. Most notably, there are repository interfaces and an abstract class, but the model's corresponding CRUD methods require manual connection.
I think it's worth keeping the distinction that a Model doesn't have to have a Repository, but make it very easy to connect the two when it does. Therefore, I propose adding a HasRepository Trait, something like:
trait HasRepository {
abstract protected static function getRepository(): Repository;
public function find( $id ): ?Model {
return static::getRepository()->getById( $id );
}
// other CRUD methods here
}
I'm inclined to either make it so the Repository abstract class implement the existing interfaces, or introduce a new RepositoryCrud interface that does it all. We could check in each CRUD method that the repository has the given interface, but what I don't like about that is we'd only catch that at runtime. It's safer to just be able to make the assumption that the repository will handle all the CRUD operations.
Presently, the library has a concept of Models and Repositories (which result in Models), but the integration is still largely left to the implementor to connect. Most notably, there are repository interfaces and an abstract class, but the model's corresponding CRUD methods require manual connection.
I think it's worth keeping the distinction that a Model doesn't have to have a Repository, but make it very easy to connect the two when it does. Therefore, I propose adding a
HasRepositoryTrait, something like:I'm inclined to either make it so the Repository abstract class implement the existing interfaces, or introduce a new RepositoryCrud interface that does it all. We could check in each CRUD method that the repository has the given interface, but what I don't like about that is we'd only catch that at runtime. It's safer to just be able to make the assumption that the repository will handle all the CRUD operations.