Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
4086d130
Commit
4086d130
authored
Apr 02, 2013
by
Steven Klar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unregister to IoC-Contrainer
Signed-off-by: Steven Klar <steven.klar@mayflower.de>
parent
e86532e0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
laravel/documentation/ioc.md
+10
-0
laravel/ioc.php
+15
-0
laravel/tests/cases/ioc.test.php
+14
-0
No files found.
laravel/documentation/ioc.md
View file @
4086d130
...
@@ -47,3 +47,12 @@ Now that we have SwiftMailer registered in the container, we can resolve it usin
...
@@ -47,3 +47,12 @@ Now that we have SwiftMailer registered in the container, we can resolve it usin
$mailer = IoC::resolve('mailer');
$mailer = IoC::resolve('mailer');
> **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection).
> **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection).
<a
name=
"unregister"
></a>
## Unregister an existing instance
For test purposes sometimes you need to unregister some container.
#### Unregister example mail class:
IoC::unregister('mailer');
\ No newline at end of file
laravel/ioc.php
View file @
4086d130
...
@@ -32,6 +32,19 @@ class IoC {
...
@@ -32,6 +32,19 @@ class IoC {
}
}
/**
/**
* Unregister an object
*
* @param string $name
*/
public
static
function
unregister
(
$name
)
{
if
(
array_key_exists
(
$name
,
static
::
$registry
))
{
unset
(
static
::
$registry
[
$name
]);
unset
(
static
::
$singletons
[
$name
]);
}
}
/**
* Determine if an object has been registered in the container.
* Determine if an object has been registered in the container.
*
*
* @param string $name
* @param string $name
...
@@ -141,6 +154,7 @@ class IoC {
...
@@ -141,6 +154,7 @@ class IoC {
* @param string $type
* @param string $type
* @param array $parameters
* @param array $parameters
* @return mixed
* @return mixed
* @throws \Exception
*/
*/
protected
static
function
build
(
$type
,
$parameters
=
array
())
protected
static
function
build
(
$type
,
$parameters
=
array
())
{
{
...
@@ -218,6 +232,7 @@ class IoC {
...
@@ -218,6 +232,7 @@ class IoC {
*
*
* @param ReflectionParameter
* @param ReflectionParameter
* @return default value
* @return default value
* @throws \Exception
*/
*/
protected
static
function
resolveNonClass
(
$parameter
)
protected
static
function
resolveNonClass
(
$parameter
)
{
{
...
...
laravel/tests/cases/ioc.test.php
View file @
4086d130
...
@@ -28,6 +28,7 @@ class TestClassTwoForIoC
...
@@ -28,6 +28,7 @@ class TestClassTwoForIoC
}
}
}
}
use
\Laravel\IoC
as
IoC
;
class
IoCTest
extends
PHPUnit_Framework_TestCase
{
class
IoCTest
extends
PHPUnit_Framework_TestCase
{
...
@@ -150,4 +151,17 @@ class IoCTest extends PHPUnit_Framework_TestCase {
...
@@ -150,4 +151,17 @@ class IoCTest extends PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
42
,
$class_two
->
class_one
->
test_variable
);
$this
->
assertEquals
(
42
,
$class_two
->
class_one
->
test_variable
);
}
}
public
function
testCanUnregisterRegistered
()
{
$testClass
=
'test'
;
IoC
::
register
(
$testClass
,
function
()
{});
$this
->
assertTrue
(
IoC
::
registered
(
$testClass
));
IoC
::
unregister
(
$testClass
);
$this
->
assertFalse
(
IoC
::
registered
(
$testClass
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment