-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSalesforceProxyRepository.php
More file actions
76 lines (63 loc) · 1.68 KB
/
SalesforceProxyRepository.php
File metadata and controls
76 lines (63 loc) · 1.68 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);
namespace MatchBot\Domain;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use MatchBot\Client;
use Psr\Log\LoggerInterface;
/**
* @template T of SalesforceProxy
* @template C of Client\Common
* @template-extends EntityRepository<T>
*
* @psalm-suppress MissingConstructor - these repositories have to have setters called after construction
*/
abstract class SalesforceProxyRepository extends EntityRepository
{
/**
* @psalm-var C
*/
protected ?Client\Common $client = null;
protected ?LoggerInterface $logger = null;
protected function getLogger(): LoggerInterface
{
if ($this->logger === null) {
throw new \Exception('Logger not set');
}
return $this->logger;
}
protected function logError(string $message): void
{
$this->getLogger()->error($message);
}
protected function logWarning(string $message): void
{
$this->getLogger()->warning($message);
}
protected function logInfo(string $message): void
{
$this->getLogger()->info($message);
}
/**
* @psalm-param C $client
*/
public function setClient(Client\Common $client): void
{
$this->client = $client;
}
public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
}
/**
* @psalm-return C
*/
protected function getClient(): Client\Common
{
if (!$this->client) {
throw new \LogicException('Set a Client in DI config for this Repository to sync data');
}
return $this->client;
}
}