Singleton单例

参考Demo: rpcServer

EasySwoole提供了trait写法的单例,只需要在类里面use Singleton;该类即可实现单例模式. 例如在demo中的rpcServer中,就使用了单例模式:

<?php
/**
 * Created by PhpStorm.
 * User: Apple
 * Date: 2018/11/27 0027
 * Time: 12:19
 */
namespace App\Rpc;
use EasySwoole\Component\Singleton;
use EasySwoole\Rpc\Rpc;
class RpcServer extends Rpc
{
    use Singleton;
}

调用:

<?php
 $rpc = \App\Rpc\RpcServer::getInstance($rpcConfig);

results matching ""

    No results matching ""