定制 phptailors/singleton-interface 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phptailors/singleton-interface

最新稳定版本:1.0.1

Composer 安装命令:

composer require phptailors/singleton-interface

包简介

Singleton Interface

README 文档

README

PHPUnit Composer Require Checker BC Check Psalm PHP CS Fixer

phptailors/singleton-interface

A PHP Interface for Singletons. See SingletonInterface.

Installation

composer require --dev "phptailors/singleton-interface:^1.0"
composer require --dev "phpunit/phpunit"

Usage

A minimal implementation (example):

<?php

use Tailors\Lib\Singleton\SingletonInterface;
use Tailors\Lib\Singleton\SingletonException;

final class MySingleton implements SingletonInterface
{
    private static ?MySingleton $instance = null;

    public static function getInstance(): MySingleton
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    private function __construct() {}

    private function __clone() {}

    public function __wakeup()
    {
        throw new SingletonException('Cannot unserialize singleton '.self::class);
    }
}

Expected features of a Singleton

A real Singleton in PHP:

  1. Should NOT be extendable (should be final).
  2. Should have a private constructor (__construct()).
  3. Its getInstance() should return a single instance of its class.
  4. Should NOT be cloneable (__clone() should be a private method).
  5. Should always throw Tailors\Lib\Singleton\SingletonException on unserialize() (from __wakeup()).

Testing Singleton behavior

The behavior of a Singleton may be tested using phptailors/singleton-testing.

统计信息

  • 总下载量: 910
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-03-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固