<?php
/**
 * Lightweight dependency container.
 *
 * @package Noesia_Commerce_Suite
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Lightweight application container for Noesia Commerce Suite.
 *
 * This is intentionally small: it centralizes service/repository instances
 * without introducing a heavy framework into a WordPress plugin.
 */
class Noesia_CS_Container {
	/**
	 * Registered container items.
	 *
	 * @var array<string,mixed>
	 */
	private $items = array();

	/**
	 * Store a service/value by key.
	 *
	 * @param string $key   Container key.
	 * @param mixed  $value Stored value.
	 * @return void
	 */
	public function set( $key, $value ) {
		$key = sanitize_key( $key );
		if ( ! $key ) {
			return;
		}
		$this->items[ $key ] = $value;
	}

	/**
	 * Retrieve a value by key.
	 *
	 * @param string $key Container key.
	 * @return mixed|null
	 */
	public function get( $key ) {
		$key = sanitize_key( $key );
		return isset( $this->items[ $key ] ) ? $this->items[ $key ] : null;
	}

	/**
	 * Check whether a key exists.
	 *
	 * @param string $key Container key.
	 * @return bool
	 */
	public function has( $key ) {
		$key = sanitize_key( $key );
		return isset( $this->items[ $key ] );
	}

	/**
	 * Return all registered values.
	 *
	 * @return array<string,mixed>
	 */
	public function all() {
		return $this->items;
	}
}
