1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Phraseanet SDK. |
5
|
|
|
* |
6
|
|
|
* (c) Alchemy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PhraseanetSDK; |
13
|
|
|
|
14
|
|
|
use PhraseanetSDK\Http\ApiClient; |
15
|
|
|
use PhraseanetSDK\Http\APIGuzzleAdapter; |
16
|
|
|
use PhraseanetSDK\AbstractRepository; |
17
|
|
|
use PhraseanetSDK\Http\Client; |
18
|
|
|
use PhraseanetSDK\Orders\OrderRepository; |
19
|
|
|
use PhraseanetSDK\Search\SearchRepository; |
20
|
|
|
use Psr\Log\LoggerInterface; |
21
|
|
|
use Psr\Log\NullLogger; |
22
|
|
|
|
23
|
|
|
class EntityManager |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var APIGuzzleAdapter |
27
|
|
|
*/ |
28
|
|
|
private $client; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var LoggerInterface |
32
|
|
|
*/ |
33
|
|
|
private $logger; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var AbstractRepository[] |
37
|
|
|
*/ |
38
|
|
|
private $repositories = array(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ApiClient $client |
42
|
88 |
|
* @param LoggerInterface $logger |
43
|
|
|
*/ |
44
|
|
|
public function __construct(ApiClient $client, LoggerInterface $logger = null) { |
45
|
|
|
$this->client = $client; |
|
|
|
|
46
|
88 |
|
$this->logger = $logger ?: new NullLogger(); |
47
|
88 |
|
} |
48
|
88 |
|
|
49
|
|
|
/** |
50
|
|
|
* @return LoggerInterface |
51
|
|
|
*/ |
52
|
|
|
public function getLogger() |
53
|
|
|
{ |
54
|
|
|
return $this->logger; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return the client attached to this entity manager |
59
|
|
|
* |
60
|
|
|
* @return APIGuzzleAdapter |
61
|
|
|
* @deprecated This method will be removed in the next major release of the SDK. Use EntityManager::getClient(). |
62
|
|
|
*/ |
63
|
86 |
|
public function getAdapter() |
64
|
|
|
{ |
65
|
86 |
|
return $this->getClient(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return ApiClient |
70
|
|
|
*/ |
71
|
|
|
public function getClient() |
72
|
|
|
{ |
73
|
|
|
return $this->client; |
74
|
17 |
|
} |
75
|
|
|
|
76
|
17 |
|
/** |
77
|
|
|
* Get a repository by its name |
78
|
|
|
* |
79
|
|
|
* @param string $name |
80
|
17 |
|
* @return AbstractRepository |
81
|
17 |
|
*/ |
82
|
|
|
public function getRepository($name) |
83
|
17 |
|
{ |
84
|
|
|
if (isset($this->repositories[$name])) { |
85
|
|
|
return $this->repositories[$name]; |
86
|
|
|
} |
87
|
17 |
|
|
88
|
|
|
$className = ucfirst($name); |
89
|
|
|
$objectName = sprintf('\\PhraseanetSDK\\Repository\\%s', $className); |
90
|
|
|
|
91
|
17 |
|
if ($name == 'search') { |
92
|
|
|
return $this->repositories['search'] = new SearchRepository($this, $this->client); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if ($name == 'orders') { |
96
|
|
|
return $this->repositories['orders'] = new OrderRepository($this, $this->client); |
97
|
17 |
|
} |
98
|
|
|
|
99
|
|
|
if (!class_exists($objectName)) { |
100
|
|
|
throw new Exception\InvalidArgumentException( |
101
|
|
|
sprintf('Class %s does not exists', $objectName) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $this->repositories[$name] = new $objectName($this); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..