예제 #1
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('}');
 }
예제 #2
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("}");
 }
예제 #3
0
파일: Key.php 프로젝트: spotframework/spot
 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);
 }
예제 #4
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));
 }
예제 #5
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;
 }
예제 #6
0
 public function matches(Method $method)
 {
     if ($method->isConstructor() || $method->isDestructor() || $method->isStatic()) {
         return false;
     }
     foreach ($this->pointCuts as $pointCut) {
         if ($pointCut->matches($method)) {
             return true;
         }
     }
     return false;
 }
예제 #7
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("}");
 }
 public function isTypeBinded(Method $method)
 {
     $type = $method->getType();
     $route = $type->getAnnotation("Spot\\App\\Web\\Route");
     if (!$route || !$route->value) {
         return false;
     }
     $paths = $this->compiler->parse($route->value);
     $ctor = $type->getConstructor();
     return $ctor && $ctor->getParameters() && $paths;
 }
예제 #9
0
 function matches(Method $method)
 {
     return $method->getType()->isSubtypeOf($this->value);
 }
예제 #10
0
파일: Only.php 프로젝트: spotframework/spot
 function matches(Method $method)
 {
     return $method->getType()->name == $this->class && $method->name == $this->method;
 }
예제 #11
0
 public function generateMethodCall(Method $method, CodeWriter $writer)
 {
     $writer->write($method->getType()->name, "::", $method->name);
 }