headless_cms-1.0.3/modules/headless_cms_notify_webhook/src/HeadlessNotifyWebhookQueueItem.php

modules/headless_cms_notify_webhook/src/HeadlessNotifyWebhookQueueItem.php
<?php

declare(strict_types=1);

namespace Drupal\headless_cms_notify_webhook;

use Drupal\Component\Serialization\Json;

/**
 * Defines a headless notification queue item.
 */
class HeadlessNotifyWebhookQueueItem {

  public function __construct(
    public readonly string $url,
    public readonly string $json,
  ) {}

  /**
   * Get the queue item as array.
   */
  public function toArray(): array {
    return [
      'url' => $this->url,
      'message' => $this->json,
    ];
  }

  /**
   * Get the queue item as JSON.
   */
  public function toJson(): string {
    return Json::encode($this->toArray());
  }

  /**
   * Create a new queue item from an array.
   */
  public static function fromArray(array $data): static {
    return new static(
      $data['url'],
      $data['message'],
    );
  }

  /**
   * Create a new queue item from JSON.
   */
  public static function fromJson(string $json): static {
    return self::fromArray(Json::decode($json));
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc