Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

829 B
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Services\Infrastructure\Webhook\DTO;

use HiEvents\DataTransferObjects\BaseDataObject;

class WebhookTargetDTO extends BaseDataObject
{
    public function __construct(
        public string $host,
        public int $port,
        /** @var array<int, string> */
        public array $ipAddresses,
    ) {}

    /**
     * @return array<int, string> a single curl CURLOPT_RESOLVE entry pinning the host to every address validated here.
     */
    public function toCurlResolveEntries(): array
    {
        $addresses = array_map(
            fn (string $ipAddress) => str_contains($ipAddress, ':') ? '['.$ipAddress.']' : $ipAddress,
            $this->ipAddresses,
        );

        return [sprintf('%s:%d:%s', $this->host, $this->port, implode(',', $addresses))];
    }
}