|
4 | 4 |
|
5 | 5 | namespace Database\Service;
|
6 | 6 |
|
7 |
| -use Database\Form\DeleteList as DeleteListForm; |
8 |
| -use Database\Form\MailingList as MailingListForm; |
| 7 | +use Database\Form\{ |
| 8 | + DeleteList as DeleteListForm, |
| 9 | + MailingList as MailingListForm, |
| 10 | +}; |
9 | 11 | use Database\Mapper\MailingList as MailingListMapper;
|
10 | 12 | use Database\Model\MailingList as MailingListModel;
|
| 13 | +use Laminas\Http\{ |
| 14 | + Client, |
| 15 | + Client\Adapter\Curl, |
| 16 | + Request, |
| 17 | + Response}; |
| 18 | +use RuntimeException; |
11 | 19 |
|
12 | 20 | class MailingList
|
13 | 21 | {
|
14 | 22 | public function __construct(
|
15 | 23 | private readonly DeleteListForm $deleteListForm,
|
16 | 24 | private readonly MailingListForm $mailingListForm,
|
17 | 25 | private readonly MailingListMapper $mailingListMapper,
|
| 26 | + private readonly array $mailmanConfig, |
18 | 27 | ) {
|
19 | 28 | }
|
20 | 29 |
|
@@ -78,6 +87,48 @@ public function delete(
|
78 | 87 | return true;
|
79 | 88 | }
|
80 | 89 |
|
| 90 | + /** |
| 91 | + * @param string $uri |
| 92 | + * @param string $method - Request::METHOD_GET |
| 93 | + * |
| 94 | + * @throws RuntimeException |
| 95 | + * |
| 96 | + * @return Response |
| 97 | + */ |
| 98 | + private function createMailmanRequest( |
| 99 | + string $uri, |
| 100 | + string $method = Request::METHOD_GET, |
| 101 | + string $encoding = 'application/json', |
| 102 | + array $data = [], |
| 103 | + ): Response { |
| 104 | + $client = new Client(); |
| 105 | + $request = new Request(); |
| 106 | + |
| 107 | + $request->setMethod($method) |
| 108 | + ->setUri($this->mailmanConfig['endpoint'] . $uri); |
| 109 | + $client->setAdapter(Curl::class) |
| 110 | + ->setAuth($this->mailmanConfig['username'], $this->mailmanConfig['password']) |
| 111 | + ->setEncType($encoding); |
| 112 | + |
| 113 | + switch ($method) { |
| 114 | + case Request::METHOD_GET: |
| 115 | + $client->setParameterGet($data); |
| 116 | + break; |
| 117 | + case Request::METHOD_POST: |
| 118 | + $client->setParameterPost($data); |
| 119 | + break; |
| 120 | + } |
| 121 | + |
| 122 | + return $client->send($request); |
| 123 | + } |
| 124 | + |
| 125 | + public function getAllListsFromMailman(): array |
| 126 | + { |
| 127 | + $client = $this->createMailmanRequest('lists'); |
| 128 | + |
| 129 | + try |
| 130 | + } |
| 131 | + |
81 | 132 | /**
|
82 | 133 | * Get the delete list form.
|
83 | 134 | */
|
|
0 commit comments