public function testBinding() { $injector = new Injector(null); $injector->bind([Binding::init(HeavyEngine::class)->lazy(), bind("AAA")->toAlias(HeavyEngine::class)]); $engine = $injector->get('AAA'); $this->assertInstanceOf(Engine::class, $engine); }
/** * Injector constructor. * @param $injector */ public function __construct(Injector $injector = null) { $this->injector = $injector; if (!$injector) { $this->bind(Binding::init(LazyProxyBuilder::class)->toValue(LazyProxyBuilder::init()), bind(ProxyCache::class)->toValue(ProxyCache::init())); } }
public function testClassFactoryProvider() { $injector = new Injector(null); $binding = new Binding(Tire::class); $binding->toClass(function (Injector $injector) { return new HeavyTire(); })->lazy(); $provider = $binding->getProvider(); $entity = $provider->get($injector); $this->assertInstanceOf(LazyProvider::class, $provider); $this->assertInstanceOf(Tire::class, $entity); ProxyTest::_isProxyTrait($entity); }
/** * @param $name * @param $arguments * @return Binding */ public static function __callStatic($name, $arguments) { return Binding::init($name); }