<?php
/**
 * Capability registry.
 *
 * @package SwairishXHeaderBarNotificationOffer
 */

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

class SwairishX_Registry {
    private $items = array();

    public function register($kind, $id, array $definition) {
        $kind = sanitize_key($kind);
        $id = sanitize_key($id);
        if (!$kind || !$id) {
            return false;
        }
        $definition['id'] = $id;
        $definition['kind'] = $kind;
        $definition['package'] = isset($definition['package']) ? sanitize_key($definition['package']) : 'free';
        $this->items[$kind][$id] = $definition;
        return true;
    }

    public function get($kind, $id) {
        $kind = sanitize_key($kind);
        $id = sanitize_key($id);
        return isset($this->items[$kind][$id]) ? $this->items[$kind][$id] : null;
    }

    public function all($kind) {
        $kind = sanitize_key($kind);
        return isset($this->items[$kind]) ? $this->items[$kind] : array();
    }

    public function has($kind, $id) {
        return null !== $this->get($kind, $id);
    }
}
