<commit_before><?php

declare(strict_types=1);

/**
 * @copyright   Copyright (c) 2017 gameeapp.<EMAIL> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 * @package     Gamee
 */

namespace Gamee\RabbitMQ\Producer;

use Gamee\RabbitMQ\Exchange\Exchange;
use Gamee\RabbitMQ\Queue\Queue;

final class Producer
{

	public const DELIVERY_MODE_NON_PERSISTENT = 1;
	public const DELIVERY_MODE_PERSISTENT = 2;

	/**
	 * @var Exchange|NULL
	 */
	private $exchange;

	/**
	 * @var Queue|NULL
	 */
	private $queue;

	/**
	 * @var string
	 */
	private $contentType;

	/**
	 * @var string
	 */
	private $deliveryMode;


	public function __construct(
		Exchange $exchange = null,
		Queue $queue = null,
		string $contentType,
		int $deliveryMode
	) {
		$this->exchange = $exchange;
		$this->queue = $queue;
		$this->contentType = $contentType;
		$this->deliveryMode = $deliveryMode;
	}


	public function publish(string $message, array $headers = []): void
	{
		$headers = array_merge($this->getBasicHeaders(), $headers);

		if ($this->queue) {
			$this->publishToQueue($message, $headers);
		}

		if ($this->exchange) {
			$this->publishToExchange($message, $headers);
		}
	}


	private function getBasicHeaders(): array
	{
		return [
			'content_type' => $this->contentType,
			'delivery_mode' => $this->deliveryMode
		];
	}


	private function publishToQueue(string $message, array $headers = []): void
	{
		$this->queue->getConnection()->getChannel()->publish(
			$message,
			$headers,
			'', // Exchange name
			$this->queue->getName() // Routing key, in this case the queue's name
		);
	}


	private function publishToExchange(string $message, array $headers = []): void<commit_msg>Properties should use dash not underscore.<commit_after><?php

declare(strict_types=1);

/**
 * @copyright   Copyright (c) 2017 game<EMAIL> <<EMAIL>>
 * @author      <NAME> <<EMAIL>>
 * @package     Gamee
 */

namespace Gamee\RabbitMQ\Producer;

use Gamee\RabbitMQ\Exchange\Exchange;
use Gamee\RabbitMQ\Queue\Queue;

final class Producer
{

	public const DELIVERY_MODE_NON_PERSISTENT = 1;
	public const DELIVERY_MODE_PERSISTENT = 2;

	/**
	 * @var Exchange|NULL
	 */
	private $exchange;

	/**
	 * @var Queue|NULL
	 */
	private $queue;

	/**
	 * @var string
	 */
	private $contentType;

	/**
	 * @var string
	 */
	private $deliveryMode;


	public function __construct(
		Exchange $exchange = null,
		Queue $queue = null,
		string $contentType,
		int $deliveryMode
	) {
		$this->exchange = $exchange;
		$this->queue = $queue;
		$this->contentType = $contentType;
		$this->deliveryMode = $deliveryMode;
	}


	public function publish(string $message, array $headers = []): void
	{
		$headers = array_merge($this->getBasicHeaders(), $headers);

		if ($this->queue) {
			$this->publishToQueue($message, $headers);
		}

		if ($this->exchange) {
			$this->publishToExchange($message, $headers);
		}
	}


	private function getBasicHeaders(): array
	{
		return [
			'content-type' => $this->contentType,
			'delivery-mode' => $this->deliveryMode
		];
	}


	private function publishToQueue(string $message, array $headers = []): void
	{
		$this->queue->getConnection()->getChannel()->publish(
			$message,
			$headers,
			'', // Exchange name
			$this->queue->getName() // Routing key, in this case the queue's name
		);
	}


	private function publishToExchange(string $message, array $headers = []): void
{'fraction_non_alphanumeric': 0.15517241379310345, 'fraction_numerical': 0.004161712247324614, 'mean_word_length': 3.76628895184136, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4979425', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1114, 'n_words': 248}