Exemple #1
0
 public function bindConfigItem($name, $item, $source)
 {
     static $PATTERN = '/\\{\\s*?(.*?)\\s*?\\}/';
     $key = Key::ofConstant(Named::name($name));
     if (is_array($item)) {
         $elements = $this->bindConfigCollection($item, "{$name}.", $source);
         $binding = new ConfigCollectionBinding($name, $source, $elements);
     } else {
         if (preg_match_all($PATTERN, $item, $matches)) {
             $dependencies = [];
             foreach (preg_split($PATTERN, $item) as $constant) {
                 if ($constant) {
                     $dependencies[] = new ConstantValueBinding($key, $constant);
                 }
                 $dependency = array_shift($matches[1]);
                 if ($dependency) {
                     $dependencies[] = defined($dependency) ? new ConstantNameBinding($key, $dependency) : new LateBinding(Key::ofConstant(Named::name($dependency)));
                 }
             }
             $binding = new ConfigItemBinding($name, $source, $dependencies);
         } else {
             $binding = new ConstantValueBinding($key, $item);
         }
     }
     $this->bindings->put($binding);
     return $binding;
 }
Exemple #2
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);
 }
Exemple #3
0
 public function __construct($name, $source)
 {
     parent::__construct(Key::ofConstant(Named::name($name)));
     $this->name = $name;
     $this->source = $source;
 }