TableRegistry
in package
Provides a registry/factory for Table objects.
This registry allows you to centralize the configuration for tables their connections and other meta-data.
Configuring instances
You may need to configure your table objects. Using the TableLocator
you can
centralize configuration. Any configuration set before instances are created
will be used when creating instances. If you modify configuration after
an instance is made, the instances will not be updated.
TableRegistry::getTableLocator()->setConfig('Users', ['table' => 'my_users']);
// Prior to 3.6.0
TableRegistry::config('Users', ['table' => 'my_users']);
Configuration data is stored per alias if you use the same table with multiple aliases you will need to set configuration multiple times.
Getting instances
You can fetch instances out of the registry through TableLocator::get()
.
One instance is stored per alias. Once an alias is populated the same
instance will always be returned. This reduces the ORM memory cost and
helps make cyclic references easier to solve.
$table = TableRegistry::getTableLocator()->get('Users', $config);
// Prior to 3.6.0
$table = TableRegistry::get('Users', $config);
Table of Contents
Methods
- clear() : void
- Clears the registry of configuration and instances.
- exists() : bool
- Check to see if an instance exists in the registry.
- get() : Table
- Get a table instance from the registry.
- getTableLocator() : LocatorInterface
- Returns a singleton instance of LocatorInterface implementation.
- remove() : void
- Removes an instance from the registry.
- set() : Table
- Set an instance.
- setTableLocator() : void
- Sets singleton instance of LocatorInterface implementation.
Methods
clear()
Clears the registry of configuration and instances.
public
static clear() : void
exists()
Check to see if an instance exists in the registry.
public
static exists(string $alias) : bool
Parameters
- $alias : string
-
The alias to check for.
Return values
boolget()
Get a table instance from the registry.
public
static get(string $alias[, array<string, mixed> $options = [] ]) : Table
Parameters
- $alias : string
-
The alias name you want to get.
- $options : array<string, mixed> = []
-
The options you want to build the table with.
Return values
TablegetTableLocator()
Returns a singleton instance of LocatorInterface implementation.
public
static getTableLocator() : LocatorInterface
Return values
LocatorInterfaceremove()
Removes an instance from the registry.
public
static remove(string $alias) : void
Parameters
- $alias : string
-
The alias to remove.
set()
Set an instance.
public
static set(string $alias, Table $object) : Table
Parameters
- $alias : string
-
The alias to set.
- $object : Table
-
The table to set.
Return values
TablesetTableLocator()
Sets singleton instance of LocatorInterface implementation.
public
static setTableLocator(LocatorInterface $tableLocator) : void
Parameters
- $tableLocator : LocatorInterface
-
Instance of a locator to use.