for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Ray\Di;
use Ray\Di\MultiBinding\Lazy;
use Ray\Di\MultiBinding\LazyCollection;
final class MultiBinder
{
/** @var Container */
private $container;
/** @var array<string, array<int|string, Lazy<object>>> */
array<string, array<int|string, Lazy<object>>>
10
private $lazyCollection = [];
/** @var string */
private $interface;
private function __construct(AbstractModule $module, string $interface)
$this->container = $module->getContainer();
$this->interface = $interface;
}
public static function newInstance(AbstractModule $module, string $interface): self
return new self($module, $interface);
/**
* @param class-string $class
class-string
0
*/
public function add(string $class, ?string $key = null): void
$this->bind($class, $key);
$bind = (new Bind($this->container, LazyCollection::class))->toInstance(new LazyCollection($this->lazyCollection));
$this->container->add($bind);
public function set(string $class, ?string $key = null): void
unset($this->lazyCollection[$this->interface]);
$this->add($class, $key);
private function bind(string $class, ?string $key): void
if ($key === null) {
$this->lazyCollection[$this->interface][] = new Lazy($class);
return;
$this->lazyCollection[$this->interface][$key] = new Lazy($class);