Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dependency-injector
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Flori
dependency-injector
Commits
6e0b890a
There was a problem fetching the pipeline stages.
Commit
6e0b890a
authored
8 years ago
by
Thomas Flori
Browse files
Options
Downloads
Patches
Plain Diff
add has and unset
parent
ec08f108
No related branches found
No related tags found
No related merge requests found
Pipeline
#246
passed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
composer.json
+1
-1
1 addition, 1 deletion
composer.json
src/DI.php
+26
-1
26 additions, 1 deletion
src/DI.php
tests/DependencyInjectorTest.php
+26
-12
26 additions, 12 deletions
tests/DependencyInjectorTest.php
with
53 additions
and
14 deletions
composer.json
+
1
−
1
View file @
6e0b890a
{
"name"
:
"tflori/dependency-injector"
,
"version"
:
"1.
1
.0"
,
"version"
:
"1.
2
.0"
,
"description"
:
"Easy and lightweight dependency injector"
,
"type"
:
"library"
,
"keywords"
:
[
...
...
This diff is collapsed.
Click to expand it.
src/DI.php
+
26
−
1
View file @
6e0b890a
...
...
@@ -70,7 +70,6 @@ class DI {
public
static
function
__callStatic
(
$name
,
$arguments
)
{
return
self
::
get
(
$name
);
}
/**
...
...
@@ -110,7 +109,33 @@ class DI {
self
::
$_instances
=
[];
self
::
$_dependencies
=
[];
}
/**
* Removes dependency $name
*
* @param string $name
*/
public
static
function
unset
(
$name
)
{
if
(
isset
(
self
::
$_instances
[
$name
]))
{
unset
(
self
::
$_instances
[
$name
]);
}
if
(
isset
(
self
::
$_dependencies
[
$name
]))
{
unset
(
self
::
$_dependencies
[
$name
]);
}
}
/**
* Checks if dependency $name is defined
*
* @param string $name
* @return bool
*/
public
static
function
has
(
$name
)
{
return
isset
(
self
::
$_instances
[
$name
])
||
isset
(
self
::
$_dependencies
[
$name
]);
}
private
function
__construct
()
{}
...
...
This diff is collapsed.
Click to expand it.
tests/DependencyInjectorTest.php
+
26
−
12
View file @
6e0b890a
...
...
@@ -14,7 +14,7 @@ class DependencyInjectorTest extends TestCase {
* Test that the setup works - the class should exist
*/
public
function
testSetUp
()
{
$this
->
assertTrue
(
class_exists
(
'DependencyInjector\DI'
));
self
::
assertTrue
(
class_exists
(
'DependencyInjector\DI'
));
}
/**
...
...
@@ -24,7 +24,7 @@ class DependencyInjectorTest extends TestCase {
$refDI
=
new
ReflectionClass
(
DI
::
class
);
$refConstruct
=
$refDI
->
getMethod
(
'__construct'
);
$this
->
assertTrue
(
$refConstruct
->
isPrivate
());
self
::
assertTrue
(
$refConstruct
->
isPrivate
());
}
/**
...
...
@@ -45,7 +45,7 @@ class DependencyInjectorTest extends TestCase {
DI
::
set
(
'something'
,
$something
);
$this
->
assertEquals
(
$something
,
DI
::
get
(
'something'
));
self
::
assertEquals
(
$something
,
DI
::
get
(
'something'
));
}
/**
...
...
@@ -58,7 +58,7 @@ class DependencyInjectorTest extends TestCase {
$result
=
DI
::
get
(
'anonymous'
);
$this
->
assertSame
(
'fooBar'
,
$result
);
self
::
assertSame
(
'fooBar'
,
$result
);
}
/**
...
...
@@ -71,7 +71,7 @@ class DependencyInjectorTest extends TestCase {
$calls
=
$calls
+
1
;
});
$this
->
assertSame
(
0
,
$calls
);
self
::
assertSame
(
0
,
$calls
);
}
/**
...
...
@@ -87,7 +87,7 @@ class DependencyInjectorTest extends TestCase {
DI
::
get
(
'callOnce'
);
DI
::
get
(
'callOnce'
);
$this
->
assertSame
(
1
,
$calls
);
self
::
assertSame
(
1
,
$calls
);
}
/**
...
...
@@ -103,7 +103,7 @@ class DependencyInjectorTest extends TestCase {
DI
::
get
(
'callTwice'
);
DI
::
get
(
'callTwice'
);
$this
->
assertSame
(
2
,
$calls
);
self
::
assertSame
(
2
,
$calls
);
}
/**
...
...
@@ -120,7 +120,7 @@ class DependencyInjectorTest extends TestCase {
});
$result2
=
DI
::
get
(
'microtime'
);
$this
->
assertNotSame
(
$result1
,
$result2
);
self
::
assertNotSame
(
$result1
,
$result2
);
}
/**
...
...
@@ -132,7 +132,7 @@ class DependencyInjectorTest extends TestCase {
/** @noinspection PhpUndefinedMethodInspection */
$result
=
DI
::
magicCall
();
$this
->
assertTrue
(
$result
);
self
::
assertTrue
(
$result
);
}
/**
...
...
@@ -151,7 +151,7 @@ class DependencyInjectorTest extends TestCase {
$result
=
DI
::
get
(
strtolower
(
__CLASS__
));
$this
->
assertNotSame
(
strtolower
(
__CLASS__
),
$result
);
self
::
assertNotSame
(
strtolower
(
__CLASS__
),
$result
);
}
/**
...
...
@@ -162,7 +162,7 @@ class DependencyInjectorTest extends TestCase {
$result
=
DI
::
get
(
__CLASS__
);
$this
->
assertSame
(
'FooBar'
,
$result
);
self
::
assertSame
(
'FooBar'
,
$result
);
}
/**
...
...
@@ -176,6 +176,20 @@ class DependencyInjectorTest extends TestCase {
DI
::
reset
();
$this
->
assertSame
(
__CLASS__
,
DI
::
get
(
__CLASS__
));
self
::
assertSame
(
__CLASS__
,
DI
::
get
(
__CLASS__
));
}
public
function
testHas
()
{
DI
::
set
(
'foo'
,
'bar'
);
self
::
assertTrue
(
DI
::
has
(
'foo'
));
}
public
function
testUnset
()
{
DI
::
set
(
'foo'
,
'bar'
);
DI
::
unset
(
'foo'
);
self
::
assertFalse
(
DI
::
has
(
'foo'
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment