PHP code example of itxq / singleton-pattern-php

1. Go to this page and download the library: Download itxq/singleton-pattern-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

itxq / singleton-pattern-php example snippets




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());


// 引入扩展(具体路径请根据你的目录结构自行修改)