cakephp v3.x 中的存储库和 table 对象有什么区别?

What is the difference between repositories and table objects in cakephp v3.x?

我一直在使用 Cakephp ver2.x 并且刚刚开始迁移到 Cakephp v3.x。当我尝试使用新的 ORM 时,我对存储库和 table 对象等基本概念感到困惑。存储库和 table 对象有什么区别?

存储库可以是任何东西,而 table,顾名思义,只是一个 table。

http://api.cakephp.org/3.0/class-Cake.ORM.Table.html

Represents a single database table.

Exposes methods for retrieving data out of it, and manages the associations this table has to other tables. Multiple instances of this class can be created for the same database table with different aliases, this allows you to address your database structure in a richer and more expressive way.

http://api.cakephp.org/3.0/class-Cake.Datasource.RepositoryInterface.html

Describes the methods that any class representing a data storage should comply with.

数据存储可以是任何类型的存储系统,甚至是不了解 table 的存储系统,例如图形数据库或基于文档的系统。

这类问题只要查看API文档和代码总是很简单的。该代码有很好的文档记录。然后,这种工作方式也变得显而易见:

class Table implements RepositoryInterface, EventListenerInterface

Table实现了RepositoryInterface定义的接口。