<?php
/**
 * Description of Singleton.php
 *
 * @author caoyunmeng
 * Date: 2021/3/6
 * Time: 5:38 PM
 */

namespace Api\PhpUtils\Kafka;

class Singleton
{
    /**
     * The actual singleton's instance almost always resides inside a static
     * field. In this case, the static field is an array, where each subclass of
     * the Singleton stores its own instance.
     */
    private static $instances = null;

    /**
     * Singleton's constructor should not be public. However, it can't be
     * private either if we want to allow subclassing.
     */
    protected function __construct() { }

    /**
     * Cloning and unserialization are not permitted for singletons.
     */
    protected function __clone() { }

    /**
     * 防止反序列化
     */
    public function __wakeup() { }

    /**
     * The method you use to get the Singleton's instance.
     */
    public static function getInstance($delivery_callback = false, $context = false, $conf = false)
    {
        if(self::$instances === null){
            self::$instances = new static($delivery_callback, $context, $conf);
        }

        return self::$instances;
    }
}

