-
Notifications
You must be signed in to change notification settings - Fork 0
/
MdCallsService.php
47 lines (36 loc) · 1.15 KB
/
MdCallsService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Created by PhpStorm.
* User: seven
* Date: 2019/1/29
* Time: 10:36
*/
namespace kickPeach\mdCalls;
use kickPeach\mdCalls\Exceptions\MdCallsException;
abstract class MdCallsService
{
//单例模式
private function __clone(){}
private static $mdCallsInstance;
private function __construct(){}
public static function getInstance()
{
if (empty(self::$mdCallsInstance)) {
self::$mdCallsInstance = new static();
}
return self::$mdCallsInstance;
}
protected $mdCallsNamespace;
public function __get($moduleName)
{
$moduleName = ucfirst($moduleName);
if (property_exists($this,$moduleName)) {
throw new MdCallsException("Module name {$moduleName} should begin with a captian letter");
}
$className = $this->mdCallsNamespace . '\Service\\' .$moduleName.'\\'.$moduleName.'Index';
$this->$moduleName = new $className();
$this->$moduleName->mdc = $this;
$this->$moduleName->initService($this->mdCallsNamespace,$moduleName);
return $this->$moduleName;
}
}