1 | <?php |
||
22 | class Remove extends HttpRelayBuilder |
||
23 | { |
||
24 | /** |
||
25 | * The node |
||
26 | */ |
||
27 | const NODE = 'companies'; |
||
28 | |||
29 | /** |
||
30 | * The resource |
||
31 | */ |
||
32 | const RESOURCE = 'companies'; |
||
33 | |||
34 | /** |
||
35 | * Upsert constructor. |
||
36 | * @param string $companyId |
||
37 | * @param string $contactId |
||
38 | * @param AuthorizationInterface $authorization |
||
39 | * @param CacheInterface $cache |
||
40 | * @param LoggerInterface|null $logger |
||
41 | * @param array $config |
||
42 | */ |
||
43 | public function __construct( |
||
44 | string $companyId, |
||
45 | string $contactId, |
||
46 | AuthorizationInterface $authorization, |
||
47 | CacheInterface $cache, |
||
48 | LoggerInterface $logger = null, |
||
49 | $config = [] |
||
50 | ) { |
||
51 | parent::__construct($authorization, $logger, $config); |
||
52 | |||
53 | $cacheKey = self::RESOURCE . ':' . $companyId . ':contacts' |
||
54 | |||
55 | $this->addUri($companyId, $contactId, $logger) |
||
|
|||
56 | ->addCache($cache, $cacheKey, $logger); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param string $companyId |
||
61 | * @param string $contactId |
||
62 | * @param LoggerInterface|null $logger |
||
63 | * @return $this |
||
64 | */ |
||
65 | protected function addUri(string $companyId, string $contactId, LoggerInterface $logger = null) |
||
66 | { |
||
67 | return $this->addBefore('uri', [ |
||
68 | 'class' => ResourceV2::class, |
||
69 | 'method' => 'DELETE', |
||
70 | 'node' => self::NODE, |
||
71 | 'resource' => self::RESOURCE . '/' . $companyId . '/contacts/' . $contactId, |
||
72 | 'logger' => $logger ?: $this->getLogger() |
||
73 | ]); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param CacheInterface $cache |
||
78 | * @param string|null $key |
||
79 | * @param LoggerInterface|null $logger |
||
80 | * @return $this |
||
81 | */ |
||
82 | protected function addCache(CacheInterface $cache, string $key = null, LoggerInterface $logger = null) |
||
83 | { |
||
84 | return $this->addAfter('cache', [ |
||
85 | 'class' => CacheMiddleware::class, |
||
86 | 'logger' => $logger ?: $this->getLogger(), |
||
87 | 'cache' => $cache, |
||
88 | 'key' => $key |
||
89 | ], 'body'); |
||
90 | } |
||
91 | } |