From bf52a58ea1be1924f2aeda4f8c75b23e4f1d2b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Pustu=C5=82ka?= Date: Fri, 21 Apr 2017 08:56:23 +0200 Subject: [PATCH] Apply TableRegistry locator setter and getter. --- src/Datasource/FactoryLocator.php | 2 +- src/Network/Session/DatabaseSession.php | 2 +- src/ORM/Locator/LocatorAwareTrait.php | 2 +- src/ORM/TableRegistry.php | 14 +++++++------- .../TestCase/ORM/Locator/LocatorAwareTraitTest.php | 2 +- tests/TestCase/ORM/TableRegistryTest.php | 12 ++++++------ 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Datasource/FactoryLocator.php b/src/Datasource/FactoryLocator.php index 715e21eb5ba..b7d8672e2b0 100644 --- a/src/Datasource/FactoryLocator.php +++ b/src/Datasource/FactoryLocator.php @@ -59,7 +59,7 @@ public static function drop($type) public static function get($type) { if (!isset(static::$_modelFactories['Table'])) { - static::$_modelFactories['Table'] = [TableRegistry::locator(), 'get']; + static::$_modelFactories['Table'] = [TableRegistry::getTableLocator(), 'get']; } if (!isset(static::$_modelFactories[$type])) { diff --git a/src/Network/Session/DatabaseSession.php b/src/Network/Session/DatabaseSession.php index f7ee6dc88e1..82b9858de57 100644 --- a/src/Network/Session/DatabaseSession.php +++ b/src/Network/Session/DatabaseSession.php @@ -50,7 +50,7 @@ class DatabaseSession implements SessionHandlerInterface */ public function __construct(array $config = []) { - $tableLocator = isset($config['tableLocator']) ? $config['tableLocator'] : TableRegistry::locator(); + $tableLocator = isset($config['tableLocator']) ? $config['tableLocator'] : TableRegistry::getTableLocator(); if (empty($config['model'])) { $config = $tableLocator->exists('Sessions') ? [] : ['table' => 'sessions']; diff --git a/src/ORM/Locator/LocatorAwareTrait.php b/src/ORM/Locator/LocatorAwareTrait.php index fcf0d7ffb92..9b4c9cfa559 100644 --- a/src/ORM/Locator/LocatorAwareTrait.php +++ b/src/ORM/Locator/LocatorAwareTrait.php @@ -67,7 +67,7 @@ public function setTableLocator(LocatorInterface $tableLocator) public function getTableLocator() { if (!$this->_tableLocator) { - $this->_tableLocator = TableRegistry::locator(); + $this->_tableLocator = TableRegistry::getTableLocator(); } return $this->_tableLocator; diff --git a/src/ORM/TableRegistry.php b/src/ORM/TableRegistry.php index e171210aff0..ed222a3a4da 100644 --- a/src/ORM/TableRegistry.php +++ b/src/ORM/TableRegistry.php @@ -115,7 +115,7 @@ public static function setTableLocator(LocatorInterface $locator) */ public static function config($alias = null, $options = null) { - return static::locator()->config($alias, $options); + return static::getTableLocator()->config($alias, $options); } /** @@ -129,7 +129,7 @@ public static function config($alias = null, $options = null) */ public static function get($alias, array $options = []) { - return static::locator()->get($alias, $options); + return static::getTableLocator()->get($alias, $options); } /** @@ -140,7 +140,7 @@ public static function get($alias, array $options = []) */ public static function exists($alias) { - return static::locator()->exists($alias); + return static::getTableLocator()->exists($alias); } /** @@ -152,7 +152,7 @@ public static function exists($alias) */ public static function set($alias, Table $object) { - return static::locator()->set($alias, $object); + return static::getTableLocator()->set($alias, $object); } /** @@ -163,7 +163,7 @@ public static function set($alias, Table $object) */ public static function remove($alias) { - static::locator()->remove($alias); + static::getTableLocator()->remove($alias); } /** @@ -173,7 +173,7 @@ public static function remove($alias) */ public static function clear() { - static::locator()->clear(); + static::getTableLocator()->clear(); } /** @@ -185,6 +185,6 @@ public static function clear() */ public static function __callStatic($name, $arguments) { - return static::locator()->$name(...$arguments); + return static::getTableLocator()->$name(...$arguments); } } diff --git a/tests/TestCase/ORM/Locator/LocatorAwareTraitTest.php b/tests/TestCase/ORM/Locator/LocatorAwareTraitTest.php index a827acc265a..72d470a3d0c 100644 --- a/tests/TestCase/ORM/Locator/LocatorAwareTraitTest.php +++ b/tests/TestCase/ORM/Locator/LocatorAwareTraitTest.php @@ -43,7 +43,7 @@ public function setUp() public function testTableLocator() { $tableLocator = $this->subject->tableLocator(); - $this->assertSame(TableRegistry::locator(), $tableLocator); + $this->assertSame(TableRegistry::getTableLocator(), $tableLocator); $newLocator = $this->getMockBuilder('Cake\ORM\Locator\LocatorInterface')->getMock(); $subjectLocator = $this->subject->tableLocator($newLocator); diff --git a/tests/TestCase/ORM/TableRegistryTest.php b/tests/TestCase/ORM/TableRegistryTest.php index 24151727061..c4b3fab3e8b 100644 --- a/tests/TestCase/ORM/TableRegistryTest.php +++ b/tests/TestCase/ORM/TableRegistryTest.php @@ -39,7 +39,7 @@ class TableRegistryTest extends TestCase public function setUp() { parent::setUp(); - $this->_originalLocator = TableRegistry::locator(); + $this->_originalLocator = TableRegistry::getTableLocator(); } /** @@ -50,7 +50,7 @@ public function setUp() public function tearDown() { parent::tearDown(); - TableRegistry::locator($this->_originalLocator); + TableRegistry::setTableLocator($this->_originalLocator); } /** @@ -61,7 +61,7 @@ public function tearDown() protected function _setMockLocator() { $locator = $this->getMockBuilder('Cake\ORM\Locator\LocatorInterface')->getMock(); - TableRegistry::locator($locator); + TableRegistry::setTableLocator($locator); return $locator; } @@ -73,11 +73,11 @@ protected function _setMockLocator() */ public function testLocator() { - $this->assertInstanceOf('Cake\ORM\Locator\LocatorInterface', TableRegistry::locator()); + $this->assertInstanceOf('Cake\ORM\Locator\LocatorInterface', TableRegistry::getTableLocator()); $locator = $this->_setMockLocator(); - $this->assertSame($locator, TableRegistry::locator()); + $this->assertSame($locator, TableRegistry::getTableLocator()); } /** @@ -87,7 +87,7 @@ public function testLocator() */ public function testLocatorDefault() { - $locator = TableRegistry::locator(); + $locator = TableRegistry::getTableLocator(); $this->assertInstanceOf('Cake\ORM\Locator\TableLocator', $locator); }