mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Update Container DI to able unbind resolved entry (#4683)
* Added `Container::unset()` to unbind an arbitrary resolved entry. Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
f28f811b86
commit
cd6b3e7a8c
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
||||
matrix:
|
||||
os: [ ubuntu-latest ]
|
||||
php-version: [ '7.4', '8.0' ]
|
||||
sw-version: [ 'v4.5.11', 'v4.6.7', 'v4.7.1', 'v4.8.7', 'master' ]
|
||||
sw-version: [ 'v4.5.11', 'v4.6.7', 'v4.7.1', 'v4.8.8', 'master' ]
|
||||
exclude:
|
||||
- php-version: '7.4'
|
||||
sw-version: 'master'
|
||||
|
@ -8,6 +8,7 @@
|
||||
## Added
|
||||
|
||||
- [#4576](https://github.com/hyperf/hyperf/pull/4576) Support `path_prefix` for `node` when using `rpc-client`.
|
||||
- [#4683](https://github.com/hyperf/hyperf/pull/4683) Added `Container::unbind()` to unbind an arbitrary resolved entry.
|
||||
|
||||
# v2.2.30 - 2022-04-04
|
||||
|
||||
|
@ -38,6 +38,11 @@ interface ContainerInterface extends PsrContainerInterface
|
||||
*/
|
||||
public function set(string $name, $entry);
|
||||
|
||||
/**
|
||||
* Unbind an arbitrary resolved entry.
|
||||
*/
|
||||
public function unbind(string $name);
|
||||
|
||||
/**
|
||||
* Bind an arbitrary definition to an identifier.
|
||||
* Useful for testing 'make'.
|
||||
|
@ -92,6 +92,16 @@ class Container implements HyperfContainerInterface
|
||||
$this->resolvedEntries[$name] = $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind an arbitrary resolved entry.
|
||||
*/
|
||||
public function unbind(string $name)
|
||||
{
|
||||
if ($this->has($name)) {
|
||||
unset($this->resolvedEntries[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind an arbitrary definition to an identifier.
|
||||
* Useful for testing 'make'.
|
||||
|
@ -66,4 +66,16 @@ class ContainerTest extends TestCase
|
||||
{
|
||||
$this->assertInstanceOf(Container::class, new ContainerProxy());
|
||||
}
|
||||
|
||||
public function testUnset()
|
||||
{
|
||||
$container = new Container(new DefinitionSource([]));
|
||||
|
||||
$container->set('test', $id = uniqid());
|
||||
$this->assertTrue($container->has('test'));
|
||||
$this->assertSame($id, $container->get('test'));
|
||||
|
||||
$container->unbind('test');
|
||||
$this->assertFalse($container->has('test'));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user