-
Notifications
You must be signed in to change notification settings - Fork 0
Container
axios edited this page Jan 14, 2021
·
6 revisions
The core code of the TPR framework mostly uses container registration , you can change or replace any class object .
-
Container::dispatch()
- return type : tpr\core\Dispatch
-
Container::config()
- return type : tpr\core\Config
-
Container::request()
- return type : tpr\core\Request\RequestInterface
-
Container::response()
- return type : tpr\core\Response
-
Container::app()
- return type : tpr\server\ServerInterface
-
Container::lang()
- return type : tpr\core\Lang
-
Container::validator()
- return type : Rakit\Validation\Validator
-
Container::template()
- return type : Twig\Environment
- Bind
use tpr\Container;
// bind with class name
Container::bind(string $name, string $class_name, ...$construct_params);
// bind with object
Container::bindWithObj(string $name, object $object);
// bind if container is not exist
Container::bindNX(string $name, string $class_name, array $params = []);
Container::bindNXWithObj(string $name, object $object);
// Batch bind
Container::import([
'container-name' => <ContainerClassName> // bind if container is not exist.
])
// as array
$container = new tpr\Container;
$container["<contaniner-name>"] = $class_name;
$container["<contaniner-name>"] = $object;
- Get
// use method
Container::get(string $container_name);
// as array
$container = new tpr\Container;
$container["<contaniner-name>"];
- Has
// use method
Container::has(string $container_name);
// as array
$container = new tpr\Container;
isset($container["<contaniner-name>"]);
- Delete
// use method
Container::delete(string $container_name);
// as array
$container = new tpr\Container;
unset($container["<contaniner-name>"]);
Anything unclear or inaccurate? Please let me know at axioscros@aliyun.com