public static function ofProvider(Method $method) { $provides = $method->getAnnotation("Spot\\Inject\\Provides"); $qualifier = $method->getAnnotation("Spot\\Inject\\Qualifier"); if (!$qualifier && ($provides->value == Provides::ELEMENT || $provides->value == Provides::CONSTANT)) { throw new ConfigurationException("Invalid provider method in {$method->class}::{$method->name}" . ", constant or element provider must be annotated with Qualifier annotation"); } return new Key($provides->value, $qualifier); }
public function writeMultiMethod(Method $method, CodeWriter $writer) { $name = null; if (stripos($method->name, "add") === 0) { $name = lcfirst(substr($method->name, 3)); } $name = $method->getAnnotation("Spot\\Domain\\Bind")->value ?: $name; if (empty($name)) { throw new \LogicException("Invalid binding name in {$method->class}::{$method->name}()"); } $writer->write('foreach(isset($b["', $name, '"]) ? (array)'); $this->writeBinding($name, $writer); $writer->write(' : [] as $v) {'); $writer->indent(); $writer->write('$i->', $method->name, '('); $class = $method->getParameters()[0]->getClass(); if ($class) { $writer->write('is_array($v) ? $d->newInstance('); $writer->literal($class->name); $writer->write(', $v) : $d->find('); $writer->literal($class->name); $writer->write(', $v)'); } else { $writer->write('$v'); } $writer->write(');'); $writer->outdent(); $writer->writeln('}'); }
public function bindInterceptor(Method $method, $index) { $matchers = $method->getAnnotation("Spot\\Inject\\Intercept")->getMatchers(); $key = Key::ofType("Spot\\Aspect\\Intercept\\MethodInterceptor"); $dependencies = []; foreach ($method->getParameters() as $parameter) { $dependencies[] = $this->bindParameter($parameter); } $binding = new ProviderMethodBinding($key, $index, $method, $dependencies); $this->pointCuts->put(new PointCut($matchers, $binding)); }