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\APIGuzzleAdapter; |
15
|
|
|
use PhraseanetSDK\AbstractRepository; |
16
|
|
|
use PhraseanetSDK\Search\SearchRepository; |
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
use Psr\Log\NullLogger; |
19
|
|
|
|
20
|
|
|
class EntityManager |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var APIGuzzleAdapter |
24
|
|
|
*/ |
25
|
|
|
private $adapter; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var LoggerInterface |
29
|
|
|
*/ |
30
|
|
|
private $logger; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var AbstractRepository[] |
34
|
|
|
*/ |
35
|
|
|
private $repositories = array(); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param APIGuzzleAdapter $v1Adapter |
|
|
|
|
39
|
|
|
* @param LoggerInterface $logger |
40
|
|
|
*/ |
41
|
88 |
|
public function __construct( |
42
|
|
|
APIGuzzleAdapter $adapter, |
43
|
|
|
LoggerInterface $logger = null |
44
|
|
|
) { |
45
|
88 |
|
$this->adapter = $adapter; |
46
|
88 |
|
$this->logger = $logger ?: new NullLogger(); |
47
|
88 |
|
} |
48
|
|
|
|
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
|
|
|
*/ |
62
|
86 |
|
public function getAdapter() |
63
|
|
|
{ |
64
|
86 |
|
return $this->adapter; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get a repository by its name |
69
|
|
|
* |
70
|
|
|
* @param string $name |
71
|
|
|
* @return AbstractRepository |
72
|
|
|
*/ |
73
|
17 |
|
public function getRepository($name) |
74
|
|
|
{ |
75
|
17 |
|
if (isset($this->repositories[$name])) { |
76
|
|
|
return $this->repositories[$name]; |
77
|
|
|
} |
78
|
|
|
|
79
|
17 |
|
$className = ucfirst($name); |
80
|
17 |
|
$objectName = sprintf('\\PhraseanetSDK\\Repository\\%s', $className); |
81
|
|
|
|
82
|
17 |
|
if ($name == 'search') { |
83
|
|
|
return new SearchRepository($this, $this->adapter); |
84
|
|
|
} |
85
|
|
|
|
86
|
17 |
|
if (!class_exists($objectName)) { |
87
|
|
|
throw new Exception\InvalidArgumentException( |
88
|
|
|
sprintf('Class %s does not exists', $objectName) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
17 |
|
return $this->repositories[$name] = new $objectName($this); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.