-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathTableRegistry.php
More file actions
76 lines (72 loc) · 2.5 KB
/
TableRegistry.php
File metadata and controls
76 lines (72 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\ORM;
use Cake\Datasource\FactoryLocator;
use Cake\ORM\Locator\LocatorInterface;
/**
* 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']);
* ```
*
* 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);
* ```
*/
class TableRegistry
{
/**
* Returns a singleton instance of LocatorInterface implementation.
*
* @return \Cake\ORM\Locator\LocatorInterface
*/
public static function getTableLocator(): LocatorInterface
{
/** @var \Cake\ORM\Locator\LocatorInterface */
return FactoryLocator::get('Table');
}
/**
* Sets singleton instance of LocatorInterface implementation.
*
* @param \Cake\ORM\Locator\LocatorInterface $tableLocator Instance of a locator to use.
* @return void
*/
public static function setTableLocator(LocatorInterface $tableLocator): void
{
FactoryLocator::add('Table', $tableLocator);
}
}