定制 okapi/singleton 二次开发

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

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

okapi/singleton

最新稳定版本:1.0.3

Composer 安装命令:

composer require okapi/singleton

包简介

PHP Singleton is a PHP library that allows you to create singleton classes with a trait.

README 文档

README

PHP Singleton

License: MIT Twitter: @WalterWoshid PHP: >=8.0 Packagist Build

Coverage - PHP 8.0 Coverage - PHP 8.1 Coverage - PHP 8.2

PHP Singleton is a PHP library that allows you to create singleton classes with a trait.

Installation

composer require okapi/singleton

Usage

<?php use Okapi\Singleton\Singleton; class GovernmentOfUSA { // Add the singleton trait use Singleton; /**  * Function to register the singleton.   *   * This function and the "initialized" methods are completely optional.  *   * Can be static or non-static.   */ public static function register(): void { // Get instance $instance = self::getInstance(); // For non-static just use $this // Make sure the instance is only registered once $instance->ensureNotInitialized(); // Do something // ... // Mark the instance as initialized $instance->setInitialized(); } /**  * Custom function  */ public function takeOverTheWorld(): void { // Make sure the instance is initialized $this->ensureInitialized(); // Do something // ... } } // Other file // Register the singleton GovernmentOfUSA::register(); // Take over the world $instance = GovernmentOfUSA::getInstance(); $instance->takeOverTheWorld(); // or GovernmentOfUSA::getInstance()->takeOverTheWorld();

Testing

  • Run composer run-script test
    or
  • Run composer run-script test-coverage

Show your support

Give a ⭐ if this project helped you!

???? License

Copyright © 2023 Valentin Wotschel.
This project is MIT licensed.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固