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.

45 lines
857 B
PHTML

<?php
namespace Base\Factory;
use Base\Factory\LeavePercentageFactory;
class BaseFactory {
private static $instance ;
private $suffix = "Factory";
public $classes = [
'LeavePercentageFactory' => LeavePercentageFactory::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;
}
}
}