如何从实体中获取 _registryAlias

How can I get the _registryAlias from Entity

假设我有:

$user = $this->Users->newEntity(); 那么现在如何从 $user 实体中获取文本 'Users'?

在实体 class 中,我看到了 _registryAlias,但它受到保护并且没有任何函数可以获取它。 (我也不想修改核心)

我的全局函数需要这个,我只想传递 $user(而不是将 $user 和 'Users' 都传递给该函数)。

谢谢。

如果你仔细观察,一种方法,returns 属性值:EntityTrait::source()

API > \Cake\Datasource\EntityTrait::source()

[...] If called with no arguments, it returns the alias of the repository this entity came from if it is known. [...]