|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under The MIT License |
|
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CakeDC\Api\Service\Locator; |
|
13
|
|
|
|
|
14
|
|
|
use CakeDC\Api\Service\ServiceRegistry; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Contains method for setting and accessing LocatorInterface instance |
|
18
|
|
|
*/ |
|
19
|
|
|
trait LocatorAwareTrait |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Service locator instance |
|
24
|
|
|
* |
|
25
|
|
|
* @var \CakeDC\Api\Service\Locator\LocatorInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $_serviceLocator; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Sets the service locator. |
|
31
|
|
|
* If no parameters are passed, it will return the currently used locator. |
|
32
|
|
|
* |
|
33
|
|
|
* @param \CakeDC\Api\Service\Locator\LocatorInterface|null $serviceLocator LocatorInterface instance. |
|
34
|
|
|
* @return \CakeDC\Api\Service\Locator\LocatorInterface |
|
35
|
|
|
* @deprecated 3.6.0 Use getTableLocator()/setTableLocator() instead. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function serviceLocator(LocatorInterface $serviceLocator = null) |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
deprecationWarning( |
|
40
|
|
|
get_called_class() . '::tableLocator() is deprecated. ' . |
|
41
|
|
|
'Use getTableLocator()/setTableLocator() instead.' |
|
42
|
|
|
); |
|
43
|
|
|
if ($tableLocator !== null) { |
|
44
|
|
|
$this->setTableLocator($tableLocator); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->getTableLocator(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Sets the table locator. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \Cake\ORM\Locator\LocatorInterface $tableLocator LocatorInterface instance. |
|
54
|
|
|
* @return $this |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setTableLocator(LocatorInterface $tableLocator) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->_tableLocator = $tableLocator; |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Gets the table locator. |
|
65
|
|
|
* |
|
66
|
|
|
* @return \Cake\ORM\Locator\LocatorInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getTableLocator() |
|
69
|
|
|
{ |
|
70
|
|
|
if (!$this->_tableLocator) { |
|
71
|
|
|
$this->_tableLocator = TableRegistry::getTableLocator(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->_tableLocator; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.