HEX
Server: Apache
System: Linux p3plzcpnl506847.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: slfopp7cb1df (5698090)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //proc/self/cwd/wp-content/plugins/kadence-blocks/includes/resources/Notice/Notice_Handler.php
<?php declare( strict_types=1 );

namespace KadenceWP\KadenceBlocks\Notice;

use KadenceWP\KadenceBlocks\StellarWP\Uplink\Notice\Notice;
use KadenceWP\KadenceBlocks\StellarWP\Uplink\Notice\Notice_Controller;

/**
 * Handles rendering multiple admin notices at once.
 */
final class Notice_Handler {

	/**
	 * Controller responsible for rendering notices.
	 */
	private Notice_Controller $controller;

	/**
	 * @var Notice[]
	 */
	private array $notices = [];

	public function __construct( Notice_Controller $controller ) {
		$this->controller = $controller;
	}

	/**
	 * Add a notice to the stack.
	 *
	 * @param  Notice  $notice
	 *
	 * @return self
	 */
	public function add( Notice $notice ): self {
		$this->notices[] = $notice;

		return $this;
	}

	/**
	 * Display all notices in the stack.
	 */
	public function display(): void {
		if ( count( $this->notices ) <= 0 ) {
			return;
		}

		foreach ( $this->notices as $notice ) {
			$this->controller->render( $notice->toArray() );
		}
	}

	/**
	 * Get all the notices.
	 *
	 * @return Notice[]
	 */
	public function all(): array {
		return $this->notices;
	}

	/**
	 * Clear all notices in the stack.
	 */
	public function clear(): self {
		$this->notices = [];

		return $this;
	}

}