<?php

namespace Heanup\Frame;

/**
 * 数据层父类
 * Class Package
 * @package Heanup\Frame
 */
class Package
{
    const PREFIX = '';

    /**
     * 创建单例模式
     * @return Package
     */
    public static function getInstance()
    {
        static $pool;
        $class = get_called_class();
        if (!isset($pool[$class])) {
            $pool[$class] = new $class();
        }
        return $pool[$class];
    }

    /**
     * 获取带前缀的key
     * @param $id
     * @return string
     */
    protected static function getKey($id = 0)
    {
        $class = get_called_class();
        if (!$class::PREFIX) {
            $prefix = substr(md5($class), 0, 16);
        } else {
            $prefix = $class::PREFIX;
        }
        $prefix = strtolower($prefix);
        $key = trim($prefix, ':') . ':' . $id;
        return $key;
    }

    /**
     * 获取发号器ID
     * @return mixed
     * @throws \Exception
     */
    protected static function getTicket()
    {
        return \Heanup\Frame\Library\Ticket::getTicket();
    }

}