Recommend this page to a friend! |
![]() ![]() |
Info | ![]() |
![]() |
![]() ![]() |
Reputation | Support forum (1) | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-11-11 (1 month ago) ![]() | Not enough user ratings | Total: 46 This week: 1 | All time: 10,660 This week: 108![]() |
Version | License | PHP version | Categories | |||
simple-container 1.0.0 | MIT/X Consortium ... | 5 | PHP 5, Data types, Design Patterns |
Description | Author | |
This package can inject classes and create objects using containers. |
|
This is about the simple container to help developers to understand how the Reflection works.
Firstly, you have to specify a class that you want to inject.
For example, we assume that you want to inject following Profile
class:
class Profile
{
protected $userName;
public function __construct($userName = 'lee')
{
$this->userName = $userName;
}
public function getUserName()
{
return $this->userName;
}
}
Then we use the Container
class to inject this Profile
class.
use Lee\Container\Container;
$container = new Container();
$container->set(Profile::class);
$profile = $container->get(Profile::class);
echo $profile->getUserName(); // lee
If you want to inject class that its constructor arguments is without the default value, we should specify them by ourselves.
The sample codes are as follows:
class Profile
{
protected $userName;
public function __construct($userName)
{
$this->userName = $userName;
}
public function getUserName()
{
return $this->userName;
}
}
Then we use Container
class to inject this class.
use Lee\Container\Container;
$container = new Container();
$container->set(Profile::class);
$profile = $container->get(Profile::class, ['userName' => 'Peter']);
echo $profile->getUserName(); // Peter
This simple-container is about implementing this post.
However, this post we refer is incorrect on some approaches.
We decide to implement this PHP package to complete the correct container example.
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Comments (1) | |||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.