Skip to content

Commit 9ac7e72

Browse files
author
Ethan
committed
container
1 parent 806b4e8 commit 9ac7e72

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Builder.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PFinal\Database;
44

55
use Closure;
6+
use Pimple\Psr11\Container;
67

78
/**
89
* 数据库操作辅助类
@@ -21,6 +22,9 @@ class Builder
2122
/** @var static */
2223
protected static $instance;
2324

25+
/** @var Container */
26+
protected static $container;
27+
2428
/** @var Connection 数据库连接对象 */
2529
private $db;
2630

@@ -66,12 +70,24 @@ public function setAsGlobal()
6670
return $this;
6771
}
6872

73+
/**
74+
* @param Container $container
75+
*/
76+
public static function setContainer($container)
77+
{
78+
static::$container = $container;
79+
}
80+
6981
/**
7082
* @return static
7183
*/
7284
public static function getInstance()
7385
{
74-
return static::$instance;
86+
if (static::$instance instanceof Builder) {
87+
return static::$instance;
88+
}
89+
90+
return static::$container->get('PFinal\Database\Builder');
7591
}
7692

7793
/**

0 commit comments

Comments
 (0)