Last active
July 12, 2019 06:22
-
-
Save haxianhe/8f4f779ca1d702d86d51f3fac735e5f8 to your computer and use it in GitHub Desktop.
PHP 用trait实现的单例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait Service_Data_Base_Singleton | |
{ | |
private static $singleton; | |
private function __construct(){} | |
public static function getInstance() { | |
if( !(self::$singleton instanceof self) ) { | |
self::$singleton = new self(); | |
} | |
return self::$singleton; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Model_Rpc_Merchant extends Sflib_RpcBase | |
{ | |
use Service_Data_Base_Singleton; | |
public function getStockAlarmInfo( $shop_id ) { | |
$params = [ | |
'shop_id' => $shop_id | |
]; | |
$path = '/api/merchant/api/checkskustock'; | |
return $this->_get( $path, $params ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sku_info = Model_Rpc_Merchant::getInstance()->getSkuInfoWithShop( $shop_id, $sku_params ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment