Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
webguosai committed Oct 27, 2022
1 parent 7f76b4f commit b0287e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Container
* 绑定到容器
* @param mixed $abstract
* @param null $concrete
* @return $this
* @return null
*/
public function bind($abstract, $concrete = null)
{
Expand All @@ -38,21 +38,20 @@ public function bind($abstract, $concrete = null)

$this->bindings[$abstract] = $concrete;
}

return $this;
}

/**
* 取出容器中的数据
* @param mixed $abstract
* @param array $params
* @return mixed|object|$abstract
* @return mixed
*/
public function make($abstract, $params = [])
{
// if (!isset($this->bindings[$abstract])) {
// throw new \Exception('没有在容器中找到');
// }
// 容器中没有就绑定
if (!isset($this->bindings[$abstract])) {
$this->bind($abstract);
}

$concrete = $this->bindings[$abstract];
if ($concrete instanceof \Closure) {
Expand All @@ -70,7 +69,7 @@ public function make($abstract, $params = [])

/**
* 获取实例
* @return $this
* @return static
*/
public static function getInstance()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
//Container::getInstance()->bind('test', 111);
//Container::getInstance()->bind('test', [1,2,3,4]);
//Container::getInstance()->bind('test', function(){
// return 'sb';
// return 'test';
//});
//Container::getInstance()->bind([
// 'test' => [1,2,3,4],
// 'test2' => 'this is test2'
//]);
//Container::getInstance()->bind(Faker::class);
//dump(Container::getInstance()->bindings);
//dump(Container::getInstance()->make(Faker::class));



//Container::getInstance()->bind('cache', function($name, $name2){return 'cache '.$name.' '. $name2;});
Expand Down

0 comments on commit b0287e5

Please sign in to comment.