Download .zip |
Info | Documentation | View files (3) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2017-10-05 (12 days ago) | Not yet rated by the users | Total: Not yet counted | Not yet ranked |
Version | License | PHP version | Categories | |||
container 1.0 | GNU General Publi... | 7 | PHP 5, Language, Design Patterns |
Description | Author | |
This class can register and get service container classes. |
Container gives you a small dependency injetion to use in your projects
Run 'composer require saiik\container' and include your autoload.php
The container class needs at least 1 parameter. The first parameter defines the "namespace" for your container. The 2nd one is a configuration array.
Example:
$container = new saiik\Container(
'app',
[
'mockup' => true,
'cache' => 'var/cache/proxies/%s.php'
]
);
To register a new instance you can do it in 2 ways.
__When your class has dependencies on other classes, it will resolve them automatically.__
_In case you have dependencies on interfaces or an abstract class, you can set "mockup" in your configuration to true and it will mock up your interface / abstract class._
You can use the register method. This method expects at least 2 parameters.
Example:
$container->register('controller', Controller::lass);
With args:
$container->register('view', Blade::class, ['templatePath' => __DIR__]);
Also you can handle the container object as an array and register objects without any functions.
Example:
$container['contoller'] = Controller::class;
With args:
$container['view'] = [
Blade::class,
[
'templatePath' => __DIR__
]
];
To get one instance stored in the container just run this simple function:
$container->get('controller');
And you get your instance.
$container = new saiik\Container(
'app',
[
'mockup' => false
]
);
class GetMe {
public function helloWorld() {
echo "Hello!";
}
}
class Test {
protected $test;
public function __construct(GetMe $class) {
$this->test = $class;
}
public function test() {
return $this->test;
}
}
$container['test'] = Test::class;
$container->get('test')->test()->helloWorld();
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
composer.json | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Version Control | Unique User Downloads | |||||||
100% |
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.