Ejemplo n.º 1
0
 public function generateMethod(Method $method, CodeWriter $writer)
 {
     $writer->write("function ", $method->name, " (");
     $parameters = $method->getParameters();
     if ($parameters) {
         $this->generateParameter(array_shift($parameters), $writer);
         foreach ($parameters as $parameter) {
             $writer->write(", ");
             $this->generateParameter($parameter, $writer);
         }
     }
     $writer->write(") {");
     $writer->indent();
     $writer->write('return $this->__(');
     $parameters = $method->getParameters();
     if ($parameters) {
         $writer->write("\$", array_shift($parameters)->name);
         foreach ($parameters as $parameter) {
             $writer->write(", ");
             $writer->write("\$", $parameter->name);
         }
     }
     $writer->write(");");
     $writer->outdent();
     $writer->write("}");
 }
Ejemplo n.º 2
0
 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('}');
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 function matches(Method $method)
 {
     if ($method->isAnnotatedWith($this->value) || $method->getType()->isAnnotatedWith($this->value)) {
         return true;
     }
     foreach ($method->getParameters() as $parameter) {
         if ($parameter->isAnnotatedWith($this->value)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 public function generateMethod(Method $method, array $advices, CodeWriter $writer)
 {
     $writer->write("function ", $method->name, " (");
     $parameters = $method->getParameters();
     if ($parameters) {
         $this->generateParameter(array_shift($parameters), $writer);
         foreach ($parameters as $parameter) {
             $writer->write(", ");
             $this->generateParameter($parameter, $writer);
         }
     }
     $writer->write(") {");
     $writer->indent();
     $writer->writeln('$s = $this->s;');
     $writer->writeln('$m = $this->m;');
     $writer->writeln('$i = $this->i;');
     $writer->write("return (");
     $writer->indent();
     foreach ($advices as $advice) {
         $writer->write("new DelegateInvocation(");
         $advice->accept(new FactoryCompilerVisitor($writer, $this->locator, $this->aspect));
         $writer->write(", ");
     }
     $writer->write("new TerminalInvocation(func_get_args(), ");
     $writer->literal($method->getType()->name);
     $writer->write(", ");
     $writer->literal($method->name);
     $writer->write(', $this->d, $this->r)');
     foreach ($advices as $advice) {
         $writer->write(")");
     }
     $writer->outdent();
     $writer->write(")->proceed();");
     $writer->outdent();
     $writer->write("}");
 }