You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
namespace Base\Factory;
|
|
|
|
use Base\Factory\LeavePercentageFactory;
|
|
use Base\Factory\SpecialCompoentFactory;
|
|
use Base\Factory\SpecialCompoentCaculateFactory;
|
|
|
|
class BaseFactory {
|
|
|
|
private static $instance ;
|
|
private $suffix = "Factory";
|
|
|
|
public $classes = [
|
|
'LeavePercentageFactory' => LeavePercentageFactory::class,
|
|
'SpecialCompoentFactory' => SpecialCompoentFactory::class,
|
|
'SpecialCompoentCaculateFactory' => SpecialCompoentCaculateFactory::class,
|
|
'MarketPercentageFactory' => MarketPercentageFactory::class,
|
|
];
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
//获取实例化接口
|
|
static function getInstance() {
|
|
|
|
if (!(self::$instance instanceof self)) {
|
|
self::$instance = new self();
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
//工厂类返回实例化类
|
|
public function factoryClass($name = '') {
|
|
|
|
if (!$name) {
|
|
return false;
|
|
}
|
|
|
|
$className = "{$name}{$this->suffix}";
|
|
|
|
if ($this->classes[$className]) {
|
|
return (new $this->classes[$className]);
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
} |