Beispiel #1
0
 public function generateParameter(Parameter $parameter, CodeWriter $writer)
 {
     $class = $parameter->getClass();
     if ($class) {
         $writer->write("\\", $class->name, " ");
     } else {
         if ($parameter->isArray()) {
             $writer->write("array ");
         } else {
             if ($parameter->isCallable()) {
                 $writer->write("callable ");
             }
         }
     }
     $writer->write("\$", $parameter->name);
 }
Beispiel #2
0
 public function generateParameter(Parameter $parameter, CodeWriter $writer)
 {
     $name = $parameter->isAnnotatedWith("Spot\\App\\Web\\Param") ? $parameter->getAnnotation("Spot\\App\\Web\\Param")->value : $parameter->name;
     if ($parameter->isDefaultValueAvailable()) {
         $writer->write("isset(");
         $this->generateBindedParameter($name, $writer);
         $writer->write(") ? ");
     }
     $class = $parameter->getClass();
     if ($class) {
         if ($class->name == "Spot\\App\\Web\\Request") {
             $writer->write('$rq');
         } else {
             if ($class->name == "Spot\\App\\Web\\Response") {
                 $writer->write('$rp');
             } else {
                 $writer->write('is_array(');
                 $this->generateBindedParameter($name, $writer);
                 $writer->write(') ? $d->newInstance(');
                 $writer->literal($class->name);
                 $writer->write(', ');
                 $this->generateBindedParameter($name, $writer);
                 $writer->write(') : $d->find(');
                 $writer->literal($class->name);
                 $writer->write(', ');
                 $this->generateBindedParameter($name, $writer);
                 $writer->write(')');
             }
         }
     } else {
         $this->generateBindedParameter($name, $writer);
     }
     if ($parameter->isDefaultValueAvailable()) {
         $writer->write(" : ");
         $parameter->isDefaultValueConstant() ? $writer->write($parameter->getDefaultValueConstantName()) : $writer->literal($parameter->getDefaultValue());
     }
 }
Beispiel #3
0
 public static function ofParameter(Parameter $parameter)
 {
     $qualifier = $parameter->getAnnotation("Spot\\Inject\\Qualifier");
     if ($class = $parameter->getClass()) {
         return Key::ofType($class->name, $qualifier);
     }
     if (!$qualifier) {
         throw new ConfigurationException("Parameter \${$parameter->name} in " . $parameter->getDeclaringClass()->name . "::" . $parameter->getDeclaringFunction()->name . " is unbindable " . "because it's not type-hinted nor annotated with Qualifier annotation");
     }
     if ($parameter->isArray()) {
         return Key::ofCollection($qualifier);
     }
     return Key::ofConstant($qualifier);
 }
 public function generateDependencyInjectionParameter(Parameter $parameter, array $paths, CodeWriter $writer)
 {
     $name = $parameter->isAnnotatedWith("Spot\\App\\Web\\Param") ? $parameter->getAnnotation("Spot\\App\\Web\\Param")->value : $parameter->name;
     if (in_array($name, $paths)) {
         $this->generateParameter($parameter, $writer);
     } else {
         $writer->write('$_', $parameter->getPosition());
     }
 }
Beispiel #5
0
 public function writeParameter(Parameter $parameter, CodeWriter $writer)
 {
     $bind = $parameter->getAnnotation("Spot\\Domain\\Bind") ?: new Bind();
     $name = $bind->value ?: $parameter->name;
     ($class = $parameter->getClass()) ? $this->writeTypedBinding($class, $name, $writer) : $this->writeBinding($name, $writer);
 }
Beispiel #6
0
 public function generateParameter(Parameter $parameter, CodeWriter $writer)
 {
     if ($parameter->getClass()) {
         $writer->write($parameter->getClass()->name, " ");
     } else {
         if ($parameter->isArray()) {
             $writer->write("array ");
         }
     }
     $writer->write('$', $parameter->name);
     if ($parameter->isDefaultValueAvailable()) {
         $writer->write(" = ");
         $writer->literal($parameter->getDefaultValue());
     }
 }