2024-05-28 04:07:04 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-30 08:42:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2024-05-28 04:07:04 -04:00
|
|
|
*/
|
|
|
|
|
|
2024-05-30 08:42:41 -04:00
|
|
|
namespace OCA\Webhooks\Command;
|
|
|
|
|
|
|
|
|
|
use OC\Core\Command\Base;
|
|
|
|
|
use OCA\Webhooks\Db\WebhookListener;
|
|
|
|
|
use OCA\Webhooks\Db\WebhookListenerMapper;
|
2024-05-28 04:07:04 -04:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
2024-06-06 05:06:58 -04:00
|
|
|
class ListWebhooks extends Base {
|
2024-05-30 08:42:41 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private WebhookListenerMapper $mapper,
|
|
|
|
|
) {
|
2024-05-28 04:07:04 -04:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 08:42:41 -04:00
|
|
|
protected function configure(): void {
|
|
|
|
|
parent::configure();
|
2024-05-28 04:07:04 -04:00
|
|
|
$this
|
2024-05-30 08:42:41 -04:00
|
|
|
->setName('webhooks:list')
|
|
|
|
|
->setDescription('Lists configured webhooks');
|
2024-05-28 04:07:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2024-05-30 08:42:41 -04:00
|
|
|
$webhookListeners = array_map(
|
2024-06-03 11:11:52 -04:00
|
|
|
fn (WebhookListener $listener): array => array_map(
|
|
|
|
|
fn (string|array|null $value): ?string => (is_array($value) ? json_encode($value) : $value),
|
|
|
|
|
$listener->jsonSerialize()
|
|
|
|
|
),
|
2024-05-30 08:42:41 -04:00
|
|
|
$this->mapper->getAll()
|
2024-05-28 04:07:04 -04:00
|
|
|
);
|
2024-05-30 08:42:41 -04:00
|
|
|
$this->writeTableInOutputFormat($input, $output, $webhookListeners);
|
|
|
|
|
return static::SUCCESS;
|
2024-05-28 04:07:04 -04:00
|
|
|
}
|
|
|
|
|
}
|