Skip to content

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 .

TPR system container

Usage

  • 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>"]);
Clone this wiki locally