Coder Social home page Coder Social logo

singleton-pattern-php's Introduction

PHP 单例设计trait

PHP Version Latest Stable Version Total Downloads Latest Unstable Version License composer.lock available

开源地址:

【GitHub:】https://github.com/itxq/singleton-pattern-php

扩展安装:

  • 方法一:composer命令 composer require itxq/singleton-pattern-php

  • 方法二:直接下载压缩包,然后进入项目中执行 composer命令 composer update 来生成自动加载文件

引用扩展:

  • 当你的项目不支持composer自动加载时,可以使用以下方式来引用该扩展包
// 引入扩展(具体路径请根据你的目录结构自行修改)
require_once __DIR__ . '/vendor/autoload.php';

使用示例:

<?php

namespace test;

use itxq\traits\SingletonPattern;

class TestClass
{
    use SingletonPattern;

    public function test(): string
    {
        return '1008611';
    }
}
// 获取实例并传入配置
var_dump(TestClass::make(['b' => '123']));

// 传入配置
TestClass::make()->setConfig('a', 'ccc');

// 获取配置
var_dump(TestClass::make()->getConfig());

// 直接运行方法
var_dump(TestClass::make()->test());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.