public function get($className, $delegate, Injector $injector) { $proxy = "AspectProxy__" . $this->modules->hash() . "__" . md5($className); if (!$this->storage->load($proxy)) { $writer = CodeWriter::create(); $writer->writeln("use Spot\\Inject\\Impl\\Aspect\\DelegateInvocation;"); $writer->writeln("use Spot\\Inject\\Impl\\Aspect\\TerminalInvocation;"); $writer->write("class ", $proxy, " extends ", $className, " {"); $writer->indent(); $this->proxyGen->generate($this->reflection->get($className), $writer); $writer->outdent(); $writer->write("}"); $this->storage->store($proxy, $writer); } return new $proxy($this->singletons, $this->modules, $injector, $this->reflection, $delegate); }
public function getFactory(Key $key) { $factory = "InjectFactory__" . $this->modules->hash() . "__" . $key->hash(); if ($this->storage->load($factory)) { return $factory; } $this->builder->build(); $binding = $this->locator->get($key); if (empty($binding)) { throw new \RuntimeException("Unable to resolve dependency of {$key}, maybe you forgot to configure it ?"); } $writer = CodeWriter::create(); $writer->writeln("use Spot\\Inject\\Key;"); $writer->nl(); $writer->writeln("/**"); $writer->writeln(" * Provides {$key}"); $writer->writeln(" * "); $writer->writeln(" * Configured with: "); array_map(function ($module) use($writer) { $writer->write(" * "); $writer->writeln(is_object($module) ? get_class($module) : $module); }, iterator_to_array($this->modules)); $writer->writeln(" */"); $writer->write("class {$factory} {"); $writer->indent(); $writer->write('static function get($s, $m, $i, $a) {'); $writer->indent(); $writer->write("return "); $binding->accept(new FactoryCompilerVisitor($writer, $this->locator, $this->aspect)); $writer->write(";"); $writer->outdent(); $writer->write("}"); $writer->outdent(); $writer->writeln("}"); $this->storage->store($factory, $writer); return $factory; }