Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
1c9798e9
Commit
1c9798e9
authored
Sep 22, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added comments to ioc container class.
parent
1a028e64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
11 deletions
+27
-11
container.php
laravel/container.php
+27
-11
No files found.
laravel/container.php
View file @
1c9798e9
...
...
@@ -21,6 +21,14 @@ class IoC {
/**
* Magic Method for calling methods on the active container instance.
*
* <code>
* // Call the "resolve" method on the active container
* $instance = IoC::resolve('laravel.routing.router');
*
* // Call the "instance" method on the active container
* IoC::instance('mailer', new Mailer);
* </code>
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
...
...
@@ -59,6 +67,14 @@ class Container {
/**
* Register an object and its resolver.
*
* The IoC container instance is always passed to the resolver, allowing the
* nested resolution of other objects from the container.
*
* <code>
* // Register an object and its resolver
* IoC::container()->register('mailer', function($c) {return new Mailer;});
* </code>
*
* @param string $name
* @param Closure $resolver
* @return void
...
...
@@ -100,6 +116,11 @@ class Container {
* This method allows you to register an already existing object instance
* with the container to be managed as a singleton instance.
*
* <code>
* // Register an instance as a singleton in the container
* IoC::container()->instance('mailer', new Mailer);
* </code>
*
* @param string $name
* @param mixed $instance
* @return void
...
...
@@ -110,7 +131,12 @@ class Container {
}
/**
* Resolve an object.
* Resolve an object instance from the container.
*
* <code>
* // Get an instance of the "mailer" object registered in the container
* $mailer = IoC::container()->resolve('mailer');
* </code>
*
* @param string $name
* @return mixed
...
...
@@ -129,14 +155,4 @@ class Container {
return
(
isset
(
$this
->
registry
[
$name
][
'singleton'
]))
?
$this
->
singletons
[
$name
]
=
$object
:
$object
;
}
/**
* Magic Method for resolving classes out of the IoC container.
*/
public
function
__get
(
$key
)
{
if
(
$this
->
registered
(
$key
))
return
$this
->
resolve
(
$key
);
throw
new
\Exception
(
"Attempting to resolve undefined class [
$key
]."
);
}
}
\ No newline at end of file
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